Map Fanavaran people and licences by party role; allow unlisted base-info lookups.

Resolve driver, owner, and policyholder from participants when they differ, prefer real licence / driverLicenseDate over dummies, and fall back unknown /lookups/fanavaran/{name} to car/base-info/{name} (including vehicle-groups).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-26 16:57:30 +03:30
co-authored by Cursor
parent 4f8fe04380
commit fc1c117b93
9 changed files with 590 additions and 44 deletions
@@ -0,0 +1,125 @@
import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto";
import {
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
formatFanavaranLicenceIssuDate,
resolveDriverFromParty,
resolveDriverIsOwner,
resolveFanavaranLicenceIssuDate,
resolveFanavaranLicenceNo,
resolveOwnerFromParty,
resolvePolicyholderFromParty,
} 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,
);
});
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("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");
});
});