-
-
Notifications
You must be signed in to change notification settings - Fork 386
London|26-ITP-January|Alexandru Pocovnicu|Sprint 3 |stretch #951
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 14 commits
ad58383
8bc912e
88e7a16
244ef86
5658bec
04e0b3f
3c7e3ca
e045c33
2fbf4b6
9462c1f
f78f11b
74c180e
ea25ca5
55f0ccc
2be0512
3e9b0ba
f266cbe
6e5099c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| function validateNumber(number) { | ||
| const arrNumber = [...number.toString()]; | ||
|
|
||
| return arrNumber.length === 16 && | ||
| arrNumber.every((x) => x >= "0" && x <= "9") && | ||
| new Set(arrNumber).size > 1 && | ||
| arrNumber[arrNumber.length - 1] % 2 === 0 && | ||
| arrNumber.reduce((acc, cur) => +acc + +cur, 0) > 16 | ||
| ? true | ||
| : false; | ||
| } | ||
|
|
||
| module.exports = validateNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| const validateNumber = require("./card-validator") | ||
| const isValidNumber=require("./card-validator") | ||
|
|
||
|
|
||
| test("should return true if the number is 16 digits long",()=>{ | ||
| expect(validateNumber(1029384756820562)).toEqual(true) | ||
| }) | ||
| test("should return false if the number is less than 16 digits", () => { | ||
| expect(validateNumber(10293847568202)).toEqual(false); | ||
| }); | ||
| test("should return false if the number is more than 16 digits long", () => { | ||
| expect(validateNumber(1029384756820512348)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| test("all digits must be numbers",()=>{ | ||
| expect(validateNumber(1036294650361848)).toEqual(true) | ||
| }) | ||
| test("all digits must be numbers", () => { | ||
| expect(validateNumber("103629465036184a")).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| test("all the digits can not be the same",()=>{ | ||
| expect(validateNumber(3636363636363636)).toEqual(true) | ||
| }) | ||
| test("all the digits can not be the same", () => { | ||
| expect(validateNumber(3333333333333336)).toEqual(true); | ||
| }); | ||
| test("all the digits can not be the same", () => { | ||
| expect(validateNumber(2222222222222222)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| test("the final digit must be even",()=>{ | ||
| expect(validateNumber(1528056378293456)).toEqual(true) | ||
| }) | ||
| test("the final digit must be even", () => { | ||
| expect(validateNumber(1528056378293457)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| test("the sum of all digits must be greater than 16",()=>{ | ||
| expect(validateNumber(1903647295628592)).toEqual(true) | ||
| }) | ||
| test("the sum of all digits must be greater than 16", () => { | ||
| expect(validateNumber(1000100000000002)).toEqual(false); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| function passwordValidator(password) { | ||
| return password.length < 5 ? false : true | ||
| } | ||
| function passwordValidator(password,oldPasswords=[]) { | ||
| if ( | ||
| /[A-Z]/.test(password) && | ||
| /[a-z]/.test(password) && | ||
| /[0-9]/.test(password) && | ||
| /[!#$%.*&]/.test(password) && | ||
| password.length >= 5 && | ||
| !oldPasswords.includes(password) | ||
| ) | ||
| return true; | ||
|
|
||
|
|
||
| return false; | ||
| } | ||
|
|
||
| module.exports = passwordValidator; | ||
| module.exports = passwordValidator; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,17 +10,72 @@ To be valid, a password must: | |
| - 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. | ||
| - 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 = "12345"; | ||
| // Act | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(true); | ||
| } | ||
| ); | ||
| // Arrange | ||
| const password = "12345Dpw%"; | ||
| // Act | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(true); | ||
| }); | ||
| test("should reject password with less than 5 characters", () => { | ||
| const password = "1aS!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| test("should require at least one uppercase letter", () => { | ||
| const password = "12345Aaoe$"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| }); | ||
|
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. When this test fails, it only means the function fails to recognise a valid password -- which may or may not related to uppercase letters. I think you can consider grouping all valid cases into the same category. |
||
| test("should reject password without uppercase letter", () => { | ||
| const password = "12345"; | ||
|
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. This sample does not satisfy the criterium: it meets all other conditions except the one you're targeting. There are a few more test samples in this file that fit this description. Can you update them accordingly? |
||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| test("should require at least one lowercase letter", () => { | ||
| const password = "S12345h#"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| }); | ||
| test("should reject password without lowercase letter", () => { | ||
| const password = "S12345P"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| test("should require at least one number", () => { | ||
| const password = "123456Aa%"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| }); | ||
| test("should reject password without number", () => { | ||
| const password = "sgjjkdAa"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| test("should require at least one special symbol", () => { | ||
| const password = "123Spdfe!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| }); | ||
| test("should reject password without special symbol", () => { | ||
| const password = "123Spdfe"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| test("should reject passwords which have been used before",()=>{ | ||
| const password = "123Spdfe!"; | ||
| const oldPasswords = ["hsqsgf", "123Spdfe!"]; | ||
| const result=isValidPassword(password,oldPasswords) | ||
| expect(result).toEqual(false) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.