Files
yara724api/src/claim-request-management/fanavaran-party-roles.spec.ts
T
SepehrYahyaee a15c54d017 feat: route user claims by branch and align licence issue dates
Require the damaged party in user flows to select an active insurer branch and preserve branch access rules. Accept older licence issue dates, correct anniversary boundaries, and update Fanavaran audit documentation and regression coverage.
2026-11-14 12:24:14 +03:30

180 lines
5.4 KiB
TypeScript

import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto";
import {
FANAVARAN_CULPRIT_TYPE_DRIVER_NOT_INSURER,
FANAVARAN_CULPRIT_TYPE_INSURER,
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
formatFanavaranLicenceIssuDate,
resolveDriverFromParty,
resolveDriverIsOwner,
resolveFanavaranIsLicenseReplaced,
resolveFanavaranLicenceIssuDate,
resolveFanavaranLicenceNo,
resolveOwnerFromParty,
resolvePolicyholderFromParty,
resolveThirdPartyCulpritTypeId,
} from "./fanavaran-party-roles";
describe("fanavaran-party-roles", () => {
const partyWithDistinctRoles = {
participants: [
{
participantId: "DRIVER",
nationalCode: "0012345678",
birthday: "1370/01/15",
licenseNumber: "1234567890",
licenseType: "1",
driverLicenseDate: "1398/06/01",
},
{
participantId: "VEHICLE_OWNER",
nationalCode: "0499370899",
birthday: "1368/05/20",
},
{
participantId: "THIRD_PARTY_POLICYHOLDER",
nationalCode: "0080086519",
birthday: "1364/06/28",
},
],
participantRoles: {
driver: "DRIVER",
vehicleOwner: "VEHICLE_OWNER",
thirdPartyPolicyholder: "THIRD_PARTY_POLICYHOLDER",
},
person: {
nationalCodeOfDriver: "0012345678",
nationalCodeOfInsurer: "0080086519",
driverLicense: "1234567890",
driverIsInsurer: false,
},
};
it("resolves driver licence and driverLicenseDate from participants", () => {
const driver = resolveDriverFromParty(partyWithDistinctRoles);
expect(driver.nationalCode).toBe("0012345678");
expect(driver.licenseNo).toBe("1234567890");
expect(driver.licenseIssuDate).toBe("1398/06/01");
expect(resolveFanavaranLicenceNo(driver, "9705463515")).toBe("1234567890");
expect(resolveFanavaranLicenceIssuDate(driver)).toBe("1398/06/01");
});
it("falls back to dummy licence issue date when driverLicenseDate is missing", () => {
const driver = resolveDriverFromParty({
participants: [
{
participantId: InquiryParticipantRole.DRIVER,
nationalCode: "0012345678",
birthday: "1370/01/15",
licenseNumber: "999",
},
],
participantRoles: { driver: InquiryParticipantRole.DRIVER },
});
expect(driver.licenseIssuDate).toBeNull();
expect(resolveFanavaranLicenceIssuDate(driver)).toBe(
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
);
expect(FANAVARAN_DUMMY_LICENCE_ISSU_DATE).toBe("1400/01/01");
});
it("marks licence replaced only when issue date is more than 10 years before accident", () => {
expect(
resolveFanavaranIsLicenseReplaced("1394/10/13", "1405/08/20"),
).toBe(1);
expect(
resolveFanavaranIsLicenseReplaced("1401/08/02", "1405/08/20"),
).toBeNull();
expect(
resolveFanavaranIsLicenseReplaced("1404/08/20", "1405/08/20"),
).toBe(0);
});
it.each([
["1402/08/21", 0],
["1402/08/20", 0],
["1402/08/19", null],
["1395/08/21", null],
["1395/08/20", null],
["1395/08/19", 1],
["1380/08/20", 1],
])("uses the exact anniversary for issue date %s", (issueDate, expected) => {
expect(resolveFanavaranIsLicenseReplaced(issueDate, "1405/08/20")).toBe(expected);
});
it("marks DriverIsOwner false when driver and owner differ", () => {
expect(resolveDriverIsOwner(partyWithDistinctRoles)).toBe(false);
});
it("marks DriverIsOwner true when driver and owner share a national code", () => {
expect(
resolveDriverIsOwner({
participants: [
{
participantId: "SAME",
nationalCode: "0012345678",
birthday: "1370/01/15",
},
],
participantRoles: {
driver: "SAME",
vehicleOwner: "SAME",
thirdPartyPolicyholder: "SAME",
},
}),
).toBe(true);
});
it("resolves owner and policyholder independently of the driver", () => {
expect(resolveOwnerFromParty(partyWithDistinctRoles).nationalCode).toBe(
"0499370899",
);
expect(
resolvePolicyholderFromParty(partyWithDistinctRoles, "third-party")
.nationalCode,
).toBe("0080086519");
});
it("maps CulpritTypeId 338 when guilty driver ≠ insurer", () => {
expect(resolveThirdPartyCulpritTypeId(partyWithDistinctRoles)).toBe(
FANAVARAN_CULPRIT_TYPE_DRIVER_NOT_INSURER,
);
});
it("maps CulpritTypeId 337 when guilty driver is the insurer", () => {
expect(
resolveThirdPartyCulpritTypeId({
participants: [
{
participantId: "SAME",
nationalCode: "0080086519",
birthday: "1364/06/28",
},
],
participantRoles: {
driver: "SAME",
thirdPartyPolicyholder: "SAME",
},
person: { driverIsInsurer: true },
}),
).toBe(FANAVARAN_CULPRIT_TYPE_INSURER);
});
it("formats compact Jalali driverLicenseDate", () => {
expect(formatFanavaranLicenceIssuDate(13980601)).toBe("1398/06/01");
});
it("falls back to legacy person.driverLicense when participants are absent", () => {
const driver = resolveDriverFromParty({
person: {
nationalCodeOfDriver: "0011111111",
driverBirthday: "13700101",
driverLicense: "5555555555",
driverLicenseDate: "1390/01/01",
},
});
expect(driver.nationalCode).toBe("0011111111");
expect(driver.licenseNo).toBe("5555555555");
expect(driver.licenseIssuDate).toBe("1390/01/01");
});
});