Skip to content

Commit

Permalink
Create database for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioImp committed Dec 1, 2019
1 parent 6c7698c commit a0e8d6b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"jwtPrivateKey": "",
"jwtExpirationTime": "",
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": ""
"AWS_SECRET_ACCESS_KEY": "",
"sequelize_Database": "postgres://vlbganljybqkij:19f31cdd0c3704ba6f463d0236de1e224187121d17811cb950b46c29daa5ace4@ec2-54-246-100-246.eu-west-1.compute.amazonaws.com:5432/d9dfhu5citam1c?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"
}
3 changes: 2 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"jwtPrivateKey": "1234",
"jwtExpirationTime": "2 days",
"AWS_ACCESS_KEY_ID": "aaaa",
"AWS_SECRET_ACCESS_KEY": "aaaa"
"AWS_SECRET_ACCESS_KEY": "aaaa",
"sequelize_Database": "postgres://wryvvzpcpmxzkh:f49e3b130adcbafe54c1d34e9c19fbca0137c5d9b9ca55dcb7a7e67de516cf6d@ec2-54-228-243-238.eu-west-1.compute.amazonaws.com:5432/dffan03venodiu?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"
}
3 changes: 2 additions & 1 deletion sequelizeSettings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Sequelize = require('sequelize');
const dbURL = 'postgres://vlbganljybqkij:19f31cdd0c3704ba6f463d0236de1e224187121d17811cb950b46c29daa5ace4@ec2-54-246-100-246.eu-west-1.compute.amazonaws.com:5432/d9dfhu5citam1c?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory';
const config = require('config');
const dbURL = config.get('sequelize_Database');


const postgresDb = new Sequelize(dbURL);
Expand Down
25 changes: 23 additions & 2 deletions tests/integration/routes/login.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


const request = require('supertest');

let server;
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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"
}
})
})


Expand Down

0 comments on commit a0e8d6b

Please sign in to comment.