Skip to content

Commit deadbdd

Browse files
committed
chore: add tests for @IsStrongPassword()
1 parent deada3f commit deadbdd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

__tests__/defaultConverters.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import _get from 'lodash.get'
55
import { validationMetadatasToSchemas } from '../src'
66

77
class Post {}
8+
89
class Comment {}
910

1011
enum PostType {
1112
Public,
1213
Private,
1314
}
15+
1416
enum Role {
1517
Anonymous = 'anonymous',
1618
User = 'user',
@@ -137,6 +139,17 @@ class User {
137139
@validator.ArrayMaxSize(10)
138140
arrayMaxSize: any[]
139141
@validator.ArrayUnique() arrayUnique: any[]
142+
143+
@validator.IsStrongPassword()
144+
password!: string
145+
@validator.IsStrongPassword({
146+
minLength: 16,
147+
minSymbols: 1,
148+
minLowercase: 2,
149+
minUppercase: 3,
150+
minNumbers: 4,
151+
})
152+
customPassword!: string
140153
}
141154

142155
const metadata = _get(
@@ -326,6 +339,16 @@ describe('defaultConverters', () => {
326339
arrayMinSize: { type: 'array', items: {}, minItems: 1 },
327340
arrayMaxSize: { type: 'array', items: {}, maxItems: 10 },
328341
arrayUnique: { type: 'array', items: {}, uniqueItems: true },
342+
password: {
343+
type: 'string',
344+
pattern:
345+
'^(?=.{8})(?=.*(?:[^a-z]*[a-z]){1})(?=.*(?:[^A-Z]*[A-Z]){1})(?=.*(?:[^0-9]*[0-9]){1})(?=.*(?:[^-#!$@£%^&*()_+|~=`{}\\[\\]:";\'<>?,.\\/ ]*[-#!$@£%^&*()_+|~=`{}\\[\\]:";\'<>?,.\\/ ]){1}).*$',
346+
},
347+
customPassword: {
348+
pattern:
349+
'^(?=.{16})(?=.*(?:[^a-z]*[a-z]){2})(?=.*(?:[^A-Z]*[A-Z]){3})(?=.*(?:[^0-9]*[0-9]){4})(?=.*(?:[^-#!$@£%^&*()_+|~=`{}\\[\\]:";\'<>?,.\\/ ]*[-#!$@£%^&*()_+|~=`{}\\[\\]:";\'<>?,.\\/ ]){1}).*$',
350+
type: 'string',
351+
},
329352
},
330353
required: expect.any(Array),
331354
type: 'object',

0 commit comments

Comments
 (0)