feat: improve error messages (#1006)
This commit is contained in:
parent
9127e1be88
commit
8a7d3e9950
13 changed files with 370 additions and 174 deletions
|
|
@ -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