diff --git a/app/src/routes/todos/[id]/+handler.ts b/app/src/routes/todos/[id]/+handler.ts index 7352b52..6b8cd20 100644 --- a/app/src/routes/todos/[id]/+handler.ts +++ b/app/src/routes/todos/[id]/+handler.ts @@ -75,7 +75,6 @@ export default (async (app) => { schema: { params, body: Type.Object({ - _id: Type.String(), title: Type.String(), completed: Type.Boolean(), }), diff --git a/app/src/routes/todos/[id]/__tests__/+handler.test.ts b/app/src/routes/todos/[id]/__tests__/+handler.test.ts index 461cbf8..d4573ff 100644 --- a/app/src/routes/todos/[id]/__tests__/+handler.test.ts +++ b/app/src/routes/todos/[id]/__tests__/+handler.test.ts @@ -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}` }); diff --git a/e2e/src/todos.test.ts b/e2e/src/todos.test.ts index e90222f..d2da3db 100644 --- a/e2e/src/todos.test.ts +++ b/e2e/src/todos.test.ts @@ -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'); });