@@ -15,67 +15,62 @@ To be valid, a password must:
1515You must breakdown this problem in order to solve it. Find one test case first and get that working
1616*/
1717const isValidPassword = require ( "./password-validator" ) ;
18- test ( "password has at least 5 characters" , ( ) => {
19- // Arrange
20- const password = "12345Dpw%" ;
21- // Act
22- const result = isValidPassword ( password ) ;
23- // Assert
24- expect ( result ) . toEqual ( true ) ;
25- } ) ;
26- test ( "should reject password with less than 5 characters" , ( ) => {
27- const password = "1aS!" ;
28- const result = isValidPassword ( password ) ;
29- expect ( result ) . toEqual ( false ) ;
30- } ) ;
3118
32- test ( "should return true if the password has at least one uppercase english letter " , ( ) => {
33- const password = "12345Aaoe$" ;
34- const result = isValidPassword ( password ) ;
35- expect ( result ) . toEqual ( true ) ;
36- } ) ;
37- test ( "should reject password without an english uppercase letter" , ( ) => {
38- const password = "12345" ;
39- const result = isValidPassword ( password ) ;
40- expect ( result ) . toEqual ( false ) ;
41- } ) ;
19+ describe ( "Valid passwords" , ( ) => {
20+ test ( "should return true for a valid password with all rules met" , ( ) => {
21+ const password = "12345Dpw%" ;
22+ const result = isValidPassword ( password ) ;
23+ expect ( result ) . toEqual ( true ) ;
24+ } ) ;
4225
43- test ( "should return true if the password has at least one english lowercase letter" , ( ) => {
44- const password = "S12345h#" ;
45- const result = isValidPassword ( password ) ;
46- expect ( result ) . toEqual ( true ) ;
47- } ) ;
48- test ( "should return false if the password doesn't have at least one english lowercase letter" , ( ) => {
49- const password = "S12345P!" ;
50- const result = isValidPassword ( password ) ;
51- expect ( result ) . toEqual ( false ) ;
52- } ) ;
26+ test ( "should return true for another valid password" , ( ) => {
27+ const password = "Abc123!" ;
28+ const result = isValidPassword ( password ) ;
29+ expect ( result ) . toEqual ( true ) ;
30+ } ) ;
5331
54- test ( "should return true if the password hasn't got at least one number " , ( ) => {
55- const password = "123456Aa%" ;
56- const result = isValidPassword ( password ) ;
57- expect ( result ) . toEqual ( true ) ;
58- } ) ;
59- test ( "should return false if the password doesn't have at least one number" , ( ) => {
60- const password = "sgjjkdAa%" ;
61- const result = isValidPassword ( password ) ;
62- expect ( result ) . toEqual ( false ) ;
32+ test ( "should return true for a valid password with different special symbol" , ( ) => {
33+ const password = "MyPass#1" ;
34+ const result = isValidPassword ( password ) ;
35+ expect ( result ) . toEqual ( true ) ;
36+ } ) ;
6337} ) ;
6438
65- test ( "should return true if the password has at least one special symbol(!, #, $, %, ., *, &)" , ( ) => {
66- const password = "123Spdfe!" ;
67- const result = isValidPassword ( password ) ;
68- expect ( result ) . toEqual ( true ) ;
69- } ) ;
70- test ( "should return false if the password doesn't include a special symbol(!, #, $, %, ., *, &)" , ( ) => {
71- const password = "123Spdfe" ;
72- const result = isValidPassword ( password ) ;
73- expect ( result ) . toEqual ( false ) ;
74- } ) ;
39+ describe ( "Invalid passwords - each breaks one rule" , ( ) => {
40+ test ( "should reject password with less than 5 characters" , ( ) => {
41+ const password = "1aS!" ;
42+ const result = isValidPassword ( password ) ;
43+ expect ( result ) . toEqual ( false ) ;
44+ } ) ;
45+
46+ test ( "should reject password without an uppercase letter" , ( ) => {
47+ const password = "abcde1!" ;
48+ const result = isValidPassword ( password ) ;
49+ expect ( result ) . toEqual ( false ) ;
50+ } ) ;
51+
52+ test ( "should reject password without a lowercase letter" , ( ) => {
53+ const password = "ABCDE1!" ;
54+ const result = isValidPassword ( password ) ;
55+ expect ( result ) . toEqual ( false ) ;
56+ } ) ;
7557
76- test ( "should return false if the password has been used before" , ( ) => {
77- const password = "123Spdfe!" ;
78- const oldPasswords = [ "hsqsgf" , "123Spdfe!" ] ;
79- const result = isValidPassword ( password , oldPasswords )
80- expect ( result ) . toEqual ( false )
81- } )
58+ test ( "should reject password without a number" , ( ) => {
59+ const password = "abcdeFg!" ;
60+ const result = isValidPassword ( password ) ;
61+ expect ( result ) . toEqual ( false ) ;
62+ } ) ;
63+
64+ test ( "should reject password without a special symbol" , ( ) => {
65+ const password = "abcde1FG" ;
66+ const result = isValidPassword ( password ) ;
67+ expect ( result ) . toEqual ( false ) ;
68+ } ) ;
69+
70+ test ( "should reject password if it was used before" , ( ) => {
71+ const password = "12345Dpw%" ;
72+ const oldPasswords = [ "12345Dpw%" ] ;
73+ const result = isValidPassword ( password , oldPasswords ) ;
74+ expect ( result ) . toEqual ( false ) ;
75+ } ) ;
76+ } ) ;
0 commit comments