From adc036877d67e25ea695712eff792d8a1ecfc7b5 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 1 Dec 2017 00:07:56 -0500 Subject: [PATCH] more tests --- server/tests/server.test.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/server/tests/server.test.js b/server/tests/server.test.js index 6a917af..cdd9f3f 100644 --- a/server/tests/server.test.js +++ b/server/tests/server.test.js @@ -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) + }); +});