Skip to content

Commit bd6a8fb

Browse files
committed
Address review: test names, length cases, previousPasswords
1 parent aab021a commit bd6a8fb

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
import { isValidCardNumber } from "./card-validator.js";
22

3-
test("accepts a valid card number", () => {
3+
test("should accept a valid 16-digit card number", () => {
44
expect(isValidCardNumber("9999777788880000")).toEqual(true);
55
});
66

7-
test("accepts another valid card number", () => {
7+
test("should accept another valid 16-digit card number", () => {
88
expect(isValidCardNumber("6666666666661666")).toEqual(true);
99
});
1010

11-
test("rejects non-digit characters", () => {
11+
test("should reject a card number with non-digit characters", () => {
1212
expect(isValidCardNumber("a92332119c011112")).toEqual(false);
1313
});
1414

15-
test("rejects all same digits", () => {
15+
test("should reject a card number where all digits are the same", () => {
1616
expect(isValidCardNumber("4444444444444444")).toEqual(false);
1717
});
1818

19-
test("rejects sum of 16 or less", () => {
19+
test("should reject a card number whose digits sum to 16 or less", () => {
2020
expect(isValidCardNumber("1111111111111110")).toEqual(false);
2121
});
2222

23-
test("rejects odd final digit", () => {
23+
test("should reject a card number with an odd final digit", () => {
2424
expect(isValidCardNumber("6666666666666661")).toEqual(false);
2525
});
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);
33+
});

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
const previousPasswords = ["password", "12345", "qwerty"];
1+
const defaultPreviousPasswords = ["password", "12345", "qwerty"];
22

3-
export function isValidPassword(password) {
3+
export function isValidPassword(
4+
password,
5+
previousPasswords = defaultPreviousPasswords
6+
) {
47
if (password.length < 5) {
58
return false;
69
}
710

8-
const upperCase = /[A-Z]/.test(password);
9-
const lowerCase = /[a-z]/.test(password);
10-
const number = /[0-9]/.test(password);
11-
const symbol = /[!#$%.*&]/.test(password);
11+
const hasUpper = /[A-Z]/.test(password);
12+
const hasLower = /[a-z]/.test(password);
13+
const hasDigit = /[0-9]/.test(password);
14+
const hasSymbol = /[!#$%.*&]/.test(password);
1215

13-
if (!upperCase || !lowerCase || !number || !symbol) {
16+
if (!hasUpper || !hasLower || !hasDigit || !hasSymbol) {
1417
return false;
1518
}
1619

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,36 @@ You must breakdown this problem in order to solve it. Find one test case first a
1616
*/
1717
import { isValidPassword } from "./password-validator.js";
1818

19-
test("password has at least 5 characters and meets all rules", () => {
19+
test("password should have at least 5 characters and meets all rules", () => {
2020
const password = "Abc1!";
2121
const result = isValidPassword(password);
2222
expect(result).toEqual(true);
2323
});
2424

25-
test("rejects password shorter than 5 characters", () => {
25+
test("should rejects password shorter than 5 characters", () => {
2626
expect(isValidPassword("Ab1!")).toEqual(false);
2727
});
2828

29-
test("rejects password without uppercase", () => {
29+
test("should rejects password without uppercase", () => {
3030
expect(isValidPassword("abc1!")).toEqual(false);
3131
});
3232

33-
test("rejects password without lowercase", () => {
33+
test("should rejects password without lowercase", () => {
3434
expect(isValidPassword("ABC1!")).toEqual(false);
3535
});
3636

37-
test("rejects password without number", () => {
37+
test("should rejects password without number", () => {
3838
expect(isValidPassword("Abcde!")).toEqual(false);
3939
});
4040

41-
test("rejects password without symbol", () => {
41+
test("should rejects password without symbol", () => {
4242
expect(isValidPassword("Abc12")).toEqual(false);
4343
});
4444

45-
test("rejects previous password", () => {
45+
test("should rejects previous password", () => {
4646
expect(isValidPassword("password")).toEqual(false);
4747
});
48+
49+
test("should reject a password listed in the previousPasswords argument", () => {
50+
expect(isValidPassword("Abc1!", ["Abc1!"])).toEqual(false);
51+
});

0 commit comments

Comments
 (0)