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", "estimateAiAnalysis"])( "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(); }, ); });