mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
rewrote validate legacy unit test from using tap, to using jest
This commit is contained in:
parent
4ae69e1b49
commit
a6dc573f30
3 changed files with 63 additions and 67 deletions
|
@ -13,7 +13,7 @@
|
|||
"test:smoke:verbose": "tap ./test/integration-legacy/smoke-testing/*.js --timeout=3600 --no-coverage -R spec",
|
||||
"test:smoke:sauce": "SMOKE_REMOTE=true tap ./test/integration-legacy/smoke-testing/*.js --timeout=60000 --no-coverage -R classic",
|
||||
"test:unit": "npm run test:unit:jest && npm run test:unit:tap",
|
||||
"test:unit:jest": "jest ./test/unit/*.test.js && jest ./test/localization/*.test.js",
|
||||
"test:unit:jest": "jest ./test/unit/ && jest ./test/localization/*.test.js",
|
||||
"test:unit:tap": "tap ./test/{unit-legacy,localization-legacy}/*.js --no-coverage -R classic",
|
||||
"test:coverage": "tap ./test/{unit-legacy,localization-legacy}/*.js --coverage --coverage-report=lcov",
|
||||
"build": "npm run clean && npm run translate && webpack --bail",
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
const tap = require('tap');
|
||||
const validate = require('../../../src/lib/validate');
|
||||
|
||||
tap.tearDown(() => process.nextTick(process.exit));
|
||||
|
||||
tap.test('validate username locally', t => {
|
||||
let response;
|
||||
t.type(validate.validateUsernameLocally, 'function');
|
||||
response = validate.validateUsernameLocally('abc');
|
||||
t.deepEqual(response, {valid: true});
|
||||
response = validate.validateUsernameLocally('abcdefghijklmnopqrst');
|
||||
t.deepEqual(response, {valid: true});
|
||||
response = validate.validateUsernameLocally('abc-def-ghi');
|
||||
t.deepEqual(response, {valid: true});
|
||||
response = validate.validateUsernameLocally('');
|
||||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationRequired'});
|
||||
response = validate.validateUsernameLocally('ab');
|
||||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameMinLength'});
|
||||
response = validate.validateUsernameLocally('abcdefghijklmnopqrstu');
|
||||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameMaxLength'});
|
||||
response = validate.validateUsernameLocally('abc def');
|
||||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
response = validate.validateUsernameLocally('abc!def');
|
||||
t.deepEqual(response, {valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
response = validate.validateUsernameLocally('abc😄def');
|
||||
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();
|
||||
});
|
62
test/unit/lib/validate.test.js
Normal file
62
test/unit/lib/validate.test.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
const validate = require('../../../src/lib/validate');
|
||||
|
||||
describe('unit test lib/validate.js', () => {
|
||||
test('validate username 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: 'form.validationRequired'});
|
||||
response = validate.validateUsernameLocally('ab');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationUsernameMinLength'});
|
||||
response = validate.validateUsernameLocally('abcdefghijklmnopqrstu');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationUsernameMaxLength'});
|
||||
response = validate.validateUsernameLocally('abc def');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
response = validate.validateUsernameLocally('abc!def');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
response = validate.validateUsernameLocally('abc😄def');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationUsernameRegexp'});
|
||||
});
|
||||
|
||||
test('validate password', () => {
|
||||
let response;
|
||||
expect(typeof validate.validatePassword).toBe('function');
|
||||
response = validate.validatePassword('abcdef');
|
||||
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('');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationRequired'});
|
||||
response = validate.validatePassword('abcde');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordLength'});
|
||||
response = validate.validatePassword('password');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'registration.validationPasswordNotEquals'});
|
||||
});
|
||||
|
||||
test('validate password confirm', () => {
|
||||
let response;
|
||||
expect(typeof validate.validatePasswordConfirm).toBe('function');
|
||||
response = validate.validatePasswordConfirm('abcdef', 'abcdef');
|
||||
expect(response).toEqual({valid: true});
|
||||
response = validate.validatePasswordConfirm('abcdefghijklmnopqrst', 'abcdefghijklmnopqrst');
|
||||
expect(response).toEqual({valid: true});
|
||||
response = validate.validatePasswordConfirm('passwo', 'passwo');
|
||||
expect(response).toEqual({valid: true});
|
||||
response = validate.validatePasswordConfirm('', '');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'form.validationRequired'});
|
||||
response = validate.validatePasswordConfirm('abcdef', 'abcdefg');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'general.error'});
|
||||
response = validate.validatePasswordConfirm('abcdef', '123456');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'general.error'});
|
||||
response = validate.validatePasswordConfirm('', 'abcdefg');
|
||||
expect(response).toEqual({valid: false, errMsgId: 'general.error'});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue