Skip to content

Commit 71c51a7

Browse files
committedOct 4, 2017
Fix tests
1 parent ba7d423 commit 71c51a7

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed
 

‎.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515
"protocol": "inspector",
1616
"console": "integratedTerminal",
1717
"internalConsoleOptions": "neverOpen"
18+
},
19+
{
20+
"type": "node",
21+
"request": "launch",
22+
"name": "node",
23+
"runtimeExecutable": "node",
24+
"runtimeArgs": [
25+
"--inspect"
26+
],
27+
"program": "${workspaceRoot}/src/index.js",
28+
"restart": true,
29+
"port": 9229,
30+
"protocol": "inspector",
31+
"console": "integratedTerminal",
32+
"internalConsoleOptions": "neverOpen"
1833
}
1934
],
2035
"compounds": []

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Daniel Sousa <sousa.dfs@gmail.com>",
66
"main": "src/index.js",
77
"private": false,
8+
"license": "MIT",
89
"engines": {
910
"node": ">=7.6",
1011
"yarn": "*"
@@ -102,6 +103,5 @@
102103
"sinon": "^3.0.0",
103104
"sinon-chai": "^2.10.0",
104105
"supertest": "^3.0.0"
105-
},
106-
"license": "MIT"
106+
}
107107
}

‎src/api/tests/integration/auth.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ describe('Authentication API', () => {
160160
});
161161

162162
it('should report error when email and password don\'t match', () => {
163+
dbUser.password = 'xxx'
163164
return request(app)
164165
.post('/v1/auth/login')
165-
.send(user)
166+
.send(dbUser)
166167
.expect(httpStatus.UNAUTHORIZED)
167168
.then((res) => {
168169
const code = res.body.code;

‎src/api/tests/integration/user.test.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const request = require('supertest');
44
const httpStatus = require('http-status');
55
const { expect } = require('chai');
66
const sinon = require('sinon');
7+
const bcrypt = require('bcryptjs');
78
const { some, omitBy, isNil } = require('lodash');
89
const app = require('../../../index');
910
const User = require('../../models/user.model');
@@ -26,43 +27,48 @@ async function format(user) {
2627
return omitBy(dbUser, isNil);
2728
}
2829

29-
describe('Users API', () => {
30+
describe('Users API', async () => {
3031
let adminAccessToken;
3132
let userAccessToken;
3233
let dbUsers;
3334
let user;
3435
let admin;
3536

37+
const password = '123456'
38+
const passwordHashed = await bcrypt.hash(password, 1)
39+
3640
beforeEach(async () => {
3741
dbUsers = {
3842
branStark: {
3943
email: 'branstark@gmail.com',
40-
password: 'mypassword',
44+
password: passwordHashed,
4145
name: 'Bran Stark',
4246
role: 'admin',
4347
},
4448
jonSnow: {
4549
email: 'jonsnow@gmail.com',
46-
password: '123456',
50+
password: passwordHashed,
4751
name: 'Jon Snow',
4852
},
4953
};
5054

5155
user = {
5256
email: 'sousa.dfs@gmail.com',
53-
password: '123456',
57+
password,
5458
name: 'Daniel Sousa',
5559
};
5660

5761
admin = {
5862
email: 'sousa.dfs@gmail.com',
59-
password: '123456',
63+
password,
6064
name: 'Daniel Sousa',
6165
role: 'admin',
6266
};
6367

6468
await User.remove({});
6569
await User.insertMany([dbUsers.branStark, dbUsers.jonSnow]);
70+
dbUsers.branStark.password = password
71+
dbUsers.jonSnow.password = password
6672
adminAccessToken = (await User.findAndGenerateToken(dbUsers.branStark)).accessToken;
6773
userAccessToken = (await User.findAndGenerateToken(dbUsers.jonSnow)).accessToken;
6874
});

0 commit comments

Comments
 (0)
Please sign in to comment.