-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into stop-sending-full-defences-on-low-leevels
- Loading branch information
Showing
11 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { beforeAll, describe, expect, it, jest } from '@jest/globals'; | ||
import { OpenAI } from 'openai'; | ||
import request from 'supertest'; | ||
|
||
import app from '@src/app'; | ||
import { StartResponse } from '@src/models/api/StartGetRequest'; | ||
import { LEVEL_NAMES } from '@src/models/level'; | ||
|
||
jest.mock('openai'); | ||
|
||
const PATH = '/start'; | ||
|
||
describe('/start endpoints', () => { | ||
const mockListFn = jest.fn<OpenAI.Models['list']>(); | ||
jest.mocked(OpenAI).mockImplementation( | ||
() => | ||
({ | ||
models: { | ||
list: mockListFn, | ||
}, | ||
} as unknown as jest.MockedObject<OpenAI>) | ||
); | ||
|
||
beforeAll(() => { | ||
mockListFn.mockResolvedValue({ | ||
data: [{ id: 'gpt-3.5-turbo' }], | ||
} as OpenAI.ModelsPage); | ||
}); | ||
|
||
it.each(Object.values(LEVEL_NAMES))( | ||
'WHEN given valid level [%s] THEN it responds with 200', | ||
async (level) => | ||
request(app) | ||
.get(`${PATH}?level=${level}`) | ||
.expect(200) | ||
.expect('Content-Type', /application\/json/) | ||
.then((response) => { | ||
const { chatHistory, emails } = response.body as StartResponse; | ||
expect(chatHistory).toEqual([]); | ||
expect(emails).toEqual([]); | ||
}) | ||
); | ||
|
||
it.each([-1, 4, 'SANDBOX'])( | ||
'WHEN given invalid level [%s] THEN it responds with 400', | ||
async (level) => | ||
request(app) | ||
.get(`${PATH}?level=${level}`) | ||
.expect(400) | ||
.then((response) => { | ||
expect(response.text).toEqual('Invalid level'); | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// set the environment variables | ||
process.env.OPENAI_API_KEY = 'sk-12345'; | ||
process.env.SESSION_SECRET = "shhh! Don't tell anyone..."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module 'query-types' { | ||
import type { NextHandleFunction } from 'connect'; | ||
|
||
function middleware(): NextHandleFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters