import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewCoreFormSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewCoreFormSC';
import { fakePositiveInteger } from '../../../common/common';
import {
    generateFormAnswerWithValues,
    generateFormQuestionAnswerFromInterface,
    generateFormQuestionAnswersFromCoreForm,
    generateRandomCoreFormWithQuestions,
} from '../../../kernels/forms/common';
import { checkPerformanceReviewCoreFormSerialized } from '../common';

describe('PerformanceReviewCoreFormSC', () => {
    it('should serialize a core form', () => {
        const coreForm = generateRandomCoreFormWithQuestions(faker.string.uuid(), fakePositiveInteger());
        const coreFormSerialized = new PerformanceReviewCoreFormSC().serialize(coreForm);

        expect(coreFormSerialized).not.toBeNull();

        checkPerformanceReviewCoreFormSerialized(coreForm, null,null, coreFormSerialized);
    });

    it('should serialize a core form with a form answer', () => {
        const coreForm = generateRandomCoreFormWithQuestions(faker.string.uuid(), fakePositiveInteger());
        const formAnswer = generateFormAnswerWithValues(
            fakePositiveInteger(),
            coreForm.tag,
            coreForm.id,
            coreForm.content.steps.map((step) => step.id),
        );
        formAnswer.questionAnswers = generateFormQuestionAnswersFromCoreForm(coreForm, formAnswer.id).formQuestionAnswers.map(
            (answerCreationInterface) => generateFormQuestionAnswerFromInterface(answerCreationInterface),
        );
        const coreFormSerialized = new PerformanceReviewCoreFormSC().serialize(coreForm, { answer: formAnswer });

        expect(coreFormSerialized).not.toBeNull();

        checkPerformanceReviewCoreFormSerialized(coreForm, null,null, coreFormSerialized, formAnswer);
    });
});
