more tests

This commit is contained in:
Tyrel Souza 2017-12-01 00:07:56 -05:00
parent dfcee7a8ee
commit adc036877d

View File

@ -7,7 +7,7 @@ const {Todo} = require('./../models/todo');
var dummy = [
{_id: new ObjectID(), text: 'One'},
{_id: new ObjectID(), text: 'Two'},
{_id: new ObjectID(), text: 'Two', completed: true, completedAt: 333},
{_id: new ObjectID(), text: 'Three'} ];
@ -37,8 +37,8 @@ describe('POST /todos', () => {
}
Todo.find().then((todos) => {
expect(todos.length).toBe(4);
expect(todos[3].text).toBe(text);
expect(todos.length).toBe(dummy.length + 1);
expect(todos[dummy.length].text).toBe(text);
done();
}).catch((e) => done(e));
})
@ -61,7 +61,6 @@ describe('POST /todos', () => {
});
});
describe("GET /todos", () => {
it('should get all TODOS', (done) => {
request(app)
@ -130,3 +129,30 @@ describe("DELETE /todos/:id", () => {
.end(done)
});
});
describe("PATCH /todos/:id", () => {
it("should update a single todo", (done) => {
var newText = "butts";
request(app)
.patch(`/todos/${dummy[0]._id.toHexString()}`)
.send({text: newText , completed: true})
.expect(200)
.expect((res) => {
expect(res.body.todo.text).toBe(newText);
expect(res.body.todo.completedAt).toBeA('number');
})
.end(done)
});
it("should clear completed at when todo is not completed", (done) => {
request(app)
.patch(`/todos/${dummy[1]._id.toHexString()}`)
.send({completed: false})
.expect(200)
.expect((res) => {
expect(res.body.todo.completedAt).toBe(null);
expect(res.body.todo.completed).toBe(false);
})
.end(done)
});
});