From a6dc573f3009161a848bcc7f98af3c19a17a176f Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Mon, 22 Jul 2019 14:54:25 -0400 Subject: [PATCH] rewrote validate legacy unit test from using tap, to using jest --- package.json | 2 +- test/unit-legacy/lib/validate.js | 66 -------------------------------- test/unit/lib/validate.test.js | 62 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 67 deletions(-) delete mode 100644 test/unit-legacy/lib/validate.js create mode 100644 test/unit/lib/validate.test.js diff --git a/package.json b/package.json index a9df0e1df..a040a0b03 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit-legacy/lib/validate.js b/test/unit-legacy/lib/validate.js deleted file mode 100644 index 3209a4307..000000000 --- a/test/unit-legacy/lib/validate.js +++ /dev/null @@ -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(); -}); diff --git a/test/unit/lib/validate.test.js b/test/unit/lib/validate.test.js new file mode 100644 index 000000000..31eca3e36 --- /dev/null +++ b/test/unit/lib/validate.test.js @@ -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'}); + }); +});