forked from Yara724/api
150 lines
5.0 KiB
TypeScript
150 lines
5.0 KiB
TypeScript
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
|
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
|
import {
|
|
fanavaranClaimProductFromBlameType,
|
|
fanavaranClaimsBaseUrl,
|
|
fanavaranClaimStageUrl,
|
|
fanavaranHasDamageCaseStage,
|
|
fanavaranPartyInquirySources,
|
|
isFanavaranSubmitSupportedBlameType,
|
|
pickCarBodyPolicyNationalCode,
|
|
pickStoredCarBodyPolicyId,
|
|
} from "./fanavaran-claim-product";
|
|
|
|
describe("fanavaran claim product", () => {
|
|
it("maps CAR_BODY blame files onto the hull claims resource", () => {
|
|
expect(fanavaranClaimProductFromBlameType(BlameRequestType.CAR_BODY)).toBe(
|
|
"car-body",
|
|
);
|
|
expect(fanavaranClaimsBaseUrl("car-body")).toBe(
|
|
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car/vehicle-hull-claims",
|
|
);
|
|
});
|
|
|
|
it("keeps THIRD_PARTY on the financial third-party claims resource", () => {
|
|
expect(
|
|
fanavaranClaimProductFromBlameType(BlameRequestType.THIRD_PARTY),
|
|
).toBe("third-party");
|
|
expect(fanavaranClaimsBaseUrl("third-party")).toBe(
|
|
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car/third-party-car-financial-claims",
|
|
);
|
|
});
|
|
|
|
it("does not POST hull damage to the missing dmg-cases resource", () => {
|
|
expect(fanavaranHasDamageCaseStage("car-body")).toBe(false);
|
|
expect(fanavaranClaimStageUrl("car-body", "damage-case", 5023617)).toBeNull();
|
|
expect(fanavaranClaimStageUrl("car-body", "attachments", 5023617)).toBe(
|
|
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car/vehicle-hull-claims/5023617/files",
|
|
);
|
|
expect(fanavaranClaimStageUrl("car-body", "expertise", 5023617)).toBe(
|
|
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car/vehicle-hull-claims/5023617/expertise",
|
|
);
|
|
expect(fanavaranClaimStageUrl("third-party", "damage-case", 1)).toBe(
|
|
"https://apimanager.iraneit.com/BimeApiManager/api/BimeApi/v2.0/car/third-party-car-financial-claims/1/dmg-cases",
|
|
);
|
|
});
|
|
|
|
it("allows Fanavaran submit for both car products", () => {
|
|
expect(isFanavaranSubmitSupportedBlameType("THIRD_PARTY")).toBe(true);
|
|
expect(isFanavaranSubmitSupportedBlameType("CAR_BODY")).toBe(true);
|
|
expect(isFanavaranSubmitSupportedBlameType("OTHER")).toBe(false);
|
|
});
|
|
|
|
it("reuses the car-body inquiry PolicyId without another policy list call", () => {
|
|
const policyId = pickStoredCarBodyPolicyId({
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
insurance: { carBodyInsurance: { policyId: 15292336 } },
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(policyId).toBe(15292336);
|
|
});
|
|
|
|
it("reads PolicyId from nested car-body inquiry raw when the flat field is missing", () => {
|
|
const policyId = pickStoredCarBodyPolicyId({
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
vehicle: {
|
|
inquiry: {
|
|
carBody: {
|
|
mapped: {},
|
|
raw: { policyId: "15292336", policy: { PolicyId: 99 } },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(policyId).toBe(15292336);
|
|
});
|
|
|
|
it("uses the first-party car-body policyholder national code", () => {
|
|
const nationalCode = pickCarBodyPolicyNationalCode({
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
person: { nationalCodeOfInsurer: "0012345678" },
|
|
insurance: {
|
|
carBodyInsurance: { ownerNationalCode: "0098765432" },
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(nationalCode).toBe("0012345678");
|
|
});
|
|
|
|
it("flattens car-body inquiry fields onto the damage-case aliases", () => {
|
|
const { mapped } = fanavaranPartyInquirySources("car-body", {
|
|
insurance: {
|
|
carBodyInsurance: {
|
|
policyNumber: "70019846985",
|
|
chassisNumber: "IRNKAEK4150012345",
|
|
},
|
|
},
|
|
vehicle: {
|
|
inquiry: {
|
|
carBody: {
|
|
mapped: {
|
|
policyId: 15292336,
|
|
policyNumber: "70019846985",
|
|
chassisNumber: "IRNKAEK4150012345",
|
|
motorNumber: "M123",
|
|
vin: "IRNKAEK4150012345",
|
|
StartDate: "1405/05/18",
|
|
EndDate: "1406/05/18",
|
|
builtYear: 1402,
|
|
platePartOne: "29",
|
|
plateLetterTitle: "د",
|
|
platePartThree: "782",
|
|
plateSerialNumber: "44",
|
|
},
|
|
raw: {
|
|
policy: { CINumber: "70019846985" },
|
|
vehicle: { ChassisNo: "IRNKAEK4150012345" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(mapped.policyId).toBe(15292336);
|
|
expect(mapped.PrntCmpDocNo).toBe("70019846985");
|
|
expect(mapped.ShsNum).toBe("IRNKAEK4150012345");
|
|
expect(mapped.MtrNum).toBe("M123");
|
|
expect(mapped.VIN).toBe("IRNKAEK4150012345");
|
|
expect(mapped.HBgnDte).toBe("1405/05/18");
|
|
expect(mapped.HEndDte).toBe("1406/05/18");
|
|
expect(mapped.PrdDte).toBe(1402);
|
|
expect(mapped.plk1).toBe("29");
|
|
expect(mapped.plk2).toBe("د");
|
|
expect(mapped.plk3).toBe("782");
|
|
expect(mapped.plksrl).toBe("44");
|
|
});
|
|
});
|