forked from Yara724/api
266 lines
8.3 KiB
TypeScript
266 lines
8.3 KiB
TypeScript
import { BadRequestException } from "@nestjs/common";
|
|
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
|
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
|
|
|
function serviceWithStaff(stubs: {
|
|
fileMaker?: any;
|
|
fileReviewer?: any;
|
|
fieldExpert?: any;
|
|
expert?: any;
|
|
damageExpert?: any;
|
|
}) {
|
|
const management = Object.create(
|
|
ClaimRequestManagementService.prototype,
|
|
) as any;
|
|
management.fileMakerDbService = {
|
|
findById: jest.fn().mockResolvedValue(stubs.fileMaker ?? null),
|
|
};
|
|
management.fileReviewerDbService = {
|
|
findById: jest.fn().mockResolvedValue(stubs.fileReviewer ?? null),
|
|
};
|
|
management.fieldExpertDbService = {
|
|
findById: jest.fn().mockResolvedValue(stubs.fieldExpert ?? null),
|
|
};
|
|
management.expertDbService = {
|
|
findById: jest.fn().mockResolvedValue(stubs.expert ?? null),
|
|
};
|
|
management.damageExpertDbService = {
|
|
findById: jest.fn().mockResolvedValue(stubs.damageExpert ?? null),
|
|
};
|
|
return management as ClaimRequestManagementService;
|
|
}
|
|
|
|
describe("Fanavaran assigned ClaimExpertId resolution", () => {
|
|
it("resolves a user-created base claim from its damage-expert reply actor", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: {
|
|
ThirdPartyClaimExpertId: "5507",
|
|
ThirdPartyExpertiseClaim: "5510",
|
|
},
|
|
});
|
|
const resolved = await (
|
|
management as any
|
|
).tryResolveFanavaranBaseClaimExpertId(
|
|
{ type: BlameRequestType.THIRD_PARTY },
|
|
{
|
|
evaluation: {
|
|
damageExpertReply: {
|
|
actorDetail: { actorId: "6af036ab0222c1322767ce19" },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
expect(resolved).toMatchObject({
|
|
claimExpertId: 5507,
|
|
code: null,
|
|
candidatesTried: ["6af036ab0222c1322767ce19"],
|
|
});
|
|
});
|
|
|
|
it("reads GEN.03 ClaimExpertId from assigned blame expert DB codes", async () => {
|
|
const management = serviceWithStaff({
|
|
expert: { ThirdPartyClaimExpertId: "154" },
|
|
});
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId({
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
expert: { assignedExpertId: "expert-1" },
|
|
}),
|
|
).resolves.toBe(154);
|
|
});
|
|
|
|
it.each(["blame", "claim"])(
|
|
"reads V2/V3 stage-1 codes from the %s field-expert initiator",
|
|
async (source) => {
|
|
const management = serviceWithStaff({
|
|
fieldExpert: { ThirdPartyClaimExpertId: "154" },
|
|
});
|
|
(management as any).damageExpertDbService.findById.mockImplementation(
|
|
async (id: string) =>
|
|
id === "dmg-1" ? { ThirdPartyClaimExpertId: "5507" } : null,
|
|
);
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId(
|
|
{
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
...(source === "blame" && { initiatedByFieldExpertId: "field-1" }),
|
|
},
|
|
{
|
|
...(source === "claim" && { initiatedByFieldExpertId: "field-1" }),
|
|
evaluation: {
|
|
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
|
},
|
|
},
|
|
),
|
|
).resolves.toBe(154);
|
|
},
|
|
);
|
|
|
|
it("resolves the CAR_BODY stage-1 code from the final review actor", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: {
|
|
CarBodyClaimExpertId: "5508",
|
|
CarBodyExpertiseClaim: "5509",
|
|
},
|
|
});
|
|
const resolved = await (
|
|
management as any
|
|
).tryResolveFanavaranBaseClaimExpertId(
|
|
{ type: BlameRequestType.CAR_BODY },
|
|
{
|
|
evaluation: {
|
|
damageExpertReply: { actorDetail: { actorId: "initial-reviewer" } },
|
|
damageExpertReplyFinal: {
|
|
actorDetail: { actorId: "final-reviewer" },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
expect(resolved.claimExpertId).toBe(5508);
|
|
expect(
|
|
(management as any).damageExpertDbService.findById,
|
|
).toHaveBeenCalledWith("final-reviewer");
|
|
});
|
|
|
|
it("resolves stage-1 from persistent claim assignment before a reply exists", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: { ThirdPartyClaimExpertId: "5507" },
|
|
});
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId(
|
|
{ type: BlameRequestType.THIRD_PARTY },
|
|
{ workflow: { assignedForReviewBy: { actorId: "dmg-1" } } },
|
|
),
|
|
).resolves.toBe(5507);
|
|
});
|
|
|
|
it("does not treat a temporary workflow lock as review assignment", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: { ThirdPartyClaimExpertId: "5507" },
|
|
});
|
|
const resolved = await (
|
|
management as any
|
|
).tryResolveFanavaranBaseClaimExpertId(
|
|
{ type: BlameRequestType.THIRD_PARTY },
|
|
{ workflow: { lockedBy: { actorId: "someone-else" } } },
|
|
);
|
|
expect(resolved.claimExpertId).toBeNull();
|
|
expect(
|
|
(management as any).damageExpertDbService.findById,
|
|
).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("reports an attached review actor whose stage-1 code is missing", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: { ThirdPartyExpertiseClaim: "5510" },
|
|
});
|
|
const resolved = await (
|
|
management as any
|
|
).tryResolveFanavaranBaseClaimExpertId(
|
|
{ type: BlameRequestType.THIRD_PARTY },
|
|
{
|
|
evaluation: {
|
|
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
|
},
|
|
},
|
|
);
|
|
expect(resolved.claimExpertId).toBeNull();
|
|
expect(resolved.candidatesTried).toEqual(["dmg-1"]);
|
|
expect(resolved.message).toContain("ThirdPartyClaimExpertId=empty");
|
|
});
|
|
|
|
it("reads GEN.03 ClaimExpertId from FileMaker on V4/V5", async () => {
|
|
const management = serviceWithStaff({
|
|
fileMaker: {
|
|
ThirdPartyClaimExpertId: "5347",
|
|
CarBodyClaimExpertId: "100",
|
|
},
|
|
});
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId(
|
|
{
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
isMadeByFileMaker: true,
|
|
initiatedByFieldExpertId: "fm-1",
|
|
},
|
|
{
|
|
evaluation: {
|
|
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
|
},
|
|
},
|
|
),
|
|
).resolves.toBe(5347);
|
|
});
|
|
|
|
it("reads expertise ClaimExpertId from damage-expert reply actor", async () => {
|
|
const management = serviceWithStaff({
|
|
damageExpert: { ThirdPartyExpertiseClaim: "29" },
|
|
});
|
|
await expect(
|
|
(management as any).resolveFanavaranExpertiseClaimExpertId(
|
|
{ type: BlameRequestType.THIRD_PARTY },
|
|
{
|
|
evaluation: {
|
|
damageExpertReply: {
|
|
actorDetail: { actorId: "dmg-1" },
|
|
submittedAt: new Date(),
|
|
parts: [{ price: 1 }],
|
|
},
|
|
},
|
|
},
|
|
),
|
|
).resolves.toBe(29);
|
|
});
|
|
|
|
it("reads expertise ClaimExpertId from FileReviewer on V4/V5", async () => {
|
|
const management = serviceWithStaff({
|
|
fileReviewer: { CarBodyExpertiseClaim: "15" },
|
|
});
|
|
await expect(
|
|
(management as any).resolveFanavaranExpertiseClaimExpertId(
|
|
{
|
|
type: BlameRequestType.CAR_BODY,
|
|
isMadeByFileMaker: true,
|
|
assignedFileReviewerId: "fr-1",
|
|
},
|
|
null,
|
|
),
|
|
).resolves.toBe(15);
|
|
});
|
|
|
|
it("does not fall back to hardcoded tenant ClaimExpertId", async () => {
|
|
const management = serviceWithStaff({});
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId({
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
expert: { assignedExpertId: "missing" },
|
|
}),
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
});
|
|
|
|
it("preview soft-resolve returns null plus a concrete warning instead of throwing", async () => {
|
|
const management = serviceWithStaff({});
|
|
await expect(
|
|
(management as any).resolveFanavaranBaseClaimExpertId(
|
|
{
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
expert: { assignedExpertId: "missing" },
|
|
},
|
|
null,
|
|
{ required: false },
|
|
),
|
|
).resolves.toBeNull();
|
|
|
|
const soft = await (management as any).tryResolveFanavaranBaseClaimExpertId(
|
|
{
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
expert: { assignedExpertId: "missing" },
|
|
},
|
|
);
|
|
expect(soft.claimExpertId).toBeNull();
|
|
expect(soft.code).toBe("FANAVARAN_CLAIM_EXPERT_ID_MISSING");
|
|
expect(soft.message).toMatch(/ThirdPartyClaimExpertId/);
|
|
expect(soft.candidatesTried).toEqual(["missing"]);
|
|
});
|
|
});
|