-
Notifications
You must be signed in to change notification settings - Fork 149
Added tests #131
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?
Added tests #131
Changes from all 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 |
|---|---|---|
|
|
@@ -26,5 +26,117 @@ describe(`Function 'validateRegisterForm':`, () => { | |
| expect(invalidPassword.message).toBe('Password is invalid.'); | ||
| }); | ||
|
|
||
| // write more tests here | ||
| it(`should return error for valid email | ||
| and password without special character`, () => { | ||
| const invalidPassword = validateRegisterForm('test@mail.com', 'Pssword12'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Password is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error for valid email | ||
| and password without uppercase letter`, () => { | ||
| const invalidPassword = validateRegisterForm('test@mail.com', 'p@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Password is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error for at least 8 characters inclusive`, () => { | ||
| const invalidPassword = validateRegisterForm('test@mail.com', 'P@wod1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Password is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error for max 16 characters inclusive`, () => { | ||
| const invalidPassword = validateRegisterForm('test@mail.com', | ||
| 'P@ssword1!p234578'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Password is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error for not English letters`, () => { | ||
| const invalidPassword = validateRegisterForm('Тест@mail.com', 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error when @ is not added`, () => { | ||
| const invalidPassword = validateRegisterForm('testmail.com', 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should pass if we have digits`, () => { | ||
| const isValid = validateRegisterForm('test123@mail.com', 'P@ssword1!'); | ||
|
|
||
| expect(isValid.code).toBe(200); | ||
| expect(isValid.message).toBe('Email and password are valid.'); | ||
| }); | ||
|
|
||
| it(`should pass if we have some characters`, () => { | ||
|
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 test is a good start, but it only validates emails containing |
||
| const isValid = validateRegisterForm('test_nik-ch@mail.com', 'P@ssword1!'); | ||
|
|
||
| expect(isValid.code).toBe(200); | ||
| expect(isValid.message).toBe('Email and password are valid.'); | ||
| }); | ||
|
Comment on lines
+81
to
+86
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. It's good that you've added a test for special characters in the email. However, this only covers |
||
|
|
||
| it(`should pass if password containing Cyrillic letters`, () => { | ||
| const invalidPassword = validateRegisterForm('test@mail.com', | ||
| 'Passwпароль1@'); | ||
|
|
||
| expect(invalidPassword.code).toBe(200); | ||
| expect(invalidPassword.message).toBe('Email and password are valid.'); | ||
| }); | ||
|
|
||
| it(`should return error when double dots added`, () => { | ||
| const invalidPassword = validateRegisterForm('test..myk@mail.com', | ||
| 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error when email be start with .`, () => { | ||
| const invalidPassword = validateRegisterForm('.test@mail.com', | ||
| 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
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 requirements mention that an email cannot end with a dot. A test case for this scenario is missing. Please add one to ensure full coverage of the requirements. |
||
|
|
||
| it(`should return error when email ends with .`, () => { | ||
| const invalidPassword = validateRegisterForm('test/@mail.com.', | ||
| 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error when top Level domain can not start with dot`, () => { | ||
| const invalidPassword = validateRegisterForm('test@.mail.com', | ||
| 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error when don't have domain Level`, () => { | ||
| const invalidPassword = validateRegisterForm('test@com', | ||
| 'P@ssword1!'); | ||
|
|
||
| expect(invalidPassword.code).toBe(422); | ||
| expect(invalidPassword.message).toBe('Email is invalid.'); | ||
| }); | ||
|
|
||
| it(`should return error for invalid email and password`, () => { | ||
| const invalidPassword = validateRegisterForm('test@com', 'ssword1'); | ||
|
|
||
| expect(invalidPassword.code).toBe(500); | ||
| expect(invalidPassword.message).toBe('Password and email are invalid.'); | ||
| }); | ||
| }); | ||
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 requirements state that valid passwords can contain Cyrillic letters (
Aa-Яя). It's important to add a test case to ensure this functionality is covered, for example, a test with a valid Cyrillic password.