Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#167975800 Fix email duplication #210

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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