diff --git a/routes/todos.js b/routes/todos.js index 6c4daf6..55f945f 100644 --- a/routes/todos.js +++ b/routes/todos.js @@ -13,7 +13,9 @@ router.get( '/', asyncHelper(async (req, res) => { const { listId } = res.locals || req.body; - const todos = await Todo.find({ list: listId, user: req.user.id }).exec(); + const todos = listId + ? await Todo.find({ list: listId, user: req.user.id }).exec() + : await Todo.find({ user: req.user.id }).exec(); res.json({ success: true, data: todos.map(todo => todo.toJson()) }); }), ); diff --git a/tests/integration/todos.test.js b/tests/integration/todos.test.js index fd075b9..031b598 100644 --- a/tests/integration/todos.test.js +++ b/tests/integration/todos.test.js @@ -49,6 +49,17 @@ describe('test todos', () => { expect(response.body.success).toBeTruthy(); expect(response.body.data[0].text).toEqual('Todo1'); }); + test('should index all todos', async () => { + const response = await request(server) + .get(`/api/todos`) + .set('Authorization', `Bearer ${token}`) + .set('Content-Type', 'application/json') + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', 'application/json; charset=utf-8'); + expect(response.body.success).toBeTruthy(); + expect(response.body.data[0].text).toEqual('Todo1'); + }); test('should not index todos without authentication', async () => { await request(server) .get(`/api/lists/${list._id}/todos`)