diff --git a/test/unit/lib/validate.test.js b/test/unit/lib/validate.test.js index a051e1faa..6074736d5 100644 --- a/test/unit/lib/validate.test.js +++ b/test/unit/lib/validate.test.js @@ -1,27 +1,55 @@ const validate = require('../../../src/lib/validate'); describe('unit test lib/validate.js', () => { - test('validate username locally', () => { + + test('validate username exists locally', () => { let response; expect(typeof validate.validateUsernameLocally).toBe('function'); response = validate.validateUsernameLocally('abc'); 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(''); 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'); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameMinLength'}); response = validate.validateUsernameLocally('abcdefghijklmnopqrstu'); 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'}); + }); + + test('validate username special chars not allowed', () => { + let response; response = validate.validateUsernameLocally('abc!def'); 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'); expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); + response = validate.validateUsernameLocally('🦆🦆🦆😺😺😺'); + expect(response).toEqual({valid: false, errMsgId: 'registration.validationUsernameRegexp'}); }); test('validate password', () => {