Skip to content

Commit b3142af

Browse files
committed
add unit testing
1 parent 0741ffe commit b3142af

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ pids
1313
# Dependency directory
1414
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
1515
node_modules
16+
17+
coverage

‎package.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"scripts": {
1010
"start": "node ./bin/www",
11-
"test": "jest"
11+
"test": "istanbul cover _mocha"
1212
},
1313
"author": {
1414
"name": "Tab Lee",
@@ -48,6 +48,9 @@
4848
"yazl": "^2.3.0"
4949
},
5050
"devDependencies": {
51-
"jest-cli": "^12.0.2"
51+
"istanbul": "^0.4.5",
52+
"mocha": "^3.0.2",
53+
"should": "^11.1.0",
54+
"supertest": "^2.0.0"
5255
}
5356
}

‎test/routes.auth.test.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var app = require('../app');
2+
var request = require('supertest')(app);
3+
var should = require("should");
4+
5+
describe('routes/auth/test.js', function() {
6+
var account = 'lisong2010@gmail.com';
7+
var password = '123456';
8+
describe('sign in', function(done) {
9+
it('should not sign in successful when account is empty', function(done) {
10+
request.post('/auth/login')
11+
.send({
12+
account: '',
13+
password: password
14+
})
15+
.end(function(err, res) {
16+
should.not.exist(err);
17+
res.text.should.containEql(`{"status":"ERROR","errorMessage":"请您输入邮箱地址"}`);
18+
done();
19+
});
20+
});
21+
it('should not sign in successful when account is not exist', function(done) {
22+
request.post('/auth/login')
23+
.send({
24+
account: account + '1',
25+
password: password
26+
})
27+
.end(function(err, res) {
28+
should.not.exist(err);
29+
res.text.should.containEql(`{"status":"ERROR","errorMessage":"您输入的邮箱或密码有误"}`);
30+
done();
31+
});
32+
});
33+
it('should not sign in successful when password is wrong', function(done) {
34+
request.post('/auth/login')
35+
.send({
36+
account: account,
37+
password: password + '1'
38+
})
39+
.end(function(err, res) {
40+
should.not.exist(err);
41+
res.text.should.containEql(`{"status":"ERROR","errorMessage":"您输入的邮箱或密码有误"}`);
42+
done();
43+
});
44+
});
45+
it('should sign in successful', function(done) {
46+
request.post('/auth/login')
47+
.send({
48+
account: account,
49+
password: password
50+
})
51+
.end(function(err, res) {
52+
should.not.exist(err);
53+
JSON.parse(res.text).status.should.containEql('OK')
54+
done();
55+
});
56+
});
57+
})
58+
});

0 commit comments

Comments
 (0)