diff --git a/config/default.json b/config/default.json index 73cdb493..1056cf9f 100644 --- a/config/default.json +++ b/config/default.json @@ -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" } \ No newline at end of file diff --git a/config/test.json b/config/test.json index b262e730..b284a8a8 100644 --- a/config/test.json +++ b/config/test.json @@ -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" } \ No newline at end of file diff --git a/sequelizeSettings.js b/sequelizeSettings.js index 5f620973..f70ba72b 100644 --- a/sequelizeSettings.js +++ b/sequelizeSettings.js @@ -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); diff --git a/tests/integration/routes/login.test.js b/tests/integration/routes/login.test.js index 4b73e79a..ab3d4af2 100644 --- a/tests/integration/routes/login.test.js +++ b/tests/integration/routes/login.test.js @@ -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: "emilio@mail.com", + 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" + } + }) })