feat: improve error messages (#1006)
This commit is contained in:
parent
9127e1be88
commit
8a7d3e9950
13 changed files with 370 additions and 174 deletions
|
|
@ -2,6 +2,7 @@ import { expect, test } from '../fixtures';
|
|||
import { AuthPage } from '../pages/auth';
|
||||
import { generateRandomTestUser } from '../helpers';
|
||||
import { ChatPage } from '../pages/chat';
|
||||
import { getMessageByErrorCode } from '@/lib/errors';
|
||||
|
||||
test.describe
|
||||
.serial('Guest Session', () => {
|
||||
|
|
@ -201,7 +202,7 @@ test.describe('Entitlements', () => {
|
|||
|
||||
await chatPage.sendUserMessage('Why is the sky blue?');
|
||||
await chatPage.expectToastToContain(
|
||||
'You have exceeded your maximum number of messages for the day! Please try again later.',
|
||||
getMessageByErrorCode('rate_limit:chat'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { generateUUID } from '@/lib/utils';
|
||||
import { expect, test } from '../fixtures';
|
||||
import { TEST_PROMPTS } from '../prompts/routes';
|
||||
import { getMessageByErrorCode } from '@/lib/errors';
|
||||
|
||||
const chatIdsCreatedByAda: Array<string> = [];
|
||||
|
||||
|
|
@ -14,8 +15,9 @@ test.describe
|
|||
});
|
||||
expect(response.status()).toBe(400);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Invalid request body');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('bad_request:api');
|
||||
expect(message).toEqual(getMessageByErrorCode('bad_request:api'));
|
||||
});
|
||||
|
||||
test('Ada can invoke chat generation', async ({ adaContext }) => {
|
||||
|
|
@ -55,8 +57,9 @@ test.describe
|
|||
});
|
||||
expect(response.status()).toBe(403);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Forbidden');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('forbidden:chat');
|
||||
expect(message).toEqual(getMessageByErrorCode('forbidden:chat'));
|
||||
});
|
||||
|
||||
test("Babbage cannot delete Ada's chat", async ({ babbageContext }) => {
|
||||
|
|
@ -67,8 +70,9 @@ test.describe
|
|||
);
|
||||
expect(response.status()).toBe(403);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Forbidden');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('forbidden:chat');
|
||||
expect(message).toEqual(getMessageByErrorCode('forbidden:chat'));
|
||||
});
|
||||
|
||||
test('Ada can delete her own chat', async ({ adaContext }) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { Document } from '@/lib/db/schema';
|
||||
import { generateUUID } from '@/lib/utils';
|
||||
import { expect, test } from '../fixtures';
|
||||
import { getMessageByErrorCode } from '@/lib/errors';
|
||||
|
||||
const documentsCreatedByAda: Array<Document> = [];
|
||||
|
||||
|
|
@ -12,8 +13,9 @@ test.describe
|
|||
const response = await adaContext.request.get('/api/document');
|
||||
expect(response.status()).toBe(400);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Missing id');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('bad_request:api');
|
||||
expect(message).toEqual(getMessageByErrorCode(code));
|
||||
});
|
||||
|
||||
test('Ada cannot retrieve a document that does not exist', async ({
|
||||
|
|
@ -26,8 +28,9 @@ test.describe
|
|||
);
|
||||
expect(response.status()).toBe(404);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Not found');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('not_found:document');
|
||||
expect(message).toEqual(getMessageByErrorCode(code));
|
||||
});
|
||||
|
||||
test('Ada can create a document', async ({ adaContext }) => {
|
||||
|
|
@ -118,8 +121,9 @@ test.describe
|
|||
const response = await adaContext.request.delete(`/api/document`);
|
||||
expect(response.status()).toBe(400);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Missing id');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('bad_request:api');
|
||||
expect(message).toEqual(getMessageByErrorCode(code));
|
||||
});
|
||||
|
||||
test('Ada cannot delete a document without specifying a timestamp', async ({
|
||||
|
|
@ -132,8 +136,9 @@ test.describe
|
|||
);
|
||||
expect(response.status()).toBe(400);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Missing timestamp');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('bad_request:api');
|
||||
expect(message).toEqual(getMessageByErrorCode(code));
|
||||
});
|
||||
|
||||
test('Ada can delete a document by specifying id and timestamp', async ({
|
||||
|
|
@ -187,8 +192,9 @@ test.describe
|
|||
);
|
||||
expect(response.status()).toBe(403);
|
||||
|
||||
const text = await response.text();
|
||||
expect(text).toEqual('Forbidden');
|
||||
const { code, message } = await response.json();
|
||||
expect(code).toEqual('forbidden:document');
|
||||
expect(message).toEqual(getMessageByErrorCode(code));
|
||||
});
|
||||
|
||||
test("Ada's documents did not get updated", async ({ adaContext }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue