-
-
Notifications
You must be signed in to change notification settings - Fork 337
Glasgow | 25-ITP-Sep | Alaa Tagi| Sprint 3 | coursework/sprint 3 stretch #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
24f294c
6b8d975
8499ca3
14ab0f6
e2191a4
7f09ec5
46024de
444fbb9
df9863b
9354edf
d50290e
9abe2c9
e615f8a
08603d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,30 @@ | ||
| function passwordValidator(password) { | ||
| return password.length < 5 ? false : true | ||
| } | ||
| const passwords = ["Abcde1!", "Hello#2"]; | ||
| function passwordValidator(password) { | ||
| if (password.length < 5) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!/[A-Z]/.test(password)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!/[a-z]/.test(password)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!/[0-9]/.test(password)) { | ||
| return false; | ||
| } | ||
| if (!/[!#$%&? "]/.test(password)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (passwords.includes(password)) { | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
| return true; | ||
| } | ||
|
|
||
| module.exports = passwordValidator; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,59 @@ test("password has at least 5 characters", () => { | |
| // Act | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
|
|
||
| // passsword has at least one uppercase letter | ||
| test("password has at least one uppercase letter", () => { | ||
|
|
||
| const password = "abcd!1"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
|
|
||
| // password has at least one lowercase letter | ||
| test("password has at least one lowercase letter", () => { | ||
|
|
||
| const password = "ABCD!1"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
|
|
||
| // password has at least one number | ||
| test("password has at least one number", () => { | ||
|
|
||
| const password = "Abcd!@"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
|
|
||
| // password has at least one symbol: | ||
| test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { | ||
|
|
||
| const password = "abcd!1"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
|
Comment on lines
56
to
61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two possible reasons the test could pass;
Comment on lines
56
to
61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something about this test is still not quite right. Can you fix the issue? |
||
| ); | ||
|
|
||
| // password must not be any previous password in the passwords array. | ||
| test("password must not be any previous password in the passwords array.", () => { | ||
|
|
||
| const password = "abcd!1"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
| // password is valid when all requirements are met | ||
| test ("password is valid when it meets all requirements",() =>{ | ||
|
|
||
| const password = "Abcd!2"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| } | ||
| ); | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function can return
falsefor multiple reasons.To test a specific reason, choose an input that satisfies all other conditions except the one you're targeting. This way, if the function returns
false, you can confidently attribute it to that specific condition.For example, the function might return
falsefor "1234a" not only because it lacks an uppercase letter, but also because it lacks a special symbol.As a result, we can't be certain that the function correctly handles the case of passwords without uppercase letters, since multiple conditions are being violated simultaneously.