Skip to content

Commit

Permalink
Merge branch 'develop' into chore/update-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
AnayoOleru committed May 17, 2019
2 parents 3b8ac87 + b65eca6 commit e6a06f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
11 changes: 7 additions & 4 deletions server/joiSchema/confirmPasswordSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ const passwordSchema = Joi.object().keys({
password: Joi.string()
.strict()
.trim()
.regex(/^[a-zA-Z0-9]{3,30}$/)
.regex(/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/)
.min(8)
.required()
.error(() => 'Password is required'),
.error(
() =>
`Password must be greater than 8 and should contain at least one upper case letter, one lower case letter, one digit and one special character`
),
confirmPassword: Joi.string()
.strict()
.trim()
.regex(/^[a-zA-Z0-9]{3,30}$/)
.regex(/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/)
.min(8)
.required()
.error(() => 'confirmPassword is required'),
.error(() => 'Confirm Password is required'),
});

const emailSchema = Joi.object().keys({
Expand Down
2 changes: 1 addition & 1 deletion server/routes/reset-password.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ resetPasswordRouter.get('/reset/message', (req, res) => {
/**
* @swagger
*
* /new_password:
* /new-password:
* post:
* tags:
* - update password
Expand Down
38 changes: 22 additions & 16 deletions tests/reset-password.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: '12345asdf',
confirmPassword: '12345asdf',
password: '@H0ttestt',
confirmPassword: '@H0ttestt',
})
.set('Authorization', emailToken)
.end((err, res) => {
Expand All @@ -95,8 +95,8 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: '12345asdf',
confirmPassword: '12345asdf',
password: '@H0ttestt',
confirmPassword: '@H0ttestt',
})
.end((err, res) => {
expect(res).to.have.status(403);
Expand All @@ -112,8 +112,8 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: '12345asdf',
confirmPassword: '12345asdf',
password: '@H0ttestt',
confirmPassword: '@H0ttestt',
})
.set('Authorization', emailToken)
.end((err, res) => {
Expand All @@ -130,13 +130,15 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: '12345asdf',
confirmPassword: '12345wssasdf',
password: '@H0ttestt',
confirmPassword: 'H0ttestt',
})
.set('Authorization', emailToken)
.end((err, res) => {
expect(res).to.have.status(400);
expect(res.body.errors.body[0]).to.be.equal('Passwords do not match');
expect(res.body.errors.body[0]).to.be.equal(
'Confirm Password is required'
);
done();
});
});
Expand All @@ -146,12 +148,14 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
confirmPassword: '12345wssasdf',
confirmPassword: '@H0ttestt',
})
.set('Authorization', emailToken)
.end((err, res) => {
expect(res).to.have.status(400);
expect(res.body.errors.body[0]).to.be.equal('Password is required');
expect(res.body.errors.body[0]).to.be.equal(
'Password must be greater than 8 and should contain at least one upper case letter, one lower case letter, one digit and one special character'
);
done();
});
});
Expand All @@ -161,13 +165,13 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: '12345wssasdf',
password: '@H0ttestt',
})
.set('Authorization', emailToken)
.end((err, res) => {
expect(res).to.have.status(400);
expect(res.body.errors.body[0]).to.be.equal(
'confirmPassword is required'
'Confirm Password is required'
);
done();
});
Expand All @@ -184,7 +188,9 @@ describe('UPDATE Password', () => {
.set('Authorization', emailToken)
.end((err, res) => {
expect(res).to.have.status(400);
expect(res.body.errors.body[0]).to.be.equal('Password is required');
expect(res.body.errors.body[0]).to.be.equal(
'Password must be greater than 8 and should contain at least one upper case letter, one lower case letter, one digit and one special character'
);
done();
});
});
Expand All @@ -194,14 +200,14 @@ describe('UPDATE Password', () => {
.request(app)
.patch('/api/v1/auth/new-password')
.send({
password: 'dfddddjk',
password: '@H0ttestt',
confirmPassword: 'dfd',
})
.set('Authorization', emailToken)
.end((err, res) => {
expect(res).to.have.status(400);
expect(res.body.errors.body[0]).to.be.equal(
'confirmPassword is required'
'Confirm Password is required'
);
done();
});
Expand Down

0 comments on commit e6a06f6

Please sign in to comment.