Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion src/validateRegisterForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});

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.


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`, () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a good start, but it only validates emails containing _ and -. The requirements specify a much wider range of allowed special characters (e.g., ! # $ % & ' * +). As requested in the previous review, please add a new, more comprehensive test case to ensure these other characters are also handled correctly.

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

Choose a reason for hiding this comment

The 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 _ and -. The requirements specify that emails can also contain other characters like ! # $ % & ' * + / = ? ^ { | } ~`. Could you add another test case that includes some of these other characters to make sure they are also handled correctly?


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.');
});

Choose a reason for hiding this comment

The 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.');
});
});