Skip to content

Commit

Permalink
bug(users): Fix email duplication
Browse files Browse the repository at this point in the history
- normalizes email upon signup

[Delivers #167975800]
  • Loading branch information
leonardnjura committed Aug 21, 2019
1 parent 7c63683 commit 9ce0616
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/server/middlewares/validateBody.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const Joi = require('joi');

module.exports = (req, res, next, schema) => {
if (req.body.email) {
const email = req.body.email;
req.body.email = email.toLowerCase();
}
Joi.validate(req.body, schema, error => {
if (error) {
return res.status(400).send({ message: error.details[0].message });
Expand Down
16 changes: 16 additions & 0 deletions src/tests/users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const newUser = {
username: 'Oliver Brice',
};

const newUserCaps = {
...testUser,
email: '[email protected]',
username: 'Oliver Brice',
};


jest.mock('nodemailer', () => ({
createTransport: () => ({
sendMail: (options, call) => {
Expand Down Expand Up @@ -56,6 +63,15 @@ describe('User tests', () => {
});
});

it('should normalize email', done => {
sendRequest('post', '/api/users', newUser, () => {
sendRequest('post', '/api/users', newUserCaps, (err, res) => {
expect(res.text).toMatch('email must be unique');
done();
});
});
});

it('should login an authorised user', done => {
sendRequest(
'post',
Expand Down

0 comments on commit 9ce0616

Please sign in to comment.