forked from Yara724/api
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
|
|
|
describe("Fanavaran depreciation age eligibility", () => {
|
|
it.each(
|
|
["car-body", "third-party"].flatMap((product) =>
|
|
[10, 11].map((age) => ({ product, age })),
|
|
),
|
|
)(
|
|
"$product: age $age uses the eligible total only",
|
|
async ({ product, age }) => {
|
|
const service = Object.create(
|
|
ClaimRequestManagementService.prototype,
|
|
) as any;
|
|
const first = {
|
|
role: "FIRST",
|
|
person: { userId: "first" },
|
|
statement: { accidentDate: "2026-11-23" },
|
|
vehicle: { inquiry: { mapped: { ModelField: String(1405 - age) } } },
|
|
};
|
|
const second = {
|
|
role: "SECOND",
|
|
person: { userId: "second" },
|
|
vehicle: first.vehicle,
|
|
};
|
|
const blame =
|
|
product === "car-body"
|
|
? { type: "CAR_BODY", parties: [first] }
|
|
: {
|
|
type: "THIRD_PARTY",
|
|
parties: [first, second],
|
|
expert: { decision: { guiltyPartyId: "first" } },
|
|
};
|
|
service.blameRequestDbService = {
|
|
findById: jest.fn().mockResolvedValue(blame),
|
|
};
|
|
service.tryResolveFanavaranExpertiseClaimExpertId = jest
|
|
.fn()
|
|
.mockResolvedValue({ claimExpertId: 4044 });
|
|
service.resolveFanavaranClaimProduct = jest
|
|
.fn()
|
|
.mockResolvedValue(product);
|
|
service.getFanavaranLookupRows = jest.fn().mockResolvedValue([]);
|
|
service.buildCarBodyFanavaranExpertisePayload = jest.fn(
|
|
async (input) => ({ payload: { DropAmount: input.priceDropTotal ?? 0 } }),
|
|
);
|
|
const claimCase = {
|
|
_id: "claim",
|
|
blameRequestId: "blame",
|
|
owner: { userId: "first" },
|
|
evaluation: { priceDrop: { total: 999, carPrice: 400000000 } },
|
|
};
|
|
const result = await service.buildFanavaranExpertisePayload({
|
|
claimCase,
|
|
clientKey: "parsian",
|
|
});
|
|
expect(
|
|
result.payload[
|
|
product === "car-body"
|
|
? "DropAmount"
|
|
: "DropAmountAdditionsDeductions"
|
|
],
|
|
).toBe(product === "car-body" || age > 10 ? 0 : 999);
|
|
expect(claimCase.evaluation.priceDrop.total).toBe(999); // Historical data is preserved.
|
|
},
|
|
);
|
|
});
|