From 112207f6d6c2da57e8bd14e6ca6553fcb7747a06 Mon Sep 17 00:00:00 2001 From: Tarun Batra Date: Thu, 12 Sep 2019 00:21:22 +0530 Subject: [PATCH] Added detailed tests for --- tests/index.test.js | 128 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/tests/index.test.js b/tests/index.test.js index 0987eb5..9c7a1ff 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -255,6 +255,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().digits(); + }); + + it('should return false if digit is present', function () { + valid = schema.validate('1234567890'); + expect(valid).to.be.false; + }); + + it('should return true if digit is not present', function () { + valid = schema.validate('qwerty'); + expect(valid).to.be.true; + }); + }); }); describe('letters', function () { @@ -284,6 +302,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().letters(); + }); + + it('should return false if letter is present', function () { + valid = schema.validate('letters'); + expect(valid).to.be.false; + }); + + it('should return true if letter is not present', function () { + valid = schema.validate('1234'); + expect(valid).to.be.true; + }); + }); }); describe('lowercase', function () { @@ -313,6 +349,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().lowercase(); + }); + + it('should return false if lowercase is present', function () { + valid = schema.validate('lettersCAPS'); + expect(valid).to.be.false; + }); + + it('should return true if lowercase is not present', function () { + valid = schema.validate('1234CAPS'); + expect(valid).to.be.true; + }); + }); }); describe('uppercase', function () { @@ -342,6 +396,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().uppercase(); + }); + + it('should return false if uppercase is present', function () { + valid = schema.validate('lettersCAPS'); + expect(valid).to.be.false; + }); + + it('should return true if uppercase is not present', function () { + valid = schema.validate('letters'); + expect(valid).to.be.true; + }); + }); }); describe('symbols', function () { @@ -384,6 +456,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().symbols(); + }); + + it('should return false if symbol is present', function () { + valid = schema.validate('letters&CAPS'); + expect(valid).to.be.false; + }); + + it('should return true if symbol is not present', function () { + valid = schema.validate('1234lower'); + expect(valid).to.be.true; + }); + }); }); describe('space', function () { @@ -413,6 +503,24 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().spaces(); + }); + + it('should return false if space is present', function () { + valid = schema.validate('letters &CAPS'); + expect(valid).to.be.false; + }); + + it('should return true if space is not present', function () { + valid = schema.validate('letters&CAPS'); + expect(valid).to.be.true; + }); + }); }); describe('oneOf', function () { @@ -434,7 +542,7 @@ describe('password-validator', function () { beforeEach(function () { schema = new Schema(); - schema.oneOf('this'); + schema.oneOf([ 'this' ]); valid = schema.validate('this'); }); @@ -442,5 +550,23 @@ describe('password-validator', function () { expect(valid).to.be.true; }); }); + + describe('used with not', function () { + + beforeEach(function () { + schema = new Schema(); + schema.not().oneOf([ 'this' ]); + }); + + it('should return false if said password is used', function () { + valid = schema.validate('this'); + expect(valid).to.be.false; + }); + + it('should return true if said password is not used', function () { + valid = schema.validate('that'); + expect(valid).to.be.true; + }); + }); }); });