Added AI damage helper

This commit is contained in:
SepehrYahyaee
2026-10-03 16:38:48 +03:30
parent 18ccfa81e4
commit 2f92766689
22 changed files with 1085 additions and 442 deletions
+86
View File
@@ -0,0 +1,86 @@
import { SuperAdminController } from "src/super-admin/super-admin.controller";
import { ForbiddenException } from "@nestjs/common";
import { ExpertClaimV2Controller } from "src/expert-claim/expert-claim.v2.controller";
import { ExpertInsurerController } from "src/expert-insurer/expert-insurer.controller";
describe("AI analysis file access", () => {
const actor = { sub: "actor", clientKey: "tenant" };
it.each(["getAiAnalysis", "retryAiAnalysis"])(
"expert %s uses the existing file access gate before reading results or scheduling work",
async (method) => {
const service = {
getClaimDetailV2: jest.fn().mockRejectedValue(new ForbiddenException()),
};
const ai = { list: jest.fn(), retry: jest.fn() },
db = { findById: jest.fn() };
const controller = new ExpertClaimV2Controller(
service as any,
ai as any,
db as any,
{} as any,
);
await expect(controller[method]("other-tenant", actor)).rejects.toThrow(
ForbiddenException,
);
expect(db.findById).not.toHaveBeenCalled();
expect(ai.list).not.toHaveBeenCalled();
expect(ai.retry).not.toHaveBeenCalled();
},
);
it.each(["getAiAnalysis", "retryAiAnalysis"])(
"insurer %s validates its public file identifier before resolving a claim",
async (method) => {
const service = {
retrieveFileDetailsByPublicId: jest
.fn()
.mockRejectedValue(new ForbiddenException()),
};
const ai = { list: jest.fn(), retry: jest.fn() },
db = { findById: jest.fn() };
const controller = new ExpertInsurerController(
service as any,
{} as any,
ai as any,
db as any,
);
await expect(controller[method](actor, "other-tenant")).rejects.toThrow(
ForbiddenException,
);
expect(service.retrieveFileDetailsByPublicId).toHaveBeenCalledWith(
"tenant",
"other-tenant",
);
expect(db.findById).not.toHaveBeenCalled();
},
);
});
describe("admin AI tenant selection", () => {
it.each(["getAiAnalysis", "retryAiAnalysis"])(
"%s resolves the file inside the selected tenant before reading AI results",
async (method) => {
const insurer = {
retrieveFileDetailsByPublicId: jest
.fn()
.mockRejectedValue(new ForbiddenException()),
};
const ai = { list: jest.fn(), retry: jest.fn() },
db = { findById: jest.fn() };
const controller = new SuperAdminController(
{} as any,
{} as any,
insurer as any,
ai as any,
db as any,
);
await expect(
controller[method]("selected-client", "other-client-file"),
).rejects.toThrow(ForbiddenException);
expect(insurer.retrieveFileDetailsByPublicId).toHaveBeenCalledWith(
"selected-client",
"other-client-file",
);
expect(db.findById).not.toHaveBeenCalled();
},
);
});