From b2fb5abbe5b3664ec4d1c5317f06d88457cc8c51 Mon Sep 17 00:00:00 2001 From: Olusola Ajayi Date: Thu, 31 Jan 2019 12:42:19 +0100 Subject: [PATCH] #bg-163498757 Login verification bug (#55) --- server/controllers/UserController.js | 10 +++++ server/migrations/.gitkeep | 0 .../20190121154422-create-user-follows.js | 38 ------------------- .../20190127133424-create-reading-stats.js | 3 +- server/seeders/20190115151310-demoUser.js | 1 + server/test/controllers/comment.spec.js | 1 + .../test/controllers/userController.spec.js | 12 +++++- 7 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 server/migrations/.gitkeep delete mode 100644 server/migrations/20190121154422-create-user-follows.js diff --git a/server/controllers/UserController.js b/server/controllers/UserController.js index eaa7ab58..4a5960f7 100755 --- a/server/controllers/UserController.js +++ b/server/controllers/UserController.js @@ -300,6 +300,16 @@ class UserController { }); } + if (foundUser.dataValues.isVerified !== true) { + return res.status(401).send({ + status: 'failure', + data: { + statusCode: 401, + message: 'Your account has not been verified' + } + }); + } + const payload = { userId: foundUser.id, userName: foundUser.userName, diff --git a/server/migrations/.gitkeep b/server/migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/server/migrations/20190121154422-create-user-follows.js b/server/migrations/20190121154422-create-user-follows.js deleted file mode 100644 index 2ba3eed4..00000000 --- a/server/migrations/20190121154422-create-user-follows.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; -module.exports = { - up: (queryInterface, Sequelize) => { - return queryInterface.createTable('UserFollows', { - id: { - allowNull: false, - autoIncrement: true, - primaryKey: true, - type: Sequelize.INTEGER - }, - followersId: { - type: Sequelize.UUID, - references: { - model: 'Users', - key: 'id' - } - }, - usersId: { - type: Sequelize.UUID, - references: { - model: 'Users', - key: 'id' - } - }, - createdAt: { - allowNull: false, - type: Sequelize.DATE - }, - updatedAt: { - allowNull: false, - type: Sequelize.DATE - } - }); - }, - down: (queryInterface, Sequelize) => { - return queryInterface.dropTable('UserFollows'); - } -}; diff --git a/server/migrations/20190127133424-create-reading-stats.js b/server/migrations/20190127133424-create-reading-stats.js index 2eebfa9d..989895f7 100644 --- a/server/migrations/20190127133424-create-reading-stats.js +++ b/server/migrations/20190127133424-create-reading-stats.js @@ -1,7 +1,6 @@ export default { up: (queryInterface, Sequelize) => { - return queryInterface.sequelize - .query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";') + return queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";') .then(() => { return queryInterface.createTable('ReadingStats', { id: { diff --git a/server/seeders/20190115151310-demoUser.js b/server/seeders/20190115151310-demoUser.js index 210d14b6..3abfcadf 100755 --- a/server/seeders/20190115151310-demoUser.js +++ b/server/seeders/20190115151310-demoUser.js @@ -25,6 +25,7 @@ export default { email: 'kabir@now.com', bio: 'Learning life now', password: '$2y$10$QCQ1uW0OWH7xKOvJ9gNWsewzoXSjvAmXw21mcZBEB52TN6T/f2Xfy', + isVerified: true, authTypeId: '15745c60-7b1a-11e8-9c9c-2d42b21b1a3e', roleId: '3ceb546e-054d-4c1d-8860-e27c209d4ae4', getEmailsNotification: true, diff --git a/server/test/controllers/comment.spec.js b/server/test/controllers/comment.spec.js index 6fd8fdb0..dc474c40 100644 --- a/server/test/controllers/comment.spec.js +++ b/server/test/controllers/comment.spec.js @@ -191,6 +191,7 @@ describe('Comment Model', () => { }); expect(response.status).to.eqls(404); expect(response.body.status).to.eqls('failure'); + expect(response.body.data.message).to.eqls('Article not found'); }); }); describe('Delete comment', () => { diff --git a/server/test/controllers/userController.spec.js b/server/test/controllers/userController.spec.js index 09795080..31f16551 100755 --- a/server/test/controllers/userController.spec.js +++ b/server/test/controllers/userController.spec.js @@ -142,11 +142,21 @@ describe('User Model', () => { expect(response.body.data.message).to.eqls('Sorry!!, Your login information is not correct.'); }); + it('User should get an error for unverified account', async () => { + const response = await chai + .request(app) + .post('/api/v1/auth/login') + .send({ user: userInfo.email, password: userInfo.password }); + expect(response.status).to.eql(401); + expect(response.body.status).to.eqls('failure'); + expect(response.body.data.message).to.eqls('Your account has not been verified'); + }); + it('User should get loggedIn and token returned when correct credentials are provided', async () => { const response = await chai .request(app) .post('/api/v1/auth/login') - .send({ user: userInfo.userName, password: userInfo.password }); + .send({ user: 'kabir', password: 'Blahblah' }); expect(response.status).to.eql(200); expect(response.body.status).to.eqls('success'); expect(response.body.data.token).to.be.a('String');