-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathcheckPassword.test.js
More file actions
104 lines (73 loc) · 2.89 KB
/
checkPassword.test.js
File metadata and controls
104 lines (73 loc) · 2.89 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
describe(`Function 'checkPassword':`, () => {
const checkPassword = require('./checkPassword');
const generatePassword = (amountOfCharacters, partWithRequiredCharacters) => {
const different = amountOfCharacters - partWithRequiredCharacters.length;
if (different <= 0) {
return partWithRequiredCharacters.slice(0, amountOfCharacters);
}
const randomLetterASCII = (howManyTimes) => {
let generatedLetters = '';
for (let i = 1; i <= howManyTimes; i++) {
const codeASCII = Math.floor(Math.random() * 26) + 97;
generatedLetters += String.fromCharCode(codeASCII);
}
return generatedLetters;
};
const randomPart = randomLetterASCII(amountOfCharacters
- partWithRequiredCharacters.length);
const result = partWithRequiredCharacters + randomPart;
return result;
};
it(`should be declared`, () => {
expect(checkPassword).toBeInstanceOf(Function);
});
it(`should return boolean`, () => {
const typeOfValue = typeof checkPassword('B34ji^sska');
expect(typeOfValue).toBeTruthy();
});
it(`should return 'true' for the valid password with 8 characters`, () => {
const value = generatePassword(8, '1^B');
expect(checkPassword(value)).toBe(true);
});
it(`should return 'true' for the valid password with 9 characters`, () => {
const value = generatePassword(9, '1^B');
expect(checkPassword(value)).toBe(true);
});
it(`should return 'true' for the valid password with 15 characters`, () => {
const value = generatePassword(15, '1^B');
expect(checkPassword(value)).toBe(true);
});
it(`should return 'true' for the valid password with 16 characters`, () => {
const value = generatePassword(16, '1^B');
expect(checkPassword(value)).toBe(true);
});
it(`should return 'false' for the valid password with 7 characters`, () => {
const value = generatePassword(7, '1^B');
expect(checkPassword(value)).toBe(false);
});
it(`should return 'false' for the valid password with 17 characters`, () => {
const value = generatePassword(17, '1^B');
expect(checkPassword(value)).toBe(false);
});
it(`should return 'false' if `
+ `password doesn't contain any digit`, () => {
const value = generatePassword(10, '^B');
expect(checkPassword(value)).toBe(false);
});
it(`should return 'false' if `
+ `password doesn't contain any special character`, () => {
const value = generatePassword(10, '1B');
expect(checkPassword(value)).toBe(false);
});
it(`should return 'false' if `
+ `password doesn't contain any upperCase`, () => {
const value = generatePassword(10, '1^');
expect(checkPassword(value)).toBe(false);
});
it(`should return 'false' if `
+ `password contains non-Latin alphabet`, () => {
const value = generatePassword(10, '1^BaŁ]\\');
expect(checkPassword(value)).toBe(false);
});
});