Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ad58383
wrote password validation tests to check if the password includes num…
alexandru-pocovnicu Feb 9, 2026
8bc912e
implemented password validation function
alexandru-pocovnicu Feb 9, 2026
88e7a16
Add card validator implementation and tests from sprint-3-implement-a…
alexandru-pocovnicu Feb 10, 2026
244ef86
tested for card number length
alexandru-pocovnicu Feb 10, 2026
5658bec
Refactor card validation tests for accuracy and completeness
alexandru-pocovnicu Feb 10, 2026
04e0b3f
Implement card number validation logic
alexandru-pocovnicu Feb 10, 2026
3c7e3ca
Refactor card number validation function for improved readability
alexandru-pocovnicu Feb 10, 2026
e045c33
changed variable declaration method
alexandru-pocovnicu Feb 18, 2026
2fbf4b6
updated tests descriptions for better understanding
alexandru-pocovnicu Feb 18, 2026
9462c1f
refactored for improved performance
alexandru-pocovnicu Feb 18, 2026
f78f11b
updated tests description
alexandru-pocovnicu Feb 18, 2026
74c180e
updated test for password length
alexandru-pocovnicu Feb 18, 2026
ea25ca5
added test to reject previously used passwords
alexandru-pocovnicu Feb 18, 2026
55f0ccc
enhanced passwordValidator to check against previously used passwords
alexandru-pocovnicu Feb 18, 2026
2be0512
updated tests descriptions
alexandru-pocovnicu Feb 19, 2026
3e9b0ba
updated tests descriptions
alexandru-pocovnicu Feb 19, 2026
f266cbe
updated tests to check if the password was used before or not
alexandru-pocovnicu Feb 19, 2026
6e5099c
updated tests descriptons
alexandru-pocovnicu Feb 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sprint-3/4-stretch/card-validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function validateNumber(number) {
let arrNumber = [...number.toString()];
Comment thread
cjyuan marked this conversation as resolved.
Outdated

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;
50 changes: 50 additions & 0 deletions Sprint-3/4-stretch/card-validator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const validateNumber = require("./card-validator")
const isValidNumber=require("./card-validator")


test("number should be 16 digits long",()=>{
expect(validateNumber(1029384756820562)).toEqual(true)
})
test("number should be 16 digits long", () => {
expect(validateNumber(10293847568202)).toEqual(false);
});
test("number should be 16 digits long", () => {
expect(validateNumber(1029384756820512348)).toEqual(false);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When one of these tests fails, these test descriptions do not quite tell the developer why their function failed.

Can you make the test descriptions on this file more informative?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three test descriptions are greatly improved! Why not also update the remaining test descriptions?



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);
});
9 changes: 6 additions & 3 deletions Sprint-3/4-stretch/password-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function passwordValidator(password) {
return password.length < 5 ? false : true
if (password.match(/[A-Z]/) && password.match(/[a-z]/) &&
Comment thread
cjyuan marked this conversation as resolved.
Outdated
password.match(/[0-9]/) && password.match(/[!#$%.*&]/) &&
password.length >= 5) return true;

return false;
}


module.exports = passwordValidator;
module.exports = passwordValidator;
62 changes: 59 additions & 3 deletions Sprint-3/4-stretch/password-validator.test.js
Comment thread
cjyuan marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
);
test("password has at least 5 characters", () => {
const password = "1234";
const result = isValidPassword(password);
expect(result).toEqual(false);
});
Comment thread
cjyuan marked this conversation as resolved.
Outdated



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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample does not satisfy the criterium: it meets all other conditions except the one you're targeting.

There are a few more test samples in this file that fit this description.

Can you update them accordingly?

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?
Loading