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

describe('PerformanceReviewQuestionAnswerVC', () => {
    it(`should pass validation if the user sends correct parameters`, () => {
        const { errors } = getValidationClass(
            {
                answer: faker.helpers.arrayElement([faker.word.words(), fakePositiveInteger()]),
                comment: faker.word.words(),
                questionId: faker.string.uuid(),
            },
            PerformanceReviewQuestionAnswerVC,
        );

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

    it(`should pass validation if the user sends null values`, () => {
        const { errors } = getValidationClass(
            {
                answer: null,
                comment: null,
                questionId: faker.string.uuid(),
            },
            PerformanceReviewQuestionAnswerVC,
        );

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

    it(`should pass validation if the user does not send an answer nor a comment`, () => {
        const { errors, output } = getValidationClass(
            {
                questionId: faker.string.uuid(),
            },
            PerformanceReviewQuestionAnswerVC,
        );

        expect(errors).toHaveLength(0);
        expect(output.answer).toBeNull();
        expect(output.comment).toBeNull();
    });

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

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

    it('should validate correctly if the user sends incorrect types', () => {
        const { errors } = getValidationClass(
            {
                answer: null,
                comment: fakePositiveInteger(),
                questionId: fakePositiveInteger(),
            },
            PerformanceReviewQuestionAnswerVC,
        );

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

    it(`should validate correctly if the user sends null question ID`, () => {
        const { errors } = getValidationClass(
            {
                answer: null,
                comment: null,
                questionId: null,
            },
            PerformanceReviewQuestionAnswerVC,
        );

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

    it(`should validate correctly if the user sends empty question ID`, () => {
        const { errors } = getValidationClass(
            {
                answer: null,
                comment: null,
                questionId: '',
            },
            PerformanceReviewQuestionAnswerVC,
        );

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