-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
4 changed files
with
29 additions
and
5 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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
|
||
|
||
const request = require('supertest'); | ||
|
||
let server; | ||
|
@@ -8,6 +6,9 @@ let app; | |
const http = require('http'); | ||
const db = require('../../../sequelizeSettings.js'); | ||
|
||
const bcrypt = require('bcrypt'); | ||
const Owner = require('../../../models/owner.js'); | ||
|
||
describe('/api/user/login', () => { | ||
|
||
//start the server before each test suite | ||
|
@@ -32,6 +33,19 @@ describe('/api/user/login', () => { | |
//it should return a 201 because the data sent are related to a valid user | ||
it('should return a 201', async () => { | ||
|
||
//first of all, create the user in the database | ||
const salt = await bcrypt.genSalt(10); | ||
const hashed = await bcrypt.hash("123456", salt); | ||
|
||
await Owner.create({ | ||
Username: "xXEmilioXx", | ||
Name: "Emilio", | ||
Surname: "Imperiali", | ||
Email: "[email protected]", | ||
Password: hashed | ||
}); | ||
|
||
//then check if the login works by checking if the response has code 201 | ||
const exec = () => { | ||
return request(app) | ||
.post('/api/user/login') | ||
|
@@ -40,6 +54,13 @@ describe('/api/user/login', () => { | |
|
||
const res = await exec(); | ||
expect(res.status).toBe(201); | ||
|
||
//remove the previously created user from the database | ||
await Owner.destroy({ | ||
where: { | ||
Username: "xXEmilioXx" | ||
} | ||
}) | ||
}) | ||
|
||
|
||
|