Skip to content

Commit 20dcff0

Browse files
committed
0.0.5
1 parent 251afb7 commit 20dcff0

File tree

6 files changed

+135
-3196
lines changed

6 files changed

+135
-3196
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ node_js:
44
script:
55
- npm run lint
66
- npm run test
7+
- npm run build
78
services:
89
- mongodb

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "es6-express-mongoose-starter",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Express & Mongoose starter kit written in ES6 for NodeJS.",
55
"main": "src/server.js",
66
"repository": {
@@ -32,8 +32,9 @@
3232
},
3333
"scripts": {
3434
"serve": "NODE_ENV=dev nodemon src/server.js --exec \"npm run lint -s && babel-node\"",
35-
"build": "NODE_ENV=prod npm run lint -s && npm run test && babel src --out-dir build",
35+
"build": "babel src --out-dir build",
3636
"lint": "./node_modules/.bin/eslint src",
37-
"test": "NODE_ENV=test mocha --timeout 30000 --compilers js:babel-register"
37+
"test": "NODE_ENV=test mocha --exit --timeout 30000 --compilers js:babel-register",
38+
"test:watch": "NODE_ENV=test mocha --timeout 30000 --compilers js:babel-register"
3839
}
3940
}

src/api/todo/todo.ctrl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function getAll(req, res) {
1515

1616
function update(req, res) {
1717
const { id } = req.params;
18-
const { name, completed } = req.body.name;
18+
const { name, completed } = req.body;
1919

2020
TodoDa.update(id, name, completed)
2121
.then(() => res.sendStatus(200))

test/todo.spec.js

+128-118
Original file line numberDiff line numberDiff line change
@@ -14,151 +14,161 @@ chai.use(chaiHttp);
1414
* Add mockTodo into storage
1515
*/
1616
function addTodoToStorage(name, cb) {
17-
chai.request(server)
18-
.post('/api/v1/todo')
19-
.send({ name })
20-
.end((err, res) => {
21-
if(cb) {
22-
cb(err, res);
23-
}
24-
});
17+
chai
18+
.request(server)
19+
.post('/api/v1/todo')
20+
.send({ name })
21+
.end((err, res) => {
22+
if (cb) {
23+
cb(err, res);
24+
}
25+
});
2526
}
2627

2728
describe('Todos', () => {
28-
before((done) => {
29-
mongoose.disconnect();
30-
mockgoose.helper.reset();
31-
mockgoose.prepareStorage()
32-
.then(() => {
33-
mongoose.connect(config.db, (err) => {
34-
done(err);
35-
})
36-
})
29+
before(done => {
30+
mongoose.disconnect();
31+
mockgoose.helper.reset();
32+
mockgoose.prepareStorage().then(() => {
33+
mongoose.connect(
34+
config.db,
35+
err => {
36+
done(err);
37+
}
38+
);
3739
});
40+
});
3841

39-
40-
describe('/GET todo', () => {
41-
it('it should get a empty list of todos', (done) => {
42-
chai.request(server)
43-
.get('/api/v1/todo')
44-
.end((err, res) => {
45-
res.should.have.status(200);
46-
res.body.should.be.a('array').with.lengthOf(0);
47-
done();
48-
})
42+
describe('/GET todo', () => {
43+
it('it should get a empty list of todos', done => {
44+
chai
45+
.request(server)
46+
.get('/api/v1/todo')
47+
.end((err, res) => {
48+
res.should.have.status(200);
49+
res.body.should.be.a('array').with.lengthOf(0);
50+
done();
4951
});
52+
});
5053

51-
it('it should get a list of todos', (done) => {
52-
addTodoToStorage('Mock Todo', (err, res) => {
53-
chai.request(server)
54-
.get('/api/v1/todo')
55-
.end((err, res) => {
56-
res.should.have.status(200);
57-
res.body.should.be.a('array').with.lengthOf(1);
58-
res.body.should.to.deep.equal([res.body[0]]);
59-
done();
60-
})
61-
});
62-
});
54+
it('it should get a list of todos', done => {
55+
addTodoToStorage('Mock Todo', (err, res) => {
56+
chai
57+
.request(server)
58+
.get('/api/v1/todo')
59+
.end((err, res) => {
60+
res.should.have.status(200);
61+
res.body.should.be.a('array').with.lengthOf(1);
62+
res.body.should.to.deep.equal([res.body[0]]);
63+
done();
64+
});
65+
});
6366
});
67+
});
6468

65-
describe('/POST todo', () => {
66-
it('should create a todo with a name property', (done) => {
67-
const payload = { name: 'Just another todo' };
68-
chai.request(server)
69-
.post('/api/v1/todo')
70-
.send(payload)
71-
.end((err, res) => {
72-
res.should.have.status(200);
73-
res.body.should.be.a('object');
74-
res.body.should.have.property('name').eql(payload.name);
75-
res.body.should.have.property('completed').eql(false);
76-
done();
77-
});
69+
describe('/POST todo', () => {
70+
it('should create a todo with a name property', done => {
71+
const payload = { name: 'Just another todo' };
72+
chai
73+
.request(server)
74+
.post('/api/v1/todo')
75+
.send(payload)
76+
.end((err, res) => {
77+
res.should.have.status(200);
78+
res.body.should.be.a('object');
79+
res.body.should.have.property('name').eql(payload.name);
80+
res.body.should.have.property('completed').eql(false);
81+
done();
7882
});
83+
});
7984

80-
it('should not create a todo with a missing name property', (done) => {
81-
chai.request(server)
82-
.post('/api/v1/todo')
83-
.end((err, res) => {
84-
res.should.have.status(422);
85-
done();
86-
});
85+
it('should not create a todo with a missing name property', done => {
86+
chai
87+
.request(server)
88+
.post('/api/v1/todo')
89+
.end((err, res) => {
90+
res.should.have.status(422);
91+
done();
8792
});
8893
});
94+
});
8995

90-
describe('/PUT todo/:id', () => {
91-
let todoMock;
96+
describe('/PUT todo/:id', () => {
97+
let todoMock;
9298

93-
before((done) => {
94-
addTodoToStorage('Mock Todo Name for Modification', (err, res) => {
95-
todoMock = res.body;
96-
done();
97-
});
98-
});
99+
before(done => {
100+
addTodoToStorage('Mock Todo Name for Modification', (err, res) => {
101+
todoMock = res.body;
102+
done();
103+
});
104+
});
99105

100-
it('should update a todo', (done) => {
101-
const update = {
102-
name: 'Renamed Todo', completed: true
103-
};
104-
105-
chai.request(server)
106-
.put('/api/v1/todo/' + todoMock._id)
107-
.send(update)
108-
.end((err, res) => {
109-
res.should.have.status(200);
110-
done();
111-
});
112-
});
106+
it('should update a todo', done => {
107+
const update = {
108+
name: 'Renamed Todo',
109+
completed: true
110+
};
113111

114-
it('should return a 422 status if body is missing', (done) => {
115-
chai.request(server)
116-
.put('/api/v1/todo/' + todoMock._id)
117-
.end((err, res) => {
118-
res.should.have.status(422);
119-
done();
120-
});
112+
chai
113+
.request(server)
114+
.put('/api/v1/todo/' + todoMock._id)
115+
.send(update)
116+
.end((err, res) => {
117+
res.should.have.status(200);
118+
done();
121119
});
120+
});
122121

123-
it('should return a 422 status if id is wrong', (done) => {
124-
chai.request(server)
125-
.put('/api/v1/todo/A-WRONG-ID')
126-
.send({ name: 'Test'})
127-
.end((err, res) => {
128-
res.should.have.status(422);
129-
done();
130-
});
122+
it('should return a 422 status if body is missing', done => {
123+
chai
124+
.request(server)
125+
.put('/api/v1/todo/' + todoMock._id)
126+
.end((err, res) => {
127+
res.should.have.status(422);
128+
done();
131129
});
130+
});
132131

132+
it('should return a 422 status if id is wrong', done => {
133+
chai
134+
.request(server)
135+
.put('/api/v1/todo/A-WRONG-ID')
136+
.send({ name: 'Test' })
137+
.end((err, res) => {
138+
res.should.have.status(422);
139+
done();
140+
});
133141
});
142+
});
134143

135-
describe('/DELETE todo/:id', () => {
136-
let todoMock;
144+
describe('/DELETE todo/:id', () => {
145+
let todoMock;
137146

138-
before((done) => {
139-
addTodoToStorage('Mock Todo Name to delete', (err, res) => {
140-
todoMock = res.body;
141-
done();
142-
});
143-
});
147+
before(done => {
148+
addTodoToStorage('Mock Todo Name to delete', (err, res) => {
149+
todoMock = res.body;
150+
done();
151+
});
152+
});
144153

145-
it('should delete a todo', (done) => {
146-
chai.request(server)
147-
.delete('/api/v1/todo/' + todoMock._id)
148-
.end((err, res) => {
149-
res.should.have.status(200);
150-
done();
151-
});
154+
it('should delete a todo', done => {
155+
chai
156+
.request(server)
157+
.delete('/api/v1/todo/' + todoMock._id)
158+
.end((err, res) => {
159+
res.should.have.status(200);
160+
done();
152161
});
162+
});
153163

154-
it('should return a 422 status if id is wrong', (done) => {
155-
chai.request(server)
156-
.put('/api/v1/todo/A-WRONG-ID')
157-
.end((err, res) => {
158-
res.should.have.status(422);
159-
done();
160-
});
164+
it('should return a 422 status if id is wrong', done => {
165+
chai
166+
.request(server)
167+
.put('/api/v1/todo/A-WRONG-ID')
168+
.end((err, res) => {
169+
res.should.have.status(422);
170+
done();
161171
});
162172
});
163-
173+
});
164174
});

0 commit comments

Comments
 (0)