@@ -184,6 +184,9 @@ import {
184184 isPostalCode ,
185185 IsSemVer ,
186186 isSemVer ,
187+ IsStrongPassword ,
188+ isStrongPassword ,
189+ IsStrongPasswordOptions ,
187190 IsTimeZone ,
188191} from '../../src/decorator/decorators' ;
189192import { Validator } from '../../src/validation/Validator' ;
@@ -4577,3 +4580,83 @@ describe('isInstance', () => {
45774580 return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
45784581 } ) ;
45794582} ) ;
4583+
4584+ describe ( 'IsStrongPassword' , ( ) => {
4585+ class MyClass {
4586+ @IsStrongPassword ( )
4587+ someProperty : string ;
4588+ }
4589+
4590+ const validValues = [ 'Abcdef1!' ] ;
4591+ const invalidValues = [ null , undefined , 'Abcde1!' , 'abcdef1!' , 'ABCDEF1!' , 'Abcdefg!' , 'Abcdefg1' ] ;
4592+
4593+ it ( 'should not fail if validator.validate said that its valid' , ( ) => {
4594+ return checkValidValues ( new MyClass ( ) , validValues ) ;
4595+ } ) ;
4596+
4597+ it ( 'should fail if validator.validate said that its invalid' , ( ) => {
4598+ return checkInvalidValues ( new MyClass ( ) , invalidValues ) ;
4599+ } ) ;
4600+
4601+ it ( 'should not fail if method in validator said that its valid' , ( ) => {
4602+ validValues . forEach ( value => expect ( isStrongPassword ( value ) ) . toBeTruthy ( ) ) ;
4603+ } ) ;
4604+
4605+ it ( 'should fail if method in validator said that its invalid' , ( ) => {
4606+ invalidValues . forEach ( value => expect ( isStrongPassword ( value ) ) . toBeFalsy ( ) ) ;
4607+ } ) ;
4608+
4609+ it ( 'should return error object with proper data' , ( ) => {
4610+ const validationType = 'isStrongPassword' ;
4611+ const message = 'someProperty is not strong enough' ;
4612+ return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
4613+ } ) ;
4614+ } ) ;
4615+
4616+ describe ( 'IsStrongPassword with options' , ( ) => {
4617+ const options : IsStrongPasswordOptions = {
4618+ minLength : 12 ,
4619+ minLowercase : 2 ,
4620+ minUppercase : 2 ,
4621+ minNumbers : 2 ,
4622+ minSymbols : 2 ,
4623+ } ;
4624+
4625+ class MyClass {
4626+ @IsStrongPassword ( options )
4627+ someProperty : string ;
4628+ }
4629+
4630+ const validValues = [ 'ABcdefgh12!#' ] ;
4631+ const invalidValues = [
4632+ null ,
4633+ undefined ,
4634+ 'ABcdefg12!#' ,
4635+ 'Abcdefgh12!#' ,
4636+ 'ABcDEFGH12!#' ,
4637+ 'ABcdefghi1!#' ,
4638+ 'ABcdefghi12!' ,
4639+ ] ;
4640+
4641+ it ( 'should not fail if validator.validate said that its valid' , ( ) => {
4642+ return checkValidValues ( new MyClass ( ) , validValues ) ;
4643+ } ) ;
4644+
4645+ it ( 'should fail if validator.validate said that its invalid' , ( ) => {
4646+ return checkInvalidValues ( new MyClass ( ) , invalidValues ) ;
4647+ } ) ;
4648+
4649+ it ( 'should not fail if method in validator said that its valid' , ( ) => {
4650+ validValues . forEach ( value => expect ( isStrongPassword ( value , options ) ) . toBeTruthy ( ) ) ;
4651+ } ) ;
4652+
4653+ it ( 'should fail if method in validator said that its invalid' , ( ) => {
4654+ invalidValues . forEach ( value => expect ( isStrongPassword ( value , options ) ) . toBeFalsy ( ) ) ;
4655+ } ) ;
4656+
4657+ it ( 'should return error object with proper data' , ( ) => {
4658+ const validationType = 'isStrongPassword' ;
4659+ const message = 'someProperty is not strong enough' ;
4660+ return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
4661+ } ) ;
4662+ } ) ;
0 commit comments