fix(fanavaran): resolve hull expertise policy from stored inquiry

Reuse the insured vehicle hull inquiry policy when saved base-claim policy metadata is absent. This lets expertise resolve policy accessories and factory coverage before stage 1 has been persisted. Add a regression test for the missing-cache case.
This commit is contained in:
2026-11-24 12:59:05 +03:30
parent f29461fa67
commit 3f920c0be5
2 changed files with 33 additions and 4 deletions
@@ -2842,7 +2842,11 @@ export class ClaimRequestManagementService {
infoWarnings: string[];
replyKey?: string;
}> {
const policyId = this.parseHullClaimPolicyId(input.claimCase);
// Expertise preview may run before a base-claim payload has been saved.
// Reuse the insured vehicle's hull inquiry policy, as stage 1 does.
const policyId =
this.parseHullClaimPolicyId(input.claimCase) ??
pickStoredCarBodyPolicyId(input.blame);
const contractOptions = {
contractIdOverride: resolveFanavaranProductContractId(
input.clientKey,
@@ -10,7 +10,7 @@ function setup(accessories: unknown) {
"vehicle-hull-dmg-cost-kinds": [
{ Id: 8002, Caption: "مجموع لوازم", IsActive: 1 },
],
"car-components": [9, 13, 112, 10, 48, 76, 29, 100, 37].map(Id => ({ Id })),
"car-components": [1, 9, 13, 112, 10, 48, 76, 29, 100, 37].map(Id => ({ Id })),
})[name] ?? [],
);
service.fanavaranLookupService = {
@@ -25,11 +25,12 @@ function setup(accessories: unknown) {
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
],
context: { claimCase?: any; blame?: any } = {},
) =>
service.buildCarBodyFanavaranExpertisePayload({
clientKey: "parsian",
claimCase: { fanavaranSync: { baseClaim: { policyId } } },
blame: { parties: [] },
claimCase: context.claimCase ?? { fanavaranSync: { baseClaim: { policyId } } },
blame: context.blame ?? { parties: [] },
profile: {},
parts,
claimExpertId: 4044,
@@ -43,6 +44,30 @@ function setup(accessories: unknown) {
}
describe("hull expertise policy accessory mapping", () => {
it("uses the hull inquiry policy when stage-1 policy metadata is absent", async () => {
const { service, build } = setup([
{ Id: 2598601, AccessoryKindId: 92, AccessoryDesc: "پايونير 1650" },
{ Id: 2598602, AccessoryKindId: 93, AccessoryDesc: "غير فابريک" },
{ Id: 3043330, AccessoryKindId: 112, AccessoryDesc: "کليه قطعات فابريک" },
]);
const { payload, warnings } = await build(null, [
{ partId: 1, partName: "جلو کامل", salary: 10000000 },
], {
claimCase: {},
blame: {
parties: [{ role: "FIRST", insurance: { carBodyInsurance: { policyId: 13764610 } } }],
},
});
expect(payload.DmgSections[0]).toMatchObject({
AccessoryKindId: 1,
VehicleHullAccessoryId: 3043330,
});
expect(warnings).toEqual([]);
expect(service.fanavaranLookupService.vehicleHullDmgAccessoriesByPolicyId)
.toHaveBeenCalledWith("parsian", 13764610, expect.any(Object));
});
it("uses the current policy accessory IDs for the bumper and headlamp", async () => {
const { service, build } = setup([
{ Id: 900001, AccessoryKindId: 9, AccessoryDesc: "سپر جلو" },