From 3191ee36c803a5de2fd1802c2a7384a5b255a623 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 Nov 2017 23:39:28 -0500 Subject: [PATCH] testing get stuff --- server/tests/server.test.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/server/tests/server.test.js b/server/tests/server.test.js index fc80f72..f634840 100644 --- a/server/tests/server.test.js +++ b/server/tests/server.test.js @@ -4,8 +4,16 @@ const request = require('supertest'); const {app} = require('./../server'); const {Todo} = require('./../models/todo'); +var dummy = [ {text: 'One'}, {text: 'Two'}, {text: 'Three'} ]; + + beforeEach((done) => { - Todo.remove({}).then(() => done()); + Todo.remove({}).then(() => { + return Todo.insertMany(dummy); + }).then(() => { + done(); + }); + }); describe('POST /todos', () => { @@ -25,8 +33,8 @@ describe('POST /todos', () => { } Todo.find().then((todos) => { - expect(todos.length).toBe(1); - expect(todos[0].text).toBe(text); + expect(todos.length).toBe(4); + expect(todos[3].text).toBe(text); done(); }).catch((e) => done(e)); }) @@ -42,9 +50,23 @@ describe('POST /todos', () => { return done(err); } Todo.find().then((todos) => { - expect(todos.length).toBe(0); + expect(todos.length).toBe(3); done(); }).catch((e) => done(e)); }) }); }); + + +describe("GET /todos", () => { + it('should get all TODOS', (done) => { + request(app) + .get('/todos') + .expect(200) + .expect((res) => { + expect(res.body.todos.length).toBe(3) + + }) + .end(done); + }) +})