Skip to content

Commit e378e8d

Browse files
committed
Isolate card tests; single previousPasswords test
1 parent 987378d commit e378e8d

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

‎sprint-3-stretch-exercises/card-validator.test.js‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ test("should accept another valid 16-digit card number", () => {
88
expect(isValidCardNumber("6666666666661666")).toEqual(true);
99
});
1010

11-
test("should reject a card number with non-digit characters", () => {
11+
test("should reject a card number shorter than 16 digits", () => {
12+
expect(isValidCardNumber("999999999999998")).toEqual(false);
13+
});
14+
15+
test("should reject a card number longer than 16 digits", () => {
16+
expect(isValidCardNumber("99999999999999998")).toEqual(false);
17+
});
18+
19+
test("should reject a card number with a non-digit character", () => {
1220
expect(isValidCardNumber("a92332119c011112")).toEqual(false);
1321
});
1422

@@ -21,13 +29,6 @@ test("should reject a card number whose digits sum to 16 or less", () => {
2129
});
2230

2331
test("should reject a card number with an odd final digit", () => {
24-
expect(isValidCardNumber("6666666666666661")).toEqual(false);
25-
});
26-
27-
test("should reject a card number shorter than 16 digits", () => {
28-
expect(isValidCardNumber("123456789012345")).toEqual(false);
29-
});
30-
31-
test("should reject a card number longer than 16 digits", () => {
32-
expect(isValidCardNumber("12345678901234567")).toEqual(false);
32+
// same style as a valid number, only last digit is odd
33+
expect(isValidCardNumber("9999777788880001")).toEqual(false);
3334
});

‎sprint-3-stretch-exercises/password-validator.test.js‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
/*
1+
/*
22
Password Validation
3-
43
Write a program that should check if a password is valid
54
and returns a boolean
6-
75
To be valid, a password must:
86
- Have at least 5 characters.
97
- Have at least one English uppercase letter (A-Z)
108
- Have at least one English lowercase letter (a-z)
119
- Have at least one number (0-9)
1210
- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
13-
- Must not be any previous password in the passwords array.
14-
11+
- Must not be any previous password in the passwords array.
1512
You must breakdown this problem in order to solve it. Find one test case first and get that working
1613
*/
1714
import { isValidPassword } from "./password-validator.js";
1815

19-
const previousPasswords = ["password", "12345", "qwerty"];
20-
2116
test("should accept a password that meets all rules", () => {
2217
expect(isValidPassword("Abc1!")).toEqual(true);
2318
});
@@ -43,10 +38,7 @@ test("should reject a password without a required symbol", () => {
4338
expect(isValidPassword("Abc12")).toEqual(false);
4439
});
4540

46-
test("should reject a previous password", () => {
47-
expect(isValidPassword("password", previousPasswords)).toEqual(false);
48-
});
49-
50-
test("should reject a password listed in the previousPasswords argument", () => {
41+
test("should reject a password listed in previousPasswords", () => {
42+
// meets all other rules; fails only because it is in the list
5143
expect(isValidPassword("Abc1!", ["Abc1!"])).toEqual(false);
5244
});

0 commit comments

Comments
 (0)