import { ForbiddenException } from "@nestjs/common"; import { ClaimRequestManagementService } from "./claim-request-management.service"; import { RoleEnum } from "src/Types&Enums/role.enum"; describe("V2 claim-detail access for split file roles", () => { const makerId = "maker-id"; const reviewerId = "reviewer-id"; const createService = (blame: Record) => { const service = Object.create( ClaimRequestManagementService.prototype, ) as ClaimRequestManagementService; (service as any).blameRequestDbService = { findById: jest.fn().mockResolvedValue(blame), }; return service; }; const claim = { blameRequestId: "blame-id" }; it("allows the FileMaker who created a completed V4/V5 file", async () => { const service = createService({ isMadeByFileMaker: true, expertInitiated: true, creationMethod: "IN_PERSON", initiatedByFieldExpertId: makerId, }); await expect( (service as any).assertActorCanViewClaimV2(claim, makerId, { sub: makerId, role: RoleEnum.FILE_MAKER, }), ).resolves.toBeUndefined(); }); it("allows only the assigned FileReviewer", async () => { const service = createService({ isMadeByFileMaker: true, expertInitiated: true, creationMethod: "IN_PERSON", assignedFileReviewerId: reviewerId, }); await expect( (service as any).assertActorCanViewClaimV2(claim, reviewerId, { sub: reviewerId, role: RoleEnum.FILE_REVIEWER, }), ).resolves.toBeUndefined(); await expect( (service as any).assertActorCanViewClaimV2(claim, "other-reviewer", { sub: "other-reviewer", role: RoleEnum.FILE_REVIEWER, }), ).rejects.toBeInstanceOf(ForbiddenException); }); });