import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewCycle } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewCycle';
import { PerformanceReviewCycleWithUserReviewsSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewCycleWithUserReviewsSC';
import {
    checkPerformanceReviewCycleSerializedWithUserReviews,
    generateRandomPerformanceReviewCycle,
    generateRandomPerformanceReviewFormReview,
} from '../common';

describe('PerformanceReviewCycleWithUserReviewsSC', () => {
    let reviewCycle: PerformanceReviewCycle;

    beforeEach(() => {
        reviewCycle = generateRandomPerformanceReviewCycle();
    });

    it('should serialize review cycle without form reviews', () => {
        const reviewCycleSerialized = new PerformanceReviewCycleWithUserReviewsSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerializedWithUserReviews(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with reviewer form reviews', () => {
        const formReviewsCount = faker.number.int({ max: 3, min: 1 });
        reviewCycle.reviewerFormReviews = Array(formReviewsCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewFormReview(reviewCycle.id));

        const reviewCycleSerialized = new PerformanceReviewCycleWithUserReviewsSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerializedWithUserReviews(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with reviewed form reviews', () => {
        const formReviewsCount = faker.number.int({ max: 3, min: 1 });
        reviewCycle.reviewedFormReviews = Array(formReviewsCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewFormReview(reviewCycle.id));

        const reviewCycleSerialized = new PerformanceReviewCycleWithUserReviewsSC().serialize(reviewCycle);

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerializedWithUserReviews(reviewCycle, reviewCycleSerialized);
    });

    it('should serialize review cycle with reviewed form reviews and obfuscate scores', () => {
        const formReviewsCount = faker.number.int({ max: 3, min: 1 });
        reviewCycle.reviewedFormReviews = Array(formReviewsCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewFormReview(reviewCycle.id));

        const reviewCycleSerialized = new PerformanceReviewCycleWithUserReviewsSC().serialize(reviewCycle, { scoreNeedsObfuscation: true });

        expect(reviewCycleSerialized).not.toBeNull();

        checkPerformanceReviewCycleSerializedWithUserReviews(reviewCycle, reviewCycleSerialized, true);
    });
});
