tests
This commit is contained in:
parent
eac8779435
commit
9c7041a80f
1603
package-lock.json
generated
1603
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,8 @@
|
||||
"description": "yeahhh",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "mocha server/**/*.test.js",
|
||||
"test-watch": "nodemon --exec 'npm test'"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
@ -14,5 +15,11 @@
|
||||
"express": "^4.14.0",
|
||||
"mongodb": "^2.2.5",
|
||||
"mongoose": "^4.5.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expect": "^1.20.2",
|
||||
"mocha": "^3.0.2",
|
||||
"nodemon": "^1.10.2",
|
||||
"supertest": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ var express = require('express')
|
||||
var bodyParser = require('body-parser')
|
||||
|
||||
var {mongoose} = require('./db/mongoose')
|
||||
|
||||
// models
|
||||
var {User} = require('./models/user')
|
||||
var {Todo} = require('./models/todo')
|
||||
|
||||
@ -17,12 +15,14 @@ app.post('/todos', (req, res) => {
|
||||
});
|
||||
|
||||
todo.save().then((doc) => {
|
||||
res.send(doc)
|
||||
return res.send(doc);
|
||||
}, (e) => {
|
||||
res.status(400).send(e);
|
||||
})
|
||||
})
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log("Started on port 3000");
|
||||
return res.status(400).send(e);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(8888, () => {
|
||||
console.log("Started on port 8888");
|
||||
});
|
||||
|
||||
module.exports = {app}
|
||||
|
35
server/tests/server.test.js
Normal file
35
server/tests/server.test.js
Normal 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))
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user