move completed todos outside of tasksOrder (and back) with tests

This commit is contained in:
Matteo Pagliazzi
2015-12-16 12:57:19 +01:00
parent d9e786ebaa
commit 35316ebeb6
3 changed files with 54 additions and 4 deletions

View File

@@ -53,6 +53,39 @@ describe('POST /tasks/:id/score/:direction', () => {
.then((task) => expect(task.completed).to.equal(true));
});
it('moves completed todos out of user.tasksOrder.todos', () => {
return api.get('/user')
.then(user => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
}).then(() => api.post(`/tasks/${todo._id}/score/up`))
.then(() => api.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(true);
return api.get('/user');
})
.then((user) => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(-1)
});
});
it('moves un-completed todos back into user.tasksOrder.todos', () => {
return api.get('/user')
.then(user => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
}).then(() => api.post(`/tasks/${todo._id}/score/up`))
.then(() => api.post(`/tasks/${todo._id}/score/down`))
.then(() => api.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(false);
return api.get('/user');
})
.then((user) => {
let l = user.tasksOrder.todos.length;
expect(user.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1);
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom
});
});
it('uncompletes todo when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/tasks/${todo._id}`))

View File

@@ -15,7 +15,7 @@ describe('PUT /tasks/:id', () => {
});
});
xcontext('validates params', () => {
context('validates params', () => {
let task;
beforeEach(() => {
@@ -64,7 +64,7 @@ describe('PUT /tasks/:id', () => {
});
});
xcontext('habits', () => {
context('habits', () => {
let habit;
beforeEach(() => {
@@ -92,7 +92,7 @@ describe('PUT /tasks/:id', () => {
});
});
xcontext('todos', () => {
context('todos', () => {
let todo;
beforeEach(() => {
@@ -255,7 +255,7 @@ describe('PUT /tasks/:id', () => {
});
});
xcontext('rewards', () => {
context('rewards', () => {
let reward;
beforeEach(() => {