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 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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;