2025-04-22 18:55:17 -07:00
|
|
|
import { generateUUID } from '@/lib/utils';
|
|
|
|
|
import { expect, test } from '../fixtures';
|
|
|
|
|
import { TEST_PROMPTS } from '../prompts/routes';
|
|
|
|
|
|
|
|
|
|
const chatIdsCreatedByAda: Array<string> = [];
|
|
|
|
|
|
|
|
|
|
test.describe
|
|
|
|
|
.serial('/api/chat', () => {
|
|
|
|
|
test('Ada cannot invoke a chat generation with empty request body', async ({
|
|
|
|
|
adaContext,
|
|
|
|
|
}) => {
|
|
|
|
|
const response = await adaContext.request.post('/api/chat', {
|
|
|
|
|
data: {},
|
|
|
|
|
});
|
|
|
|
|
expect(response.status()).toBe(500);
|
|
|
|
|
|
|
|
|
|
const text = await response.text();
|
|
|
|
|
expect(text).toEqual('An error occurred while processing your request!');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Ada can invoke chat generation', async ({ adaContext }) => {
|
|
|
|
|
const chatId = generateUUID();
|
|
|
|
|
|
2025-04-25 23:40:15 -07:00
|
|
|
const response = await adaContext.request.post('/api/chat', {
|
2025-04-22 18:55:17 -07:00
|
|
|
data: {
|
|
|
|
|
id: chatId,
|
|
|
|
|
messages: TEST_PROMPTS.SKY.MESSAGES,
|
|
|
|
|
selectedChatModel: 'chat-model',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
expect(response.status()).toBe(200);
|
|
|
|
|
|
|
|
|
|
const text = await response.text();
|
|
|
|
|
const lines = text.split('\n');
|
|
|
|
|
|
|
|
|
|
const [_, ...rest] = lines;
|
|
|
|
|
expect(rest.filter(Boolean)).toEqual(TEST_PROMPTS.SKY.OUTPUT_STREAM);
|
|
|
|
|
|
|
|
|
|
chatIdsCreatedByAda.push(chatId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Babbage cannot append message to Ada's chat", async ({
|
|
|
|
|
babbageContext,
|
|
|
|
|
}) => {
|
|
|
|
|
const [chatId] = chatIdsCreatedByAda;
|
|
|
|
|
|
2025-04-25 23:40:15 -07:00
|
|
|
const response = await babbageContext.request.post('/api/chat', {
|
2025-04-22 18:55:17 -07:00
|
|
|
data: {
|
|
|
|
|
id: chatId,
|
|
|
|
|
messages: TEST_PROMPTS.GRASS.MESSAGES,
|
|
|
|
|
selectedChatModel: 'chat-model',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
expect(response.status()).toBe(403);
|
|
|
|
|
|
|
|
|
|
const text = await response.text();
|
|
|
|
|
expect(text).toEqual('Forbidden');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Babbage cannot delete Ada's chat", async ({ babbageContext }) => {
|
|
|
|
|
const [chatId] = chatIdsCreatedByAda;
|
|
|
|
|
|
|
|
|
|
const response = await babbageContext.request.delete(
|
2025-04-25 23:40:15 -07:00
|
|
|
`/api/chat?id=${chatId}`,
|
2025-04-22 18:55:17 -07:00
|
|
|
);
|
|
|
|
|
expect(response.status()).toBe(403);
|
|
|
|
|
|
|
|
|
|
const text = await response.text();
|
|
|
|
|
expect(text).toEqual('Forbidden');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Ada can delete her own chat', async ({ adaContext }) => {
|
|
|
|
|
const [chatId] = chatIdsCreatedByAda;
|
|
|
|
|
|
2025-04-25 23:40:15 -07:00
|
|
|
const response = await adaContext.request.delete(
|
|
|
|
|
`/api/chat?id=${chatId}`,
|
|
|
|
|
);
|
2025-04-22 18:55:17 -07:00
|
|
|
expect(response.status()).toBe(200);
|
|
|
|
|
|
|
|
|
|
const deletedChat = await response.json();
|
|
|
|
|
expect(deletedChat).toMatchObject({ id: chatId });
|
|
|
|
|
});
|
|
|
|
|
});
|