mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
revised username tests to separate them, make them clearer
This commit is contained in:
parent
87a73b3fce
commit
a9810b6a1f
1 changed files with 34 additions and 6 deletions
|
@ -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', () => {
|
||||||
|
|
Loading…
Reference in a new issue