import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewEvaluationTypes } from '../../../../src/api/modules/performanceReviews/business/types/performanceReviewEvaluationTypes';
import { PerformanceReviewFormTemplateVC } from '../../../../src/api/modules/performanceReviews/presentation/validationClasses/performanceReviewFormTemplateVC';
import { fakePositiveInteger } from '../../../common/common';
import { getValidationClass } from '../../../common/serializationClasses/serializationClassesHelper';

describe('PerformanceReviewFormTemplateVC', () => {
    it(`should pass validation if the user sends correct parameters`, () => {
        const { errors } = getValidationClass(
            {
                evaluationType: faker.helpers.arrayElement(Object.values(PerformanceReviewEvaluationTypes)),
                formTemplateId: fakePositiveInteger(),
            },
            PerformanceReviewFormTemplateVC,
        );

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

    it(`should pass validation if the user sends null form template id`, () => {
        const { errors } = getValidationClass(
            {
                evaluationType: faker.helpers.arrayElement(Object.values(PerformanceReviewEvaluationTypes)),
                formTemplateId: null,
            },
            PerformanceReviewFormTemplateVC,
        );

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

    it(`should pass validation if the user sends empty form template id`, () => {
        const { errors, output } = getValidationClass(
            {
                evaluationType: faker.helpers.arrayElement(Object.values(PerformanceReviewEvaluationTypes)),
            },
            PerformanceReviewFormTemplateVC,
        );

        expect(errors).toHaveLength(0);
        expect(output.templateId).toBeNull();
    });

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

        ['evaluationType'].forEach((property) => {
            expect(errors).toPartiallyContain({ property });
        });
    });

    it('should validate correctly if the user sends incorrect types', () => {
        const { errors } = getValidationClass(
            {
                evaluationType: faker.datatype.boolean(),
                formTemplateId: faker.word.words(),
            },
            PerformanceReviewFormTemplateVC,
        );

        ['evaluationType', 'formTemplateId'].forEach((property) => {
            expect(errors).toPartiallyContain({ property });
        });
    });

    it(`should validate correctly if the user sends incorrect evaluation type`, () => {
        const { errors } = getValidationClass(
            {
                evaluationType: faker.word.words(),
                formTemplateId: fakePositiveInteger(),
            },
            PerformanceReviewFormTemplateVC,
        );

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