This commit is contained in:
Tyrel Souza 2017-11-29 23:15:25 -05:00
parent eac8779435
commit 9c7041a80f
4 changed files with 1655 additions and 10 deletions

1603
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
"description": "yeahhh", "description": "yeahhh",
"main": "server/server.js", "main": "server/server.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
@ -14,5 +15,11 @@
"express": "^4.14.0", "express": "^4.14.0",
"mongodb": "^2.2.5", "mongodb": "^2.2.5",
"mongoose": "^4.5.9" "mongoose": "^4.5.9"
},
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^3.0.2",
"nodemon": "^1.10.2",
"supertest": "^2.0.0"
} }
} }

View File

@ -2,8 +2,6 @@ var express = require('express')
var bodyParser = require('body-parser') var bodyParser = require('body-parser')
var {mongoose} = require('./db/mongoose') var {mongoose} = require('./db/mongoose')
// models
var {User} = require('./models/user') var {User} = require('./models/user')
var {Todo} = require('./models/todo') var {Todo} = require('./models/todo')
@ -17,12 +15,14 @@ app.post('/todos', (req, res) => {
}); });
todo.save().then((doc) => { todo.save().then((doc) => {
res.send(doc) return res.send(doc);
}, (e) => { }, (e) => {
res.status(400).send(e); return res.status(400).send(e);
})
})
app.listen(3000, () => {
console.log("Started on port 3000");
}); });
});
app.listen(8888, () => {
console.log("Started on port 8888");
});
module.exports = {app}

View File

@ -0,0 +1,35 @@
const expect = require('expect');
const request = require('supertest');
const {app} = require('./../server');
const {Todo} = require('./../models/todo');
beforeEach((done) => {
Todo.remove({}).then(() => done());
});
describe('POST /todos', () => {
it('should create a new todo', (done) => {
var text = 'X GON GIVE IT TO YA';
request(app)
.post('/todos')
.send({text})
.expect(200)
.expect((res) => {
expect(res.body.text).toBe(text);
})
.end((err, res) => {
if (err){
console.log(err);
return done(err);
}
Todo.find().then((todos) => {
expect(todos.length).toBe(1);
expect(todos[0].text).toBe(text);
})
done();
}).catch((err) => done(err))
});
});