-
Notifications
You must be signed in to change notification settings - Fork 155
js_check_password #156
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
base: main
Are you sure you want to change the base?
js_check_password #156
Changes from 2 commits
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /* eslint-disable max-len */ | ||
| 'use strict'; | ||
|
|
||
| describe(`Function 'checkPassword':`, () => { | ||
|
|
@@ -8,12 +9,78 @@ describe(`Function 'checkPassword':`, () => { | |
| }); | ||
|
|
||
| it(`should return boolean`, () => { | ||
| expect(typeof checkPassword('12345678')).toEqual('boolean'); | ||
| }); | ||
|
|
||
| it(`should return true for valid password with exactly 8 characters`, () => { | ||
| expect(checkPassword('P@ssw0r1')).toEqual(true); | ||
| }); | ||
|
|
||
| it(`should return true for valid password with 9 characters`, () => { | ||
| expect(checkPassword('P@ssw0rd!')).toEqual(true); | ||
|
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. The test description says "valid password with 8 characters" but the assertion uses |
||
| }); | ||
|
|
||
| it(`should return false when the password is less than 8 characters`, () => { | ||
| expect(checkPassword('P@sw0rd')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return true for valid password with exactly 16 characters`, () => { | ||
| expect(checkPassword('P@ssw0rd!P@ssw0r')).toEqual(true); | ||
| }); | ||
|
|
||
| it(`should return false when the password is more than 16 characters`, () => { | ||
| expect(checkPassword('P@ssw0rd!P@ssw0rd!')).toEqual(false); | ||
|
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. Add a test that verifies the upper length boundary is accepted (exactly 16 characters). Current tests check >16 is invalid but not that 16 is valid. Add an assertion like: |
||
| }); | ||
|
|
||
| it(`should return false when password has no uppercase letter`, () => { | ||
| expect(checkPassword('p@ssw0rd!')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return false when password has no lowercase letter (function requires both upper and lower)`, () => { | ||
| expect(checkPassword('P@SSW0RD!')).toEqual(false); | ||
| }); | ||
|
||
|
|
||
| it(`should return false when password has no digit`, () => { | ||
| expect(checkPassword('Password!')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return 'true' for the valid password with 8 characters`, () => { | ||
| it(`should return false when password has no special character`, () => { | ||
| expect(checkPassword('Passw0rd')).toEqual(false); | ||
|
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 is no test for a password missing a digit. Add a test asserting |
||
| }); | ||
|
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. Add the requested edge-case checks: (1) a minimal valid password with exactly one of each required category (uppercase, digit, special) and total length >= 8, e.g. |
||
|
|
||
| it(`should return false when password contains spaces`, () => { | ||
| expect(checkPassword('P@s sw0rd!')).toEqual(false); | ||
|
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. Add tests that verify non-Latin letters are rejected. The requirements state only Latin letters A–Z/a–z are allowed. For example: |
||
| }); | ||
|
|
||
| // write more tests here | ||
| it(`should return true for example password 'Password1!'`, () => { | ||
| expect(checkPassword('Password1!')).toEqual(true); | ||
| }); | ||
|
|
||
| it(`should return false for example password 'qwerty'`, () => { | ||
| expect(checkPassword('qwerty')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return false for example password 'Str@ng'`, () => { | ||
| expect(checkPassword('Str@ng')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return true when password contains non-Latin letters like ä (function does not block them)`, () => { | ||
| expect(checkPassword('Pässw0rd!')).toEqual(true); | ||
| }); | ||
|
||
|
|
||
| it(`should return false when password contains Cyrillic letters (Рassword1!)`, () => { | ||
| expect(checkPassword('Рassword1!')).toEqual(false); | ||
| }); | ||
|
|
||
| it(`should return true for minimal valid password with all required categories (A1!aaaaa)`, () => { | ||
| expect(checkPassword('A1!aaaaa')).toEqual(true); | ||
| }); | ||
|
|
||
| it(`should return true for password with multiple specials and digits (P@ssw0rd!!11)`, () => { | ||
| expect(checkPassword('P@ssw0rd!!11')).toEqual(true); | ||
| }); | ||
|
|
||
| it(`should return false when password has uppercase + special but no digit (Passw@rd)`, () => { | ||
| expect(checkPassword('Passw@rd')).toEqual(false); | ||
| }); | ||
| }); | ||
|
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. Missing test: ensure digits/specials don't substitute for letters. The spec requires letters (and at least one uppercase). There is no test ensuring a password that contains only digits and special characters (no letters) is invalid. Add a negative test to confirm that the presence of digits/specials does not substitute for required letters. Add it near the other negative tests (for example, before the final cases). Example: it('should return false when password has no letters (only digits/specials)', () => {
expect(checkPassword('1!2345678')).toEqual(false);
});This test enforces that letters (A–Z/a–z) must be present and that digits/specials alone are insufficient. |
||
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.
Add explicit tests for the examples from the task description so they are covered by the suite:
checkPassword('Password1!') === true,checkPassword('qwerty') === false, andcheckPassword('Str@ng') === false. Place these near other simple example tests so the specification examples are validated.