forked from Yara724/api
fix claim validation and expert branch scoping
This commit is contained in:
55
src/fanavaran/fanavaran-location.service.spec.ts
Normal file
55
src/fanavaran/fanavaran-location.service.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user