Skip to content

Manchester | 26-ITP-Sep | Salah Alsabhi | Sprint 3 | Stretch coursework - #1751

Open
salahalsabhi wants to merge 5 commits into
CodeYourFuture:mainfrom
salahalsabhi:coursework/sprint-3-stretch
Open

salahalsabhi wants to merge 5 commits into
CodeYourFuture:mainfrom
salahalsabhi:coursework/sprint-3-stretch

Conversation

@salahalsabhi

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1065

Changelist

  • Implemented full password validation rules with tests
  • Added credit card validator (isValidCardNumber) with tests

Questions

No questions.

@salahalsabhi salahalsabhi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 23, 2026

@cjyuan cjyuan left a comment

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.

Functions are correctly implemented. Good job.

Comment on lines +11 to +25
test("rejects non-digit characters", () => {
expect(isValidCardNumber("a92332119c011112")).toEqual(false);
});

test("rejects all same digits", () => {
expect(isValidCardNumber("4444444444444444")).toEqual(false);
});

test("rejects sum of 16 or less", () => {
expect(isValidCardNumber("1111111111111110")).toEqual(false);
});

test("rejects odd final digit", () => {
expect(isValidCardNumber("6666666666666661")).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.

  • Could also test card numbers that do not have exactly 16 digits.

  • Some of the test descriptions are not yet properly phrased. Could you rephrase them? A common pattern you could try is "should ____________ when _________________".

Comment on lines 1 to 3
const previousPasswords = ["password", "12345", "qwerty"];

export function isValidPassword(password) {

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.

For higher flexibility, we could design the function to accept previousPasswords as an optional second parameter (with a default value).

expect(isValidPassword("ABC1!")).toEqual(false);
});

test("rejects password without number", () => {

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.

Note: The term digit refers to a number in the range 0-9. A number may contain one or more digits.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 24, 2026
@salahalsabhi

Copy link
Copy Markdown
Author

Thanks for the feedback. I’ve updated the test names, added length checks for card numbers, and made previousPasswords an optional second parameter with a default.

@salahalsabhi salahalsabhi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026

@cjyuan cjyuan left a comment

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.

To test a function that could return false for multiple reasons, we should choose an input (argument) that satisfies all conditions except the one we're targeting.
This way, if the function returns false, we can confidently attribute the result to that specific condition.

To illustrate, consider this example:

  test("returns false when the password has fewer than 5 characters", () => {
    expect(isValidPassword("1234")).toBe(false);
  });

The test case "1234" is a poor choice because it violates multiple conditions, not just the minimum length requirement.
Even if the function incorrectly checks the password length, this test could still pass because the function returns false for one of the other reasons.

A better test case would be "Ab1!" because it satisfies all conditions except the minimum length requirement.

Could you review each test case to ensure it isolates the specific condition being tested? Make sure the input satisfies all the other conditions and violates only the target condition, so that if the test passes, you can be confident that the specific condition is being checked correctly.

Comment on lines +1 to +6
const defaultPreviousPasswords = ["password", "12345", "qwerty"];

export function isValidPassword(
password,
previousPasswords = defaultPreviousPasswords
) {

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.

Why set these as default previous passwords? If the function is used in an application, how would these default passwords affect the application? If they are for testing purpose, why not declare them in the test script.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026
@salahalsabhi

Copy link
Copy Markdown
Author

Updated tests so each invalid case only breaks one rule, and moved previous passwords out of the function default into the tests (default is now []).

@salahalsabhi salahalsabhi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026

@cjyuan cjyuan left a comment

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.

Some of the test cases in card-validator.test.js also violate more than one conditions. Could you fix them?

Comment on lines +46 to +48
test("should reject a previous password", () => {
expect(isValidPassword("password", previousPasswords)).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.

  • The function could also return false because "password" violates several other conditions.

  • And this test is very similar to the next test (lines 50-52). You could consider grouping both tests into one category.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026
@salahalsabhi

Copy link
Copy Markdown
Author

Isolated each card invalid case to a single rule, and reduced previous-password coverage to one test that only fails via the previousPasswords list.

@salahalsabhi salahalsabhi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026

@cjyuan cjyuan left a comment

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.

Changes look good.

Comment on lines -19 to -20
const previousPasswords = ["password", "12345", "qwerty"];

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.

Larger array of previous passwords was a good for testing. It was just that all the previous passwords you chose were invalid.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants