forked from Yara724/api
feat(depreciation): apply Fanavaran tables and age eligibility
Use the supplied part, severity and age codes for depreciation. Exclude vehicles older than ten from calculated and manual amounts, preserve historical assessments, and send zero depreciation to Fanavaran for ineligible vehicles.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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 } }),
|
||||
);
|
||||
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(age > 10 ? 0 : 999);
|
||||
expect(claimCase.evaluation.priceDrop.total).toBe(999); // Historical data is preserved.
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user