From ad5838314510ee2d4c4d5136a39963370b898123 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 9 Feb 2026 20:02:27 +0000 Subject: [PATCH 01/18] wrote password validation tests to check if the password includes numbers, english letters upper/lower case , non-alphanumeric symbols and it has a length of minimum 5 letters --- Sprint-3/4-stretch/password-validator.test.js | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6..fd9273f1d 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -10,17 +10,73 @@ To be valid, a password must: - Have at least one English lowercase letter (a-z) - Have at least one number (0-9) - Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&") -- Must not be any previous password in the passwords array. +- Must not be any previous password in the passwords array. You must breakdown this problem in order to solve it. Find one test case first and get that working */ const isValidPassword = require("./password-validator"); test("password has at least 5 characters", () => { // Arrange - const password = "12345"; + const password = "12345Dpw%"; // Act const result = isValidPassword(password); // Assert expect(result).toEqual(true); } -); \ No newline at end of file +); +test("password has at least 5 characters", () => { + const password = "1234"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); + + + +test("password has at least one English uppercase letter (A-Z)",()=>{ + const password ="12345Aaoe$" + const result=isValidPassword(password) + expect(result).toEqual(true) + +}); +test("password has at least one English uppercase letter (A-Z)", () => { + const password = "12345"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); + + +test("password has at least one English lower case letter (a-z)", () => { + const password = "S12345h#"; + const result = isValidPassword(password); + expect(result).toEqual(true); +}); +test("password has at least one English lower case letter (a-z)", () => { + const password = "S12345P"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); + +test("password has at least one number (0-9)", () => { + const password = "123456Aa%"; + const result = isValidPassword(password); + expect(result).toEqual(true); +}); +test("password has at least one number (0-9)", () => { + const password = "sgjjkdAa"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); + +test("password has at least one of the following non-alphanumeric symbols: (!, #, $, %, ., *, &)", () => { + const password = "123Spdfe!"; + const result = isValidPassword(password); + expect(result).toEqual(true); +}); +test("password has at least one of the following non-alphanumeric symbols: (!, #, $, %, ., *, &)", () => { + const password = "123Spdfe"; + const result = isValidPassword(password); + expect(result).toEqual(false); +}); + + +//don't know how to check if the password was used before, do i need to create a passwords array? \ No newline at end of file From 8bc912e31ad8d155789fb296ae0485e433949d42 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 9 Feb 2026 20:03:16 +0000 Subject: [PATCH 02/18] implemented password validation function --- Sprint-3/4-stretch/password-validator.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527db..e6ef7fc72 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,6 +1,9 @@ function passwordValidator(password) { - return password.length < 5 ? false : true + if (password.match(/[A-Z]/) && password.match(/[a-z]/) && + password.match(/[0-9]/) && password.match(/[!#$%.*&]/) && + password.length >= 5) return true; + + return false; } - -module.exports = passwordValidator; \ No newline at end of file +module.exports = passwordValidator; From 88e7a161ef31a7e9feead4dcf29940d5ac5ffc3b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 10 Feb 2026 09:08:19 +0000 Subject: [PATCH 03/18] Add card validator implementation and tests from sprint-3-implement-and-rewrite branch --- Sprint-3/4-stretch/card-validator.js | 4 ++++ Sprint-3/4-stretch/card-validator.test.js | 1 + 2 files changed, 5 insertions(+) create mode 100644 Sprint-3/4-stretch/card-validator.js create mode 100644 Sprint-3/4-stretch/card-validator.test.js diff --git a/Sprint-3/4-stretch/card-validator.js b/Sprint-3/4-stretch/card-validator.js new file mode 100644 index 000000000..347797e9e --- /dev/null +++ b/Sprint-3/4-stretch/card-validator.js @@ -0,0 +1,4 @@ +function validateNumber(){ + +} +module.exports=validateNumber \ No newline at end of file diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js new file mode 100644 index 000000000..37014d883 --- /dev/null +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -0,0 +1 @@ +const isValidNumber=require("./card-validator") \ No newline at end of file From 244ef86670a0be5e6bd955522102867f357ac67f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 10 Feb 2026 09:19:36 +0000 Subject: [PATCH 04/18] tested for card number length --- Sprint-3/4-stretch/card-validator.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js index 37014d883..cce57334e 100644 --- a/Sprint-3/4-stretch/card-validator.test.js +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -1 +1,13 @@ -const isValidNumber=require("./card-validator") \ No newline at end of file +const validateNumber = require("./card-validator") +const isValidNumber=require("./card-validator") + + +test("number should be 16 digits long",()=>{ + expect(validateNumber(1029384756820563)).toEqual(true) +}) +test("number should be 16 digits long", () => { + expect(validateNumber(10293847568205)).toEqual(false); +}); +test("number should be 16 digits long", () => { + expect(validateNumber(1029384756820512345)).toEqual(false); +}); \ No newline at end of file From 5658bec38ffb308f1afb65ff6cf3ad3f248fed31 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 10 Feb 2026 12:51:15 +0000 Subject: [PATCH 05/18] Refactor card validation tests for accuracy and completeness --- Sprint-3/4-stretch/card-validator.test.js | 43 +++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js index cce57334e..e2bc1497e 100644 --- a/Sprint-3/4-stretch/card-validator.test.js +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -3,11 +3,48 @@ const isValidNumber=require("./card-validator") test("number should be 16 digits long",()=>{ - expect(validateNumber(1029384756820563)).toEqual(true) + expect(validateNumber(1029384756820562)).toEqual(true) }) test("number should be 16 digits long", () => { - expect(validateNumber(10293847568205)).toEqual(false); + expect(validateNumber(10293847568202)).toEqual(false); }); test("number should be 16 digits long", () => { - expect(validateNumber(1029384756820512345)).toEqual(false); + expect(validateNumber(1029384756820512348)).toEqual(false); +}); + + + +test("all digits must be numbers",()=>{ + expect(validateNumber(1036294650361848)).toEqual(true) +}) +test("all digits must be numbers", () => { + expect(validateNumber("103629465036184a")).toEqual(false); +}); + + + +test("all the digits can not be the same",()=>{ + expect(validateNumber(3636363636363636)).toEqual(true) +}) +test("all the digits can not be the same", () => { + expect(validateNumber(3333333333333336)).toEqual(true); +}); +test("all the digits can not be the same", () => { + expect(validateNumber(2222222222222222)).toEqual(false); +}); + + +test("the final digit must be even",()=>{ + expect(validateNumber(1528056378293456)).toEqual(true) +}) +test("the final digit must be even", () => { + expect(validateNumber(1528056378293457)).toEqual(false); +}); + + +test("the sum of all digits must be greater than 16",()=>{ + expect(validateNumber(1903647295628592)).toEqual(true) +}) +test("the sum of all digits must be greater than 16", () => { + expect(validateNumber(1000100000000002)).toEqual(false); }); \ No newline at end of file From 04e0b3fc99eeeb0bebea0106a72969bc435e75dd Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 10 Feb 2026 12:52:01 +0000 Subject: [PATCH 06/18] Implement card number validation logic --- Sprint-3/4-stretch/card-validator.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.js b/Sprint-3/4-stretch/card-validator.js index 347797e9e..93afef265 100644 --- a/Sprint-3/4-stretch/card-validator.js +++ b/Sprint-3/4-stretch/card-validator.js @@ -1,4 +1,16 @@ -function validateNumber(){ +function validateNumber(number) { + let arrNumber = [...number.toString()]; + + + return arrNumber.length === 16 && + arrNumber.every((x) => x >= "0" && x <= "9") && + new Set(arrNumber).size > 1 && + arrNumber[arrNumber.length-1]%2===0 && + arrNumber.reduce((acc,cur)=>+acc+(+cur),0)>16 + ? true + : false; } -module.exports=validateNumber \ No newline at end of file +console.log(validateNumber(11111111111112)); + +module.exports = validateNumber; From 3c7e3ca0c6103e54aa9088ace6341d8d973ee1e3 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 10 Feb 2026 12:52:09 +0000 Subject: [PATCH 07/18] Refactor card number validation function for improved readability --- Sprint-3/4-stretch/card-validator.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.js b/Sprint-3/4-stretch/card-validator.js index 93afef265..674280b28 100644 --- a/Sprint-3/4-stretch/card-validator.js +++ b/Sprint-3/4-stretch/card-validator.js @@ -1,16 +1,13 @@ function validateNumber(number) { let arrNumber = [...number.toString()]; - - return arrNumber.length === 16 && arrNumber.every((x) => x >= "0" && x <= "9") && new Set(arrNumber).size > 1 && - arrNumber[arrNumber.length-1]%2===0 && - arrNumber.reduce((acc,cur)=>+acc+(+cur),0)>16 + arrNumber[arrNumber.length - 1] % 2 === 0 && + arrNumber.reduce((acc, cur) => +acc + +cur, 0) > 16 ? true : false; } -console.log(validateNumber(11111111111112)); module.exports = validateNumber; From e045c330f0a1b50d85e02cc5cc693e037b50099a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:55:40 +0000 Subject: [PATCH 08/18] changed variable declaration method --- Sprint-3/4-stretch/card-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/card-validator.js b/Sprint-3/4-stretch/card-validator.js index 674280b28..134867007 100644 --- a/Sprint-3/4-stretch/card-validator.js +++ b/Sprint-3/4-stretch/card-validator.js @@ -1,5 +1,5 @@ function validateNumber(number) { - let arrNumber = [...number.toString()]; + const arrNumber = [...number.toString()]; return arrNumber.length === 16 && arrNumber.every((x) => x >= "0" && x <= "9") && From 2fbf4b62096354dc2ba11812783afd5a1f32d59d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:59:01 +0000 Subject: [PATCH 09/18] updated tests descriptions for better understanding --- Sprint-3/4-stretch/card-validator.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js index e2bc1497e..7e399899f 100644 --- a/Sprint-3/4-stretch/card-validator.test.js +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -2,13 +2,13 @@ const validateNumber = require("./card-validator") const isValidNumber=require("./card-validator") -test("number should be 16 digits long",()=>{ +test("should return true if the number is 16 digits long",()=>{ expect(validateNumber(1029384756820562)).toEqual(true) }) -test("number should be 16 digits long", () => { +test("should return false if the number is less than 16 digits", () => { expect(validateNumber(10293847568202)).toEqual(false); }); -test("number should be 16 digits long", () => { +test("should return false if the number is more than 16 digits long", () => { expect(validateNumber(1029384756820512348)).toEqual(false); }); From 9462c1f7bcc14309debbef177a00a6f88d77f26c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:04:06 +0000 Subject: [PATCH 10/18] refactored for improved performance --- Sprint-3/4-stretch/password-validator.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index e6ef7fc72..a269037e9 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,8 +1,13 @@ function passwordValidator(password) { - if (password.match(/[A-Z]/) && password.match(/[a-z]/) && - password.match(/[0-9]/) && password.match(/[!#$%.*&]/) && - password.length >= 5) return true; - + if ( + /[A-Z]/.test(password) && + /[a-z]/.test(password) && + /[0-9]/.test(password) && + /[!#$%.*&]/.test(password) && + password.length >= 5 + ) + return true; + return false; } From f78f11b809ce62fddbc843f4f3a73605d332fd3c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:10:06 +0000 Subject: [PATCH 11/18] updated tests description --- Sprint-3/4-stretch/password-validator.test.js | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index fd9273f1d..0f562e637 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -16,67 +16,61 @@ You must breakdown this problem in order to solve it. Find one test case first a */ const isValidPassword = require("./password-validator"); test("password has at least 5 characters", () => { - // Arrange - const password = "12345Dpw%"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); -} -); -test("password has at least 5 characters", () => { + // Arrange + const password = "12345Dpw%"; + // Act + const result = isValidPassword(password); + // Assert + expect(result).toEqual(true); +}); +test("should reject password with less than 5 characters", () => { const password = "1234"; const result = isValidPassword(password); expect(result).toEqual(false); }); - - -test("password has at least one English uppercase letter (A-Z)",()=>{ - const password ="12345Aaoe$" - const result=isValidPassword(password) - expect(result).toEqual(true) - +test("should require at least one uppercase letter", () => { + const password = "12345Aaoe$"; + const result = isValidPassword(password); + expect(result).toEqual(true); }); -test("password has at least one English uppercase letter (A-Z)", () => { +test("should reject password without uppercase letter", () => { const password = "12345"; const result = isValidPassword(password); expect(result).toEqual(false); }); - -test("password has at least one English lower case letter (a-z)", () => { +test("should require at least one lowercase letter", () => { const password = "S12345h#"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("password has at least one English lower case letter (a-z)", () => { +test("should reject password without lowercase letter", () => { const password = "S12345P"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("password has at least one number (0-9)", () => { +test("should require at least one number", () => { const password = "123456Aa%"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("password has at least one number (0-9)", () => { +test("should reject password without number", () => { const password = "sgjjkdAa"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("password has at least one of the following non-alphanumeric symbols: (!, #, $, %, ., *, &)", () => { +test("should require at least one special symbol", () => { const password = "123Spdfe!"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("password has at least one of the following non-alphanumeric symbols: (!, #, $, %, ., *, &)", () => { +test("should reject password without special symbol", () => { const password = "123Spdfe"; const result = isValidPassword(password); expect(result).toEqual(false); }); - -//don't know how to check if the password was used before, do i need to create a passwords array? \ No newline at end of file +//don't know how to check if the password was used before, do i need to create a passwords array? From 74c180e150b89c406ba8eebf783171c9292a2b0b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:12:26 +0000 Subject: [PATCH 12/18] updated test for password length --- Sprint-3/4-stretch/password-validator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 0f562e637..8112db900 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -24,7 +24,7 @@ test("password has at least 5 characters", () => { expect(result).toEqual(true); }); test("should reject password with less than 5 characters", () => { - const password = "1234"; + const password = "1aS!"; const result = isValidPassword(password); expect(result).toEqual(false); }); From ea25ca55f66c80625b288c47bb4fe7bf3f8a4de8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:28:27 +0000 Subject: [PATCH 13/18] added test to reject previously used passwords --- Sprint-3/4-stretch/password-validator.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8112db900..9b94ff07a 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -73,4 +73,9 @@ test("should reject password without special symbol", () => { expect(result).toEqual(false); }); -//don't know how to check if the password was used before, do i need to create a passwords array? +test("should reject passwords which have been used before",()=>{ + const password = "123Spdfe!"; + const oldPasswords = ["hsqsgf", "123Spdfe!"]; + const result=isValidPassword(password,oldPasswords) + expect(result).toEqual(false) +}) From 55f0cccf09ced0ce6980fc79f92536b89735d634 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:28:38 +0000 Subject: [PATCH 14/18] enhanced passwordValidator to check against previously used passwords --- Sprint-3/4-stretch/password-validator.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index a269037e9..e43442c34 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,12 +1,14 @@ -function passwordValidator(password) { +function passwordValidator(password,oldPasswords=[]) { if ( /[A-Z]/.test(password) && /[a-z]/.test(password) && /[0-9]/.test(password) && /[!#$%.*&]/.test(password) && - password.length >= 5 + password.length >= 5 && + !oldPasswords.includes(password) ) return true; + return false; } From 2be0512e1bec9f0823f82334de77f7e6c815bbe1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 19 Feb 2026 10:58:07 +0000 Subject: [PATCH 15/18] updated tests descriptions --- Sprint-3/4-stretch/card-validator.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js index 7e399899f..f81f6ba06 100644 --- a/Sprint-3/4-stretch/card-validator.test.js +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -14,37 +14,37 @@ test("should return false if the number is more than 16 digits long", () => { -test("all digits must be numbers",()=>{ +test("should return true if all digits are numbers",()=>{ expect(validateNumber(1036294650361848)).toEqual(true) }) -test("all digits must be numbers", () => { +test("should return false if one or more of the digits aren't numbers", () => { expect(validateNumber("103629465036184a")).toEqual(false); }); -test("all the digits can not be the same",()=>{ +test("should return true if at least one of the digits isn't the same as the others",()=>{ expect(validateNumber(3636363636363636)).toEqual(true) }) -test("all the digits can not be the same", () => { +test("should return true if at least one of the digits isn't the same as the others", () => { expect(validateNumber(3333333333333336)).toEqual(true); }); -test("all the digits can not be the same", () => { +test("should return false if at least one of the digits isn't different from all the others", () => { expect(validateNumber(2222222222222222)).toEqual(false); }); -test("the final digit must be even",()=>{ +test("should return true if the final digit is even",()=>{ expect(validateNumber(1528056378293456)).toEqual(true) }) -test("the final digit must be even", () => { +test("should return false if the final digit isn't even", () => { expect(validateNumber(1528056378293457)).toEqual(false); }); -test("the sum of all digits must be greater than 16",()=>{ +test("should return true if the sum of all digits is greater than 16",()=>{ expect(validateNumber(1903647295628592)).toEqual(true) }) -test("the sum of all digits must be greater than 16", () => { +test("should return false if the sum of all the digits isn't greater than 16", () => { expect(validateNumber(1000100000000002)).toEqual(false); }); \ No newline at end of file From 3e9b0bab9685edc921a73a9872c4f95065f7e1e1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:46:28 +0000 Subject: [PATCH 16/18] updated tests descriptions --- Sprint-3/4-stretch/password-validator.test.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 9b94ff07a..1dc30230c 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -29,51 +29,51 @@ test("should reject password with less than 5 characters", () => { expect(result).toEqual(false); }); -test("should require at least one uppercase letter", () => { +test("should return true if the password has at least one uppercase english letter ", () => { const password = "12345Aaoe$"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("should reject password without uppercase letter", () => { +test("should reject password without an english uppercase letter", () => { const password = "12345"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("should require at least one lowercase letter", () => { +test("should return true if the password has at least one english lowercase letter", () => { const password = "S12345h#"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("should reject password without lowercase letter", () => { - const password = "S12345P"; +test("should return false if the password doesn't have at least one english lowercase letter", () => { + const password = "S12345P!"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("should require at least one number", () => { +test("should return true if the password hasn't got at least one number ", () => { const password = "123456Aa%"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("should reject password without number", () => { - const password = "sgjjkdAa"; +test("should return false if the password doesn't have at least one number", () => { + const password = "sgjjkdAa%"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("should require at least one special symbol", () => { +test("should return true if the password has at least one special symbol(!, #, $, %, ., *, &)", () => { const password = "123Spdfe!"; const result = isValidPassword(password); expect(result).toEqual(true); }); -test("should reject password without special symbol", () => { +test("should return false if the password doesn't include a special symbol(!, #, $, %, ., *, &)", () => { const password = "123Spdfe"; const result = isValidPassword(password); expect(result).toEqual(false); }); -test("should reject passwords which have been used before",()=>{ +test("should return false if the password has been used before",()=>{ const password = "123Spdfe!"; const oldPasswords = ["hsqsgf", "123Spdfe!"]; const result=isValidPassword(password,oldPasswords) From f266cbeb3645ee72aec77e5e300608c0700bd052 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:55:12 +0000 Subject: [PATCH 17/18] updated tests to check if the password was used before or not --- Sprint-3/4-stretch/password-validator.test.js | 111 +++++++++--------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 1dc30230c..4e622a711 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -15,67 +15,62 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ const isValidPassword = require("./password-validator"); -test("password has at least 5 characters", () => { - // Arrange - const password = "12345Dpw%"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); -}); -test("should reject password with less than 5 characters", () => { - const password = "1aS!"; - const result = isValidPassword(password); - expect(result).toEqual(false); -}); -test("should return true if the password has at least one uppercase english letter ", () => { - const password = "12345Aaoe$"; - const result = isValidPassword(password); - expect(result).toEqual(true); -}); -test("should reject password without an english uppercase letter", () => { - const password = "12345"; - const result = isValidPassword(password); - expect(result).toEqual(false); -}); +describe("Valid passwords", () => { + test("should return true for a valid password with all rules met", () => { + const password = "12345Dpw%"; + const result = isValidPassword(password); + expect(result).toEqual(true); + }); -test("should return true if the password has at least one english lowercase letter", () => { - const password = "S12345h#"; - const result = isValidPassword(password); - expect(result).toEqual(true); -}); -test("should return false if the password doesn't have at least one english lowercase letter", () => { - const password = "S12345P!"; - const result = isValidPassword(password); - expect(result).toEqual(false); -}); + test("should return true for another valid password", () => { + const password = "Abc123!"; + const result = isValidPassword(password); + expect(result).toEqual(true); + }); -test("should return true if the password hasn't got at least one number ", () => { - const password = "123456Aa%"; - const result = isValidPassword(password); - expect(result).toEqual(true); -}); -test("should return false if the password doesn't have at least one number", () => { - const password = "sgjjkdAa%"; - const result = isValidPassword(password); - expect(result).toEqual(false); + test("should return true for a valid password with different special symbol", () => { + const password = "MyPass#1"; + const result = isValidPassword(password); + expect(result).toEqual(true); + }); }); -test("should return true if the password has at least one special symbol(!, #, $, %, ., *, &)", () => { - const password = "123Spdfe!"; - const result = isValidPassword(password); - expect(result).toEqual(true); -}); -test("should return false if the password doesn't include a special symbol(!, #, $, %, ., *, &)", () => { - const password = "123Spdfe"; - const result = isValidPassword(password); - expect(result).toEqual(false); -}); +describe("Invalid passwords - each breaks one rule", () => { + test("should reject password with less than 5 characters", () => { + const password = "1aS!"; + const result = isValidPassword(password); + expect(result).toEqual(false); + }); + + test("should reject password without an uppercase letter", () => { + const password = "abcde1!"; + const result = isValidPassword(password); + expect(result).toEqual(false); + }); + + test("should reject password without a lowercase letter", () => { + const password = "ABCDE1!"; + const result = isValidPassword(password); + expect(result).toEqual(false); + }); -test("should return false if the password has been used before",()=>{ - const password = "123Spdfe!"; - const oldPasswords = ["hsqsgf", "123Spdfe!"]; - const result=isValidPassword(password,oldPasswords) - expect(result).toEqual(false) -}) + test("should reject password without a number", () => { + const password = "abcdeFg!"; + const result = isValidPassword(password); + expect(result).toEqual(false); + }); + + test("should reject password without a special symbol", () => { + const password = "abcde1FG"; + const result = isValidPassword(password); + expect(result).toEqual(false); + }); + + test("should reject password if it was used before", () => { + const password = "12345Dpw%"; + const oldPasswords = ["12345Dpw%"]; + const result = isValidPassword(password, oldPasswords); + expect(result).toEqual(false); + }); +}); From 6e5099c6040c465ac546a84eda9db8df17f18372 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 19 Feb 2026 17:28:17 +0000 Subject: [PATCH 18/18] updated tests descriptons --- Sprint-3/4-stretch/card-validator.test.js | 47 ++++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/Sprint-3/4-stretch/card-validator.test.js b/Sprint-3/4-stretch/card-validator.test.js index f81f6ba06..c79150032 100644 --- a/Sprint-3/4-stretch/card-validator.test.js +++ b/Sprint-3/4-stretch/card-validator.test.js @@ -1,10 +1,9 @@ -const validateNumber = require("./card-validator") -const isValidNumber=require("./card-validator") +const validateNumber = require("./card-validator"); +const isValidNumber = require("./card-validator"); - -test("should return true if the number is 16 digits long",()=>{ - expect(validateNumber(1029384756820562)).toEqual(true) -}) +test("returns true for a 16-digit number", () => { + expect(validateNumber(1029384756820562)).toEqual(true); +}); test("should return false if the number is less than 16 digits", () => { expect(validateNumber(10293847568202)).toEqual(false); }); @@ -12,39 +11,33 @@ test("should return false if the number is more than 16 digits long", () => { expect(validateNumber(1029384756820512348)).toEqual(false); }); - - -test("should return true if all digits are numbers",()=>{ - expect(validateNumber(1036294650361848)).toEqual(true) -}) +test("returns true when all characters are digits", () => { + expect(validateNumber(1036294650361848)).toEqual(true); +}); test("should return false if one or more of the digits aren't numbers", () => { expect(validateNumber("103629465036184a")).toEqual(false); }); - - -test("should return true if at least one of the digits isn't the same as the others",()=>{ - expect(validateNumber(3636363636363636)).toEqual(true) -}) -test("should return true if at least one of the digits isn't the same as the others", () => { +test("returns true when digits are not all identical", () => { + expect(validateNumber(3636363636363636)).toEqual(true); +}); +test("returns true when one digit differs", () => { expect(validateNumber(3333333333333336)).toEqual(true); }); -test("should return false if at least one of the digits isn't different from all the others", () => { +test("returns false when all digits are identical", () => { expect(validateNumber(2222222222222222)).toEqual(false); }); - -test("should return true if the final digit is even",()=>{ - expect(validateNumber(1528056378293456)).toEqual(true) -}) +test("should return true if the final digit is even", () => { + expect(validateNumber(1528056378293456)).toEqual(true); +}); test("should return false if the final digit isn't even", () => { expect(validateNumber(1528056378293457)).toEqual(false); }); - -test("should return true if the sum of all digits is greater than 16",()=>{ - expect(validateNumber(1903647295628592)).toEqual(true) -}) +test("should return true if the sum of all digits is greater than 16", () => { + expect(validateNumber(1903647295628592)).toEqual(true); +}); test("should return false if the sum of all the digits isn't greater than 16", () => { expect(validateNumber(1000100000000002)).toEqual(false); -}); \ No newline at end of file +});