forked from Yara724/api
133 lines
4.2 KiB
TypeScript
133 lines
4.2 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("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("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",
|
|
}),
|
|
).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"]);
|
|
});
|
|
});
|