Skip to content

Commit

Permalink
#bg-163498757 Login verification bug (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebzeal authored and seunkoko committed Jan 31, 2019
1 parent 350262a commit b2fb5ab
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 41 deletions.
10 changes: 10 additions & 0 deletions server/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Empty file added server/migrations/.gitkeep
Empty file.
38 changes: 0 additions & 38 deletions server/migrations/20190121154422-create-user-follows.js

This file was deleted.

3 changes: 1 addition & 2 deletions server/migrations/20190127133424-create-reading-stats.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
1 change: 1 addition & 0 deletions server/seeders/20190115151310-demoUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions server/test/controllers/comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
12 changes: 11 additions & 1 deletion server/test/controllers/userController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit b2fb5ab

Please sign in to comment.