From a7901c47734b55e5c749866963f86b307d430ab0 Mon Sep 17 00:00:00 2001 From: Oleksii-Ivan Stetsyk Date: Fri, 3 Oct 2025 18:07:53 +0300 Subject: [PATCH 1/3] add tests for checkPassword function --- src/checkPassword.test.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index 1e77e16..f2b2276 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ 'use strict'; describe(`Function 'checkPassword':`, () => { @@ -8,12 +9,34 @@ describe(`Function 'checkPassword':`, () => { }); it(`should return boolean`, () => { - + expect(typeof checkPassword('12345678')).toEqual('boolean'); }); it(`should return 'true' for the valid password with 8 characters`, () => { + expect(checkPassword('P@ssw0rd!')).toEqual(true); + }); + + it(`should return 'false' when the password is less than 8 characters`, () => { + expect(checkPassword('P@sw0rd')).toEqual(false); + }); + + it(`should return 'false' when the password is more than 16 characters`, () => { + expect(checkPassword('P@ssw0rd!P@ssw0rd!')).toEqual(false); + }); + it(`should return 'false' when password without big letter`, () => { + expect(checkPassword('p@ssw0rd!')).toEqual(false); }); - // write more tests here + it(`should return 'false' when password without small letter`, () => { + expect(checkPassword('P@SSW0RD!')).toEqual(false); + }); + + it(`should return 'false' when password without special character`, () => { + expect(checkPassword('Passw0rd')).toEqual(false); + }); + + it(`should return 'false' when password with spaces`, () => { + expect(checkPassword('P@s sw0rd!')).toEqual(false); + }); }); From fa8b224dc488a1f8baf7a6fa958eae32151cb256 Mon Sep 17 00:00:00 2001 From: Oleksii-Ivan Stetsyk Date: Fri, 3 Oct 2025 18:29:59 +0300 Subject: [PATCH 2/3] update tests --- src/checkPassword.test.js | 58 ++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index f2b2276..33153e3 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -12,31 +12,75 @@ describe(`Function 'checkPassword':`, () => { expect(typeof checkPassword('12345678')).toEqual('boolean'); }); - it(`should return 'true' for the valid password with 8 characters`, () => { + it(`should return true for valid password with exactly 8 characters`, () => { + expect(checkPassword('P@ssw0r1')).toEqual(true); + }); + + it(`should return true for valid password with 9 characters`, () => { expect(checkPassword('P@ssw0rd!')).toEqual(true); }); - it(`should return 'false' when the password is less than 8 characters`, () => { + it(`should return false when the password is less than 8 characters`, () => { expect(checkPassword('P@sw0rd')).toEqual(false); }); - it(`should return 'false' when the password is more than 16 characters`, () => { + it(`should return true for valid password with exactly 16 characters`, () => { + expect(checkPassword('P@ssw0rd!P@ssw0r')).toEqual(true); + }); + + it(`should return false when the password is more than 16 characters`, () => { expect(checkPassword('P@ssw0rd!P@ssw0rd!')).toEqual(false); }); - it(`should return 'false' when password without big letter`, () => { + it(`should return false when password has no uppercase letter`, () => { expect(checkPassword('p@ssw0rd!')).toEqual(false); }); - it(`should return 'false' when password without small letter`, () => { + it(`should return false when password has no lowercase letter (function requires both upper and lower)`, () => { expect(checkPassword('P@SSW0RD!')).toEqual(false); }); - it(`should return 'false' when password without special character`, () => { + it(`should return false when password has no digit`, () => { + expect(checkPassword('Password!')).toEqual(false); + }); + + it(`should return false when password has no special character`, () => { expect(checkPassword('Passw0rd')).toEqual(false); }); - it(`should return 'false' when password with spaces`, () => { + it(`should return false when password contains spaces`, () => { expect(checkPassword('P@s sw0rd!')).toEqual(false); }); + + it(`should return true for example password 'Password1!'`, () => { + expect(checkPassword('Password1!')).toEqual(true); + }); + + it(`should return false for example password 'qwerty'`, () => { + expect(checkPassword('qwerty')).toEqual(false); + }); + + it(`should return false for example password 'Str@ng'`, () => { + expect(checkPassword('Str@ng')).toEqual(false); + }); + + it(`should return true when password contains non-Latin letters like ä (function does not block them)`, () => { + expect(checkPassword('Pässw0rd!')).toEqual(true); + }); + + it(`should return false when password contains Cyrillic letters (Рassword1!)`, () => { + expect(checkPassword('Рassword1!')).toEqual(false); + }); + + it(`should return true for minimal valid password with all required categories (A1!aaaaa)`, () => { + expect(checkPassword('A1!aaaaa')).toEqual(true); + }); + + it(`should return true for password with multiple specials and digits (P@ssw0rd!!11)`, () => { + expect(checkPassword('P@ssw0rd!!11')).toEqual(true); + }); + + it(`should return false when password has uppercase + special but no digit (Passw@rd)`, () => { + expect(checkPassword('Passw@rd')).toEqual(false); + }); }); From a19692ed1a20750ed532c8e5afeb308eb3aad1ee Mon Sep 17 00:00:00 2001 From: Oleksii-Ivan Stetsyk Date: Sat, 4 Oct 2025 16:14:11 +0300 Subject: [PATCH 3/3] update tests again --- src/checkPassword.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index 33153e3..4c21e97 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -36,7 +36,7 @@ describe(`Function 'checkPassword':`, () => { expect(checkPassword('p@ssw0rd!')).toEqual(false); }); - it(`should return false when password has no lowercase letter (function requires both upper and lower)`, () => { + it(`should return false when password has no lowercase letter`, () => { expect(checkPassword('P@SSW0RD!')).toEqual(false); }); @@ -64,7 +64,7 @@ describe(`Function 'checkPassword':`, () => { expect(checkPassword('Str@ng')).toEqual(false); }); - it(`should return true when password contains non-Latin letters like ä (function does not block them)`, () => { + it(`should return true when password contains non-Latin (accented) letters like ä`, () => { expect(checkPassword('Pässw0rd!')).toEqual(true); });