Skip to content
Open
Changes from 1 commit
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
82 changes: 78 additions & 4 deletions src/validateRegisterForm.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
'use strict';

describe(`Function 'validateRegisterForm':`, () => {
Expand All @@ -8,8 +9,9 @@ describe(`Function 'validateRegisterForm':`, () => {
});

it(`should return object`, () => {
expect(typeof validateRegisterForm('test@mail.com', 'P@ssword1!'))
.toBe('object');
expect(typeof validateRegisterForm('test@mail.com', 'P@ssword1!')).toBe(
'object'
);
});

it(`should return success message for the valid input`, () => {
Expand All @@ -19,12 +21,84 @@ describe(`Function 'validateRegisterForm':`, () => {
expect(isValid.message).toBe('Email and password are valid.');
});

it(`should return error for valid email and password without number`, () => {
it(`should return error for valid email
and password without number`, () => {
const invalidPassword = validateRegisterForm('test@mail.com', 'P@ssword');

expect(invalidPassword.code).toBe(422);
expect(invalidPassword.message).toBe('Password is invalid.');
});

// write more tests here
it(`should return error for valid email and password.length < 8`, () => {
const invalidPassword = validateRegisterForm('test@mail.com', 'P@ssw1');

expect(invalidPassword.code).toBe(422);
expect(invalidPassword.message).toBe('Password is invalid.');
});

it(`should return error for valid email and password.length > 16`, () => {
const invalidPassword = validateRegisterForm(
'test@mail.com',
'P@sswordPas2Word122'
);

expect(invalidPassword.code).toBe(422);
expect(invalidPassword.message).toBe('Password is invalid.');
});

it(`should return error for valid email
and password without big 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 valid email
and password without small letter`, () => {
const invalidPassword = validateRegisterForm('test@mail.com', 'P@SSWORD1');

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.

This test appears to be based on a misunderstanding of the password requirements. The password 'P@SSWORD1' is valid because it meets all specified criteria (length, contains an uppercase letter, a digit, and a special character). The requirements do not state that a lowercase letter is mandatory. This test should likely be removed or changed to reflect a successful validation.


it(`should return error for valid email
and password without special character`, () => {
const invalidPassword = validateRegisterForm('test@mail.com', 'PPssword1');

expect(invalidPassword.code).toBe(422);
expect(invalidPassword.message).toBe('Password is invalid.');
});

it(`should return error for valid email and password with spaces`, () => {
const invalidPassword = validateRegisterForm('test@mail.com', 'P@ss word1');

expect(invalidPassword.code).toBe(422);
expect(invalidPassword.message).toBe('Password is invalid.');
});

it('should return error when email format is invalid', () => {
const invalidEmail = validateRegisterForm('testmail.com', 'P@ssword1!');

expect(invalidEmail.code).toBe(422);
expect(invalidEmail.message).toBe('Email is invalid.');
});

it('should return error when both email and password are invalid', () => {
const invalidEmailAndPassword = validateRegisterForm('test@com', 'ssword1');

expect(invalidEmailAndPassword.code).toEqual(500);

expect(invalidEmailAndPassword.message).toEqual(
'Password and email are invalid.'
);
});

it(`should return success for complex valid
password with multiple specials and digits`, () => {
const result = validateRegisterForm('some@mail.com', 'P@ssw0rd!123$');

expect(result.code).toBe(200);
expect(result.message).toBe('Email and password are valid.');
});
});

Choose a reason for hiding this comment

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

You're still missing a test case for a valid password that includes Cyrillic letters (e.g., 'ТестПароль!1'). Please add a test to ensure the validator correctly handles the Aa-Яя character set as specified in the requirements.