revised username tests to separate them, make them clearer

This commit is contained in:
Ben Wheeler 2019-10-30 15:16:15 -04:00
parent 87a73b3fce
commit a9810b6a1f

View file

@ -1,27 +1,55 @@
const validate = require('../../../src/lib/validate'); const validate = require('../../../src/lib/validate');
describe('unit test lib/validate.js', () => { describe('unit test lib/validate.js', () => {
test('validate username locally', () => {
test('validate username exists locally', () => {
let response; let response;
expect(typeof validate.validateUsernameLocally).toBe('function'); expect(typeof validate.validateUsernameLocally).toBe('function');
response = validate.validateUsernameLocally('abc'); response = validate.validateUsernameLocally('abc');
expect(response).toEqual({valid: true}); expect(response).toEqual({valid: true});
response = validate.validateUsernameLocally('abcdefghijklmnopqrst');
expect(response).toEqual({valid: true});
response = validate.validateUsernameLocally('abc-def-ghi');
expect(response).toEqual({valid: true});
response = validate.validateUsernameLocally(''); response = validate.validateUsernameLocally('');
expect(response).toEqual({valid: false, errMsgId: 'general.required'}); expect(response).toEqual({valid: false, errMsgId: 'general.required'});
});
test('validate username length locally', () => {
let response;
response = validate.validateUsernameLocally('abcdefghijklmnopqrst');
expect(response).toEqual({valid: true});
response = validate.validateUsernameLocally('ab'); response = validate.validateUsernameLocally('ab');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameMinLength'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameMinLength'});
response = validate.validateUsernameLocally('abcdefghijklmnopqrstu'); response = validate.validateUsernameLocally('abcdefghijklmnopqrstu');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameMaxLength'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameMaxLength'});
response = validate.validateUsernameLocally('abc def'); });
test('validate username hyphens allowed', () => {
const response = validate.validateUsernameLocally('-abc-def-ghi-');
expect(response).toEqual({valid: true});
});
test('validate username underscores allowed', () => {
const response = validate.validateUsernameLocally('_abc_def_ghi_');
expect(response).toEqual({valid: true});
});
test('validate username spaces not allowed', () => {
const response = validate.validateUsernameLocally('abc def');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
});
test('validate username special chars not allowed', () => {
let response;
response = validate.validateUsernameLocally('abc!def'); response = validate.validateUsernameLocally('abc!def');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
response = validate.validateUsernameLocally('amiascratcher?');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
});
test('validate username unicode chars not allowed', () => {
let response;
response = validate.validateUsernameLocally('abc😄def'); response = validate.validateUsernameLocally('abc😄def');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
response = validate.validateUsernameLocally('🦆🦆🦆😺😺😺');
expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'});
}); });
test('validate password', () => { test('validate password', () => {