fanavaran expert codes

This commit is contained in:
2026-11-09 18:05:20 +03:30
parent c81002da7d
commit f33eabeb4f
2 changed files with 183 additions and 29 deletions
@@ -31,6 +31,32 @@ function serviceWithStaff(stubs: {
}
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" },
@@ -43,6 +69,106 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => {
).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: {
@@ -51,11 +177,18 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => {
},
});
await expect(
(management as any).resolveFanavaranBaseClaimExpertId({
type: BlameRequestType.THIRD_PARTY,
isMadeByFileMaker: true,
initiatedByFieldExpertId: "fm-1",
}),
(management as any).resolveFanavaranBaseClaimExpertId(
{
type: BlameRequestType.THIRD_PARTY,
isMadeByFileMaker: true,
initiatedByFieldExpertId: "fm-1",
},
{
evaluation: {
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
},
},
),
).resolves.toBe(5347);
});