mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
index all todos
This commit is contained in:
@@ -13,7 +13,9 @@ router.get(
|
|||||||
'/',
|
'/',
|
||||||
asyncHelper(async (req, res) => {
|
asyncHelper(async (req, res) => {
|
||||||
const { listId } = res.locals || req.body;
|
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()) });
|
res.json({ success: true, data: todos.map(todo => todo.toJson()) });
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -49,6 +49,17 @@ describe('test todos', () => {
|
|||||||
expect(response.body.success).toBeTruthy();
|
expect(response.body.success).toBeTruthy();
|
||||||
expect(response.body.data[0].text).toEqual('Todo1');
|
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 () => {
|
test('should not index todos without authentication', async () => {
|
||||||
await request(server)
|
await request(server)
|
||||||
.get(`/api/lists/${list._id}/todos`)
|
.get(`/api/lists/${list._id}/todos`)
|
||||||
|
|||||||
Reference in New Issue
Block a user