forked from Yara724/api
update the IsLicenseReplaced and for the accessories
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
||||
|
||||
function setup(accessories: unknown) {
|
||||
const service = Object.create(ClaimRequestManagementService.prototype) as any;
|
||||
service.logger = { warn: jest.fn(), log: jest.fn() };
|
||||
service.getFanavaranLookupRows = jest.fn().mockImplementation(
|
||||
async (_client: string, name: string) =>
|
||||
({
|
||||
"vehicle-hull-dmg-kind": [{ Id: 8001, Caption: "تخريب", IsActive: 1 }],
|
||||
"vehicle-hull-dmg-cost-kinds": [
|
||||
{ Id: 8002, Caption: "مجموع لوازم", IsActive: 1 },
|
||||
],
|
||||
"car-components": [{ Id: 9 }, { Id: 13 }],
|
||||
})[name] ?? [],
|
||||
);
|
||||
service.fanavaranLookupService = {
|
||||
bodyPolicyById: jest.fn().mockResolvedValue({ VehicleValue: 15000000000 }),
|
||||
vehicleHullDmgAccessoriesByPolicyId: jest
|
||||
.fn()
|
||||
.mockResolvedValue(accessories),
|
||||
};
|
||||
const build = (policyId = 123) =>
|
||||
service.buildCarBodyFanavaranExpertisePayload({
|
||||
clientKey: "parsian",
|
||||
claimCase: { fanavaranSync: { baseClaim: { policyId } } },
|
||||
blame: { parties: [] },
|
||||
profile: {},
|
||||
parts: [
|
||||
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
|
||||
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
|
||||
],
|
||||
claimExpertId: 4044,
|
||||
submittedAt: new Date("2026-11-11T09:09:00Z"),
|
||||
priceDropTotal: 0,
|
||||
priceDropCarPrice: null,
|
||||
warnings: [],
|
||||
});
|
||||
return { service, build };
|
||||
}
|
||||
|
||||
describe("hull expertise policy accessory mapping", () => {
|
||||
it("uses the current policy accessory IDs for the bumper and headlamp", async () => {
|
||||
const { service, build } = setup([
|
||||
{ Id: 900001, AccessoryKindId: 9, AccessoryDesc: "سپر جلو" },
|
||||
{ Id: 900002, AccessoryKindId: 13, AccessoryDesc: "چراغ جلو چپ" },
|
||||
]);
|
||||
const { payload, warnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([900001, 900002]);
|
||||
expect(warnings).toEqual([]);
|
||||
expect(payload.DmgSections[0]).toMatchObject({
|
||||
DmgKindId: 8001,
|
||||
DmgSectionCosts: [
|
||||
{
|
||||
DmgCostKindId: 8002,
|
||||
Caption: expect.any(String),
|
||||
Amount: expect.any(Number),
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(
|
||||
service.fanavaranLookupService.vehicleHullDmgAccessoriesByPolicyId,
|
||||
).toHaveBeenCalledWith(
|
||||
"parsian",
|
||||
123,
|
||||
expect.objectContaining({ contractIdOverride: expect.any(String) }),
|
||||
);
|
||||
});
|
||||
|
||||
it("uses a factory bundle only when it belongs to the current policy", async () => {
|
||||
const { build } = setup([
|
||||
{ Id: 900003, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
]);
|
||||
const { payload } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([900003, 900003]);
|
||||
});
|
||||
|
||||
it("does not replace unavailable lookup values with 5485 or 1", async () => {
|
||||
const { service, build } = setup([
|
||||
{ Id: 2810613, AccessoryDesc: "کليه قطعات فابريک" },
|
||||
]);
|
||||
service.getFanavaranLookupRows.mockResolvedValue([]);
|
||||
const { payload, warnings } = await build();
|
||||
expect(payload.DmgSections[0]).toMatchObject({ DmgKindId: null });
|
||||
expect(payload.DmgSections[0].DmgSectionCosts[0].DmgCostKindId).toBeNull();
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("DmgKindId"),
|
||||
expect.stringContaining("DmgCostKindId"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports unavailable lookup data without reusing the old hardcoded ID", async () => {
|
||||
const { service, build } = setup([]);
|
||||
service.fanavaranLookupService.vehicleHullDmgAccessoriesByPolicyId.mockRejectedValue(
|
||||
new Error("lookup unavailable"),
|
||||
);
|
||||
const { payload, warnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("reports a missing hull PolicyId instead of using the claim ID as a policy", async () => {
|
||||
const { service, build } = setup([]);
|
||||
const { warnings } = await build(null);
|
||||
expect(
|
||||
service.fanavaranLookupService.vehicleHullDmgAccessoriesByPolicyId,
|
||||
).not.toHaveBeenCalled();
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([expect.stringContaining("missing PolicyId")]),
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ rows: [] },
|
||||
{ rows: [{ Id: 900004, AccessoryKindId: 99, AccessoryDesc: "unrelated" }] },
|
||||
])(
|
||||
"reports unmapped accessories instead of guessing an ID: %j",
|
||||
async ({ rows }) => {
|
||||
const { build } = setup(rows);
|
||||
const { payload, warnings } = await build();
|
||||
expect(
|
||||
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
|
||||
).toEqual([null, null]);
|
||||
expect(warnings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("VehicleHullAccessoryId"),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user