import { faker } from '@faker-js/faker/locale/en_US';
import { UpdatePerformanceReviewCycleTargetUsersVC } from '../../../../src/api/modules/performanceReviews/presentation/validationClasses/updatePerformanceReviewCycleTargetUsersVC';
import { fakePositiveInteger } from '../../../common/common';
import { getValidationClass } from '../../../common/serializationClasses/serializationClassesHelper';

describe('UpdatePerformanceReviewCycleTargetUsersVC', () => {
    it(`should pass validation if the user sends correct parameters`, () => {
        const possibleIds = Array.from(new Set(faker.helpers.multiple(faker.number.int, { count: 10 })));
        const { errors } = getValidationClass(
            {
                userIds: faker.helpers.arrayElements(possibleIds),
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toHaveLength(0);
    });

    it(`should pass validation if the user sends correct parameters with one user id`, () => {
        const { errors } = getValidationClass(
            {
                userIds: [fakePositiveInteger()],
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toHaveLength(0);
    });

    it('should validate correctly if the user sends an empty object', () => {
        const { errors } = getValidationClass({}, UpdatePerformanceReviewCycleTargetUsersVC);

        expect(errors).toPartiallyContain({ property: 'userIds' });
    });

    it('should validate correctly if the user sends incorrect types', () => {
        const { errors } = getValidationClass(
            {
                userIds: faker.word.words(),
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toPartiallyContain({ property: 'userIds' });
    });

    it('should validate correctly if the user sends a number instead of an array', () => {
        const { errors } = getValidationClass(
            {
                userIds: fakePositiveInteger(),
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toPartiallyContain({ property: 'userIds' });
    });

    it('should validate correctly if the user sends an empty array', () => {
        const { errors } = getValidationClass(
            {
                userIds: [],
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toPartiallyContain({ property: 'userIds' });
    });

    it('should validate correctly if the user sends an array with repeated values', () => {
        const userId = fakePositiveInteger();
        const { errors } = getValidationClass(
            {
                userIds: [userId, userId],
            },
            UpdatePerformanceReviewCycleTargetUsersVC,
        );

        expect(errors).toPartiallyContain({ property: 'userIds' });
    });
});
