Blame Raw
· · · 34 lines (1.3 KB)
0 contributors
1import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
2import { MockServer } from './util/mock-server.js';
3
4describe('MockServer tests', () => {
5 /** @type {MockServer} */
6 const mockServer = new MockServer({ port: 3000, host: '127.0.0.1' });
7
8 beforeAll(async () => {
9 await mockServer.start();
10 });
11
12 afterAll(async () => {
13 await mockServer.stop();
14 });
15
16 test('should provide OpenAI-compatible endpoint', async () => {
17 const requestBody = {
18 model: 'gpt-4o',
19 max_tokens: 400,
20 messages: [
21 { role: 'user', content: 'Hello, world!' },
22 ],
23 };
24 const response = await fetch('http://127.0.0.1:3000/v1/chat/completions', {
25 method: 'POST',
26 headers: { 'Content-Type': 'application/json' },
27 body: JSON.stringify(requestBody),
28 });
29 const expectedResponse = { 'choices': [{ 'finish_reason': 'stop', 'index': 0, 'message': { 'role': 'assistant', 'reasoning_content': 'gpt-4o\n1\n400', 'content': 'Hello, world!' } }], 'created': 0, 'model': 'gpt-4o' };
30 expect(response.status).toBe(200);
31 const json = await response.json();
32 expect(json).toEqual(expectedResponse);
33 });
34});