const expect = require('expect');
const request = require('supertest');

const {app} = require('./../server');
const {Todo} = require('./../models/todos');

// Lifecycle Method
// make sure the debabase is empty
beforeEach((done) => {
    Todo.remove({
        // wipe all todos with empty object 
    }).then(() => done());
});

describe('POST /todos', () => {
    it('should create a new todo', (done) => {
        // dummy text
        var text = 'test todo text';
        
        request(app)
            .post('/todos')
            .send({
                text: text
            })
            .expect(200)
            .expect((res) => {
                expect(res.body.text).toBe(text);
            })
            .end((error, resp) => {
                if (error) {
                    return done(error);
                }

                Todo.find().then((todos) => {
                    expect(todos.length).toBe(1);
                    expect(todos[0].text).toBe(text);
                    done();
                }).catch((error) => done(error));
            });
    });

    // verify a todo is not created when bad data is sent
    it('should not create todo wit invalid body data', (done) => {
        
        request(app)
            .post('/todos')
            .send({})// send an empty object
            .expect(400)
            .end((error, resp) => {
                if (error) {
                    return done(error)
                }

                Todo.find().then((todos) => {
                    expect(todos.length).toBe(0);
                    done();
                }).catch((error) => {
                    done(error);
                });
            });
    })
});
@@ -150,16 +150,239 @@
 dos');%0A%0A
+// Dummy todos for our GET method%0A// only need the text property because%0A// mongoose db will ppoulate the rest%0Aconst todos = %5B%0A    %7B%0A        text: 'test todo text'%0A    %7D,%0A    %7B%0A        text: 'test todo text again'%0A    %7D%0A%5D%0A%0A
 // Lifec
@@ -454,16 +454,19 @@
 =%3E %7B%0A   
+ //
  Todo.re
@@ -471,24 +471,27 @@
 remove(%7B%0A   
+ //
      // wipe
@@ -523,16 +523,19 @@
 ect %0A   
+ //
  %7D).then
@@ -549,16 +549,185 @@
 done());
+%0A%0A    // insertMany%0A    Todo.remove(%7B%0A        // wipe all todos with empty object%0A    %7D).then( () =%3E %7B%0A        return Todo.insertMany(todos);%0A    %7D).then( () =%3E done());
 %0A%7D);%0A%0Ade
@@ -1245,32 +1245,36 @@
       Todo.find(
+text
 ).then((todos) =
@@ -1327,9 +1327,9 @@
 oBe(
-1
+3
 );%0A 
@@ -1952,17 +1952,17 @@
 h).toBe(
-0
+2
 );%0A     
@@ -2097,12 +2097,300 @@
 ;%0A    %7D)%0A%7D);
+%0A%0A%0Adescribe('GET /todos', () =%3E %7B%0A    it('should get all todos', (done) =%3E %7B%0A        request(app)%0A            .get('/todos')%0A            .expect(200)%0A            .expect((resp) =%3E %7B%0A                expect((resp.body.todos).length).toBe(2);%0A            %7D)%0A            .end(done);%0A    %7D)%0A%7D)

add new describe, get todos with dummy data