-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathpassword-validator.test.js
More file actions
60 lines (53 loc) · 1.84 KB
/
password-validator.test.js
File metadata and controls
60 lines (53 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Password Validation
Write a program that should check if a password is valid
and returns a boolean
To be valid, a password must:
- Have at least 5 characters.
- Have at least one English uppercase letter (A-Z)
- 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.
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 = "As?123";
// Act
const result = isValidPassword(password);
// Assert
expect(result).toEqual(true);
}
);
test("password has at least 5 characters", () => {
const password = "As?3";
const result = isValidPassword(password);
expect(result).toEqual(false);
});
test("password has at least one English uppercase letter (A-Z)", () => {
const password = "As?123";
const result = isValidPassword(password);
expect(result).toEqual(true);
});
test("password has at least one English uppercase letter (A-Z)", () => {
const password = "s?123";
const result = isValidPassword(password);
expect(result).toEqual(false);
});
test("password has at least one English lowercase letter (a-z)", () => {
const password = "'aK763";
const result = isValidPassword(password);
expect(result).toEqual(true);
});
test("password has at least one English lowercase letter (a-z)", () => {
const password = "QWE<25365";
const result = isValidPassword(password);
expect(result).toEqual(false);
});
test("password has at least one number 0-9", () => {
const password = "QWE<25365";
const result = isValidPassword(password);
expect(result).toEqual(true);
});