import { ForbiddenException } from "@nestjs/common"; import { FanavaranLocationService } from "./fanavaran-location.service"; describe("FanavaranLocationService branch scope", () => { const makerId = "maker-1"; const reviewerId = "reviewer-1"; const createService = (makerBranch?: string, reviewerBranch?: string) => new FanavaranLocationService( { findById: jest.fn().mockResolvedValue( makerBranch ? { branchId: makerBranch } : {}, ), } as any, { findById: jest.fn().mockResolvedValue( reviewerBranch ? { branchId: reviewerBranch } : {}, ), } as any, ); it("allows a reviewer to view a file from the same branch", async () => { const service = createService("branch-1", "branch-1"); await expect( service.assertMakerReviewerBranchCompatible({ fileMakerId: makerId, fileReviewerId: reviewerId, }), ).resolves.toBeUndefined(); }); it("rejects a reviewer from another branch", async () => { const service = createService("branch-1", "branch-2"); await expect( service.assertMakerReviewerBranchCompatible({ fileMakerId: makerId, fileReviewerId: reviewerId, }), ).rejects.toBeInstanceOf(ForbiddenException); }); it("prefers the immutable case branch snapshot", async () => { const service = createService("old-branch", "branch-2"); await expect( service.assertMakerReviewerBranchCompatible({ fileMakerId: makerId, fileReviewerId: reviewerId, caseBranchId: "branch-2", }), ).resolves.toBeUndefined(); }); });