added tests for password validations

This commit is contained in:
Ben Wheeler 2019-07-02 17:49:29 -04:00
parent 585340d289
commit 67ad5fc383
2 changed files with 42 additions and 1 deletions

View file

@ -52,7 +52,10 @@ module.exports.validatePassword = password => {
}; };
module.exports.validatePasswordConfirm = (password, passwordConfirm) => { module.exports.validatePasswordConfirm = (password, passwordConfirm) => {
if (password !== passwordConfirm) { if (!passwordConfirm) {
return {valid: false, errMsgId: 'form.validationRequired'};
} else if (password !== passwordConfirm) {
// TODO: add a new string for this case
return {valid: false, errMsgId: 'general.error'}; return {valid: false, errMsgId: 'general.error'};
} }
return {valid: true}; return {valid: true};

View file

@ -26,3 +26,41 @@ tap.test('validate username locally', t => {
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameRegexp'}); t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameRegexp'});
t.end(); t.end();
}); });
tap.test('validate password', t => {
let response;
t.type(validate.validatePassword, 'function');
response = validate.validatePassword('abcdef');
t.deepEqual(response, {valid: true});
response = validate.validatePassword('abcdefghijklmnopqrst');
t.deepEqual(response, {valid: true});
response = validate.validatePassword('passwo');
t.deepEqual(response, {valid: true});
response = validate.validatePassword('');
t.deepEqual(response, {valid: false, errMsgId: 'form.validationRequired'});
response = validate.validatePassword('abcde');
t.deepEqual(response, {valid: false, errMsgId: 'registration.validationPasswordLength'});
response = validate.validatePassword('password');
t.deepEqual(response, {valid: false, errMsgId: 'registration.validationPasswordNotEquals'});
t.end();
});
tap.test('validate password confirm', t => {
let response;
t.type(validate.validatePasswordConfirm, 'function');
response = validate.validatePasswordConfirm('abcdef', 'abcdef');
t.deepEqual(response, {valid: true});
response = validate.validatePasswordConfirm('abcdefghijklmnopqrst', 'abcdefghijklmnopqrst');
t.deepEqual(response, {valid: true});
response = validate.validatePasswordConfirm('passwo', 'passwo');
t.deepEqual(response, {valid: true});
response = validate.validatePasswordConfirm('', '');
t.deepEqual(response, {valid: false, errMsgId: 'form.validationRequired'});
response = validate.validatePasswordConfirm('abcdef', 'abcdefg');
t.deepEqual(response, {valid: false, errMsgId: 'general.error'});
response = validate.validatePasswordConfirm('abcdef', '123456');
t.deepEqual(response, {valid: false, errMsgId: 'general.error'});
response = validate.validatePasswordConfirm('', 'abcdefg');
t.deepEqual(response, {valid: false, errMsgId: 'general.error'});
t.end();
});