Skip to content

Commit 987378d

Browse files
committed
Isolate password test cases; use empty default for previousPasswords
1 parent bd6a8fb commit 987378d

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
const defaultPreviousPasswords = ["password", "12345", "qwerty"];
2-
3-
export function isValidPassword(
4-
password,
5-
previousPasswords = defaultPreviousPasswords
6-
) {
1+
export function isValidPassword(password, previousPasswords = []) {
72
if (password.length < 5) {
83
return false;
94
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,35 @@ 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 should have at least 5 characters and meets all rules", () => {
20-
const password = "Abc1!";
21-
const result = isValidPassword(password);
22-
expect(result).toEqual(true);
19+
const previousPasswords = ["password", "12345", "qwerty"];
20+
21+
test("should accept a password that meets all rules", () => {
22+
expect(isValidPassword("Abc1!")).toEqual(true);
2323
});
2424

25-
test("should rejects password shorter than 5 characters", () => {
25+
test("should reject a password shorter than 5 characters", () => {
26+
// only length fails: has upper, lower, digit, symbol
2627
expect(isValidPassword("Ab1!")).toEqual(false);
2728
});
2829

29-
test("should rejects password without uppercase", () => {
30+
test("should reject a password without an uppercase letter", () => {
3031
expect(isValidPassword("abc1!")).toEqual(false);
3132
});
3233

33-
test("should rejects password without lowercase", () => {
34+
test("should reject a password without a lowercase letter", () => {
3435
expect(isValidPassword("ABC1!")).toEqual(false);
3536
});
3637

37-
test("should rejects password without number", () => {
38+
test("should reject a password without a digit", () => {
3839
expect(isValidPassword("Abcde!")).toEqual(false);
3940
});
4041

41-
test("should rejects password without symbol", () => {
42+
test("should reject a password without a required symbol", () => {
4243
expect(isValidPassword("Abc12")).toEqual(false);
4344
});
4445

45-
test("should rejects previous password", () => {
46-
expect(isValidPassword("password")).toEqual(false);
46+
test("should reject a previous password", () => {
47+
expect(isValidPassword("password", previousPasswords)).toEqual(false);
4748
});
4849

4950
test("should reject a password listed in the previousPasswords argument", () => {

0 commit comments

Comments
 (0)