Skip to content

Commit

Permalink
387th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Oct 15, 2024
1 parent dfc8c7e commit 7d74517
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/src/routes/todos/[id]/+handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default (async (app) => {
schema: {
params,
body: Type.Object({
_id: Type.String(),
title: Type.String(),
completed: Type.Boolean(),
}),
Expand Down
6 changes: 1 addition & 5 deletions app/src/routes/todos/[id]/__tests__/+handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ test('POST /todos/new', async () => {
await app.inject({
method: 'PUT',
url: `/todos/${id}`,
payload: {
_id: id,
...payload,
completed: true,
},
payload: { ...payload, completed: true },
});

const res2 = await app.inject({ method: 'GET', url: `/todos/${id}` });
Expand Down
27 changes: 24 additions & 3 deletions e2e/src/todos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,37 @@ test('POST /api/todos', async ({ request }) => {
});

test('POST /api/todos/new', async ({ request }) => {
const response = await request.post('/api/todos/new', {
data: { title: 'foo' },
});
const body = { title: 'foo' };
const response = await request.post('/api/todos/new', { data: body });
const data = await response.json();
expect(data.message).toEqual('OK');
});

let _id = '';

test('POST /api/todos { "title": "foo" }', async ({ request }) => {
const response = await request.post('/api/todos', { data: { title: 'foo' } });
const data = await response.json();
expect(data.total).toEqual(1);
expect(data.result[0]).toEqual(expect.objectContaining({ title: 'foo', completed: false }));
_id = data.result[0]._id;
});

test('GET /api/todos/:id', async ({ request }) => {
const response = await request.get(`/api/todos/${_id}`);
const data = await response.json();
expect(data.result).toEqual(expect.objectContaining({ title: 'foo', completed: false }));
});

test('PUT /api/todos/:id', async ({ request }) => {
const body = { title: 'foo', completed: true };
const response = await request.put(`/api/todos/${_id}`, { data: body });
const data = await response.json();
expect(data.message).toEqual('OK');
});

test('DELETE /api/todos/:id', async ({ request }) => {
const response = await request.delete(`/api/todos/${_id}`);
const data = await response.json();
expect(data.message).toEqual('OK');
});

0 comments on commit 7d74517

Please sign in to comment.