import { PerformanceReviewFormReview } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewFormReview';
import { PerformanceReviewFormReviewSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewFormReviewSC';
import { fakePositiveInteger } from '../../../common/common';
import {
    checkPerformanceReviewFormReviewSerialized,
    generateRandomExternalReviewer,
    generateRandomPerformanceReviewFormReview,
    generateRandomPerformanceReviewUser,
} from '../common';

describe('PerformanceReviewFormReviewSC', () => {
    let reviewForm: PerformanceReviewFormReview;
    let extraData: { scoreNeedsObfuscation: boolean };

    beforeEach(() => {
        reviewForm = generateRandomPerformanceReviewFormReview(fakePositiveInteger());
        extraData = { scoreNeedsObfuscation: false };
    });

    it('should serialize review form without users', () => {
        const reviewFormSerialized = new PerformanceReviewFormReviewSC().serialize(reviewForm, extraData);

        expect(reviewFormSerialized).not.toBeNull();

        checkPerformanceReviewFormReviewSerialized(reviewForm, reviewFormSerialized, extraData.scoreNeedsObfuscation);
    });

    it('should serialize review form without users, with obfuscation', () => {
        extraData = { scoreNeedsObfuscation: true };
        const reviewFormSerialized = new PerformanceReviewFormReviewSC().serialize(reviewForm, extraData);

        expect(reviewFormSerialized).not.toBeNull();

        checkPerformanceReviewFormReviewSerialized(reviewForm, reviewFormSerialized, extraData.scoreNeedsObfuscation);
    });

    it('should serialize review form with reviewer', () => {
        reviewForm.reviewer = generateRandomPerformanceReviewUser(reviewForm.reviewerId!);

        const reviewFormSerialized = new PerformanceReviewFormReviewSC().serialize(reviewForm, extraData);

        expect(reviewFormSerialized).not.toBeNull();

        checkPerformanceReviewFormReviewSerialized(reviewForm, reviewFormSerialized, extraData.scoreNeedsObfuscation);
    });

    it('should serialize review form with external reviewer', () => {
        reviewForm.externalReviewer = generateRandomExternalReviewer({ id: reviewForm.externalReviewerId! });

        const reviewFormSerialized = new PerformanceReviewFormReviewSC().serialize(reviewForm, extraData);

        expect(reviewFormSerialized).not.toBeNull();

        checkPerformanceReviewFormReviewSerialized(reviewForm, reviewFormSerialized, extraData.scoreNeedsObfuscation);
    });

    it('should serialize review form with reviewed', () => {
        reviewForm.reviewed = generateRandomPerformanceReviewUser(reviewForm.reviewedId);

        const reviewFormSerialized = new PerformanceReviewFormReviewSC().serialize(reviewForm, extraData);

        expect(reviewFormSerialized).not.toBeNull();

        checkPerformanceReviewFormReviewSerialized(reviewForm, reviewFormSerialized, extraData.scoreNeedsObfuscation);
    });
});
