Skip to content

Commit

Permalink
Add tests for AI prompt agent function
Browse files Browse the repository at this point in the history
  • Loading branch information
emielwit committed Nov 22, 2023
1 parent 4c1f20c commit 6524591
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions __tests__/ai-prompt/1.0/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import agent from '../../../functions/ai-prompt/1.0';

const validInput = {
prompt: 'Hello',
variables: [{ key: 'name', value: 'John' }],
apiKey: 'validApiKey',
maxTokens: 100,
temperature: 50,
model: 'text-davinci-002',
};

const invalidInput = {
prompt: 'Hello',
variables: [{ key: 'name', value: 'John' }],
apiKey: 'invalidApiKey',
maxTokens: 100,
temperature: 50,
model: 'text-davinci-002',
};

describe('Agent function', () => {
test('returns the expected result with valid inputs', async () => {
const { result } = await agent(validInput);
expect(result).toBe('Hello John');
});

test('throws an error with invalid inputs', async () => {
await expect(agent(invalidInput)).rejects.toThrow('Invalid API Key');
});
});
7 changes: 7 additions & 0 deletions __tests__/support/generative-ai/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const generativeAI = async ({ authorization }) => {
if (authorization.apiKey === 'validApiKey') {
return Promise.resolve({ result: 'Hello John' });
}
return Promise.reject(new Error('Invalid API Key'));
};
export default generativeAI;
2 changes: 2 additions & 0 deletions __tests__/support/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import gql from '../gql';
import parseToGqlFragment from '../parse-to-gql-fragment';
import runAction from '../run-action';
import parseData from '../parse-data';
import generativeAI from '../generative-ai';

global.generatePDF = generatePDF;
global.gql = gql;
global.parseToGqlFragment = parseToGqlFragment;
global.runAction = runAction;
global.parseData = parseData;
global.generativeAI = generativeAI;

0 comments on commit 6524591

Please sign in to comment.