forked from danielfsousa/express-rest-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba7d423
commit 71c51a7
Showing
4 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"author": "Daniel Sousa <[email protected]>", | ||
"main": "src/index.js", | ||
"private": false, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=7.6", | ||
"yarn": "*" | ||
|
@@ -102,6 +103,5 @@ | |
"sinon": "^3.0.0", | ||
"sinon-chai": "^2.10.0", | ||
"supertest": "^3.0.0" | ||
}, | ||
"license": "MIT" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
|
@@ -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; | ||
}); | ||
|