import { faker } from '@faker-js/faker/locale/en_US';
import { PerformanceReviewTargetUser } from '../../../../src/api/modules/performanceReviews/business/models/performanceReviewTargetUser';
import { PerformanceReviewTargetUserWithUserReviewsSC } from '../../../../src/api/modules/performanceReviews/presentation/serializationClasses/performanceReviewTargetUserWithUserReviewsSC';
import { fakePositiveInteger } from '../../../common/common';
import {
    checkPerformanceReviewTargetUserSerializedWithUserReviews,
    generateRandomPerformanceReviewFormReview,
    generateRandomPerformanceReviewTargetUser,
} from '../common';

describe('PerformanceReviewTargetUserWithUserReviewsSC', () => {
    let targetUser: PerformanceReviewTargetUser;
    let extraData: { scoreNeedsObfuscation: boolean };

    beforeEach(() => {
        targetUser = generateRandomPerformanceReviewTargetUser(fakePositiveInteger(), fakePositiveInteger(), fakePositiveInteger());
        extraData = { scoreNeedsObfuscation: false };
    });

    it('should serialize target user without form reviews', () => {
        const targetUserSerialized = new PerformanceReviewTargetUserWithUserReviewsSC().serialize(targetUser, extraData);

        expect(targetUserSerialized).not.toBeNull();

        checkPerformanceReviewTargetUserSerializedWithUserReviews(targetUser, targetUserSerialized, extraData.scoreNeedsObfuscation);
    });

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

        const targetUserSerialized = new PerformanceReviewTargetUserWithUserReviewsSC().serialize(targetUser, extraData);

        expect(targetUserSerialized).not.toBeNull();

        checkPerformanceReviewTargetUserSerializedWithUserReviews(targetUser, targetUserSerialized, extraData.scoreNeedsObfuscation);
    });

    it('should serialize target user with reviewed form reviews and score obfuscated', () => {
        const formReviewsCount = faker.number.int({ max: 3, min: 1 });
        targetUser.reviewedFormReviews = Array(formReviewsCount)
            .fill(1)
            .map(() => generateRandomPerformanceReviewFormReview(targetUser.cycleId));

        extraData = { scoreNeedsObfuscation: true };
        const targetUserSerialized = new PerformanceReviewTargetUserWithUserReviewsSC().serialize(targetUser, extraData);

        expect(targetUserSerialized).not.toBeNull();

        checkPerformanceReviewTargetUserSerializedWithUserReviews(targetUser, targetUserSerialized, extraData.scoreNeedsObfuscation);
    });
});
