1- /*
1+ /*
22Password Validation
3-
43Write a program that should check if a password is valid
54and returns a boolean
6-
75To be valid, a password must:
86- Have at least 5 characters.
97- Have at least one English uppercase letter (A-Z)
108- Have at least one English lowercase letter (a-z)
119- Have at least one number (0-9)
1210- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
13- - Must not be any previous password in the passwords array.
14-
11+ - Must not be any previous password in the passwords array.
1512You must breakdown this problem in order to solve it. Find one test case first and get that working
1613*/
1714import { isValidPassword } from "./password-validator.js" ;
1815
19- const previousPasswords = [ "password" , "12345" , "qwerty" ] ;
20-
2116test ( "should accept a password that meets all rules" , ( ) => {
2217 expect ( isValidPassword ( "Abc1!" ) ) . toEqual ( true ) ;
2318} ) ;
@@ -43,10 +38,7 @@ test("should reject a password without a required symbol", () => {
4338 expect ( isValidPassword ( "Abc12" ) ) . toEqual ( false ) ;
4439} ) ;
4540
46- test ( "should reject a previous password" , ( ) => {
47- expect ( isValidPassword ( "password" , previousPasswords ) ) . toEqual ( false ) ;
48- } ) ;
49-
50- test ( "should reject a password listed in the previousPasswords argument" , ( ) => {
41+ test ( "should reject a password listed in previousPasswords" , ( ) => {
42+ // meets all other rules; fails only because it is in the list
5143 expect ( isValidPassword ( "Abc1!" , [ "Abc1!" ] ) ) . toEqual ( false ) ;
5244} ) ;
0 commit comments