Skip to content

Commit

Permalink
Fix tests to supply invocation param
Browse files Browse the repository at this point in the history
  • Loading branch information
robatwilliams committed Dec 19, 2023
1 parent 083e54d commit a2d5e1a
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/functions/functions.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('CHAT_COMPLETE', () => {
const completion = await chatComplete(
[['user', 'Say hello']],
[['API_KEY', 'someapikey']],
{},
);

const requestBody = JSON.parse(fetch.mock.calls[0].arguments[1].body);
Expand All @@ -27,7 +28,7 @@ describe('CHAT_COMPLETE', () => {
mockResponseOk(makeCompletionResponse()),
);

await chatComplete([['Say hello']], [['API_KEY', 'someapikey']]);
await chatComplete([['Say hello']], [['API_KEY', 'someapikey']], {});

const requestBody = JSON.parse(fetch.mock.calls[0].arguments[1].body);
assert.deepStrictEqual(requestBody.messages[1], {
Expand All @@ -47,6 +48,7 @@ describe('CHAT_COMPLETE', () => {
[0, 0],
],
[['API_KEY', 'someapikey']],
{},
);

const requestBody = JSON.parse(fetch.mock.calls[0].arguments[1].body);
Expand All @@ -64,6 +66,7 @@ describe('CHAT_COMPLETE', () => {
['API_KEY', 'someapikey'],
['temperature', 0.3],
],
{},
);

const requestBody = JSON.parse(fetch.mock.calls[0].arguments[1].body);
Expand All @@ -82,24 +85,33 @@ describe('CHAT_COMPLETE', () => {
['API_KEY', 'someapikey'],
[0, 0],
],
{},
);

const requestBody = JSON.parse(fetch.mock.calls[0].arguments[1].body);
assert(!('0' in requestBody));
});

it('throws an error when no API key is provided - key absent', () => {
assert.rejects(() => chatComplete([['Say hello']], []), {
code: '#VALUE!',
message: 'API_KEY is required',
});
assert.rejects(
() => chatComplete([['Say hello']], []),
{
code: '#VALUE!',
message: 'API_KEY is required',
},
{},
);
});

it('throws an error when no API key is provided - value cell empty', () => {
assert.rejects(() => chatComplete([['Say hello']], [['API_KEY', 0]]), {
code: '#VALUE!',
message: 'API_KEY is required',
});
assert.rejects(
() => chatComplete([['Say hello']], [['API_KEY', 0]]),
{
code: '#VALUE!',
message: 'API_KEY is required',
},
{},
);
});

it('throws an error for an API error with a provided message', (t) => {
Expand All @@ -122,7 +134,7 @@ describe('CHAT_COMPLETE', () => {
);

assert.rejects(
() => chatComplete([['Say hello']], [['API_KEY', 'someapikey']]),
() => chatComplete([['Say hello']], [['API_KEY', 'someapikey']], {}),
{
code: '#N/A',
message: "API error: 0 is less than the minimum of 1 - 'n'",
Expand Down Expand Up @@ -151,7 +163,7 @@ describe('CHAT_COMPLETE', () => {
);

assert.rejects(
() => chatComplete([['Say hello']], [['API_KEY', 'someapikey']]),
() => chatComplete([['Say hello']], [['API_KEY', 'someapikey']], {}),
{
code: '#N/A',
message: 'API error: 502 Bad Gateway',
Expand Down

0 comments on commit a2d5e1a

Please sign in to comment.