Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfsousa committed Oct 4, 2017
1 parent ba7d423 commit 71c51a7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "node",
"runtimeExecutable": "node",
"runtimeArgs": [
"--inspect"
],
"program": "${workspaceRoot}/src/index.js",
"restart": true,
"port": 9229,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
],
"compounds": []
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Daniel Sousa <[email protected]>",
"main": "src/index.js",
"private": false,
"license": "MIT",
"engines": {
"node": ">=7.6",
"yarn": "*"
Expand Down Expand Up @@ -102,6 +103,5 @@
"sinon": "^3.0.0",
"sinon-chai": "^2.10.0",
"supertest": "^3.0.0"
},
"license": "MIT"
}
}
3 changes: 2 additions & 1 deletion src/api/tests/integration/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ describe('Authentication API', () => {
});

it('should report error when email and password don\'t match', () => {
dbUser.password = 'xxx'
return request(app)
.post('/v1/auth/login')
.send(user)
.send(dbUser)
.expect(httpStatus.UNAUTHORIZED)
.then((res) => {
const code = res.body.code;
Expand Down
16 changes: 11 additions & 5 deletions src/api/tests/integration/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const request = require('supertest');
const httpStatus = require('http-status');
const { expect } = require('chai');
const sinon = require('sinon');
const bcrypt = require('bcryptjs');
const { some, omitBy, isNil } = require('lodash');
const app = require('../../../index');
const User = require('../../models/user.model');
Expand All @@ -26,43 +27,48 @@ async function format(user) {
return omitBy(dbUser, isNil);
}

describe('Users API', () => {
describe('Users API', async () => {
let adminAccessToken;
let userAccessToken;
let dbUsers;
let user;
let admin;

const password = '123456'
const passwordHashed = await bcrypt.hash(password, 1)

beforeEach(async () => {
dbUsers = {
branStark: {
email: '[email protected]',
password: 'mypassword',
password: passwordHashed,
name: 'Bran Stark',
role: 'admin',
},
jonSnow: {
email: '[email protected]',
password: '123456',
password: passwordHashed,
name: 'Jon Snow',
},
};

user = {
email: '[email protected]',
password: '123456',
password,
name: 'Daniel Sousa',
};

admin = {
email: '[email protected]',
password: '123456',
password,
name: 'Daniel Sousa',
role: 'admin',
};

await User.remove({});
await User.insertMany([dbUsers.branStark, dbUsers.jonSnow]);
dbUsers.branStark.password = password
dbUsers.jonSnow.password = password
adminAccessToken = (await User.findAndGenerateToken(dbUsers.branStark)).accessToken;
userAccessToken = (await User.findAndGenerateToken(dbUsers.jonSnow)).accessToken;
});
Expand Down

0 comments on commit 71c51a7

Please sign in to comment.