split password tests up

This commit is contained in:
Ben Wheeler 2019-10-30 15:09:25 -04:00
parent 6bf27b7e8a
commit 7dff707782

View file

@ -24,21 +24,21 @@ describe('unit test lib/validate.js', () => {
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
}); });
test('validate password', () => { test('validate password existence', () => {
let response; let response;
expect(typeof validate.validatePassword).toBe('function'); expect(typeof validate.validatePassword).toBe('function');
response = validate.validatePassword('abcdef'); response = validate.validatePassword('abcdef');
expect(response).toEqual({valid: true}); expect(response).toEqual({valid: true});
response = validate.validatePassword('abcdefghijklmnopqrst');
expect(response).toEqual({valid: true});
response = validate.validatePassword('passwo');
expect(response).toEqual({valid: true});
response = validate.validatePassword(''); response = validate.validatePassword('');
expect(response).toEqual({valid: false, errMsgId: 'general.required'}); expect(response).toEqual({valid: false, errMsgId: 'general.required'});
});
test('validate password length', () => {
let response;
response = validate.validatePassword('abcdefghijklmnopqrst');
expect(response).toEqual({valid: true});
response = validate.validatePassword('abcde'); response = validate.validatePassword('abcde');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
response = validate.validatePassword('password');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotEquals'});
response = validate.validatePassword('😺'); response = validate.validatePassword('😺');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
response = validate.validatePassword('😺🦆🐝'); response = validate.validatePassword('😺🦆🐝');
@ -47,6 +47,15 @@ describe('unit test lib/validate.js', () => {
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
response = validate.validatePassword('😺🦆🐝🐮🐠🐻'); response = validate.validatePassword('😺🦆🐝🐮🐠🐻');
expect(response).toEqual({valid: true}); expect(response).toEqual({valid: true});
});
test('validate password cannot be "password"', () => {
const response = validate.validatePassword('password');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotEquals'});
});
test('validate password cannot be same as username', () => {
let response;
response = validate.validatePassword('abcdefg', 'abcdefg'); response = validate.validatePassword('abcdefg', 'abcdefg');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotUsername'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotUsername'});
response = validate.validatePassword('abcdefg', 'abcdefG'); response = validate.validatePassword('abcdefg', 'abcdefG');