mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
added tests for password validations
This commit is contained in:
parent
585340d289
commit
67ad5fc383
2 changed files with 42 additions and 1 deletions
|
@ -52,7 +52,10 @@ module.exports.validatePassword = password => {
|
|||
};
|
||||
|
||||
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: true};
|
||||
|
|
|
@ -26,3 +26,41 @@ tap.test('validate username locally', t => {
|
|||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
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();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue