forked from Yara724/api
77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import {
|
|
asPartyInquiryRows,
|
|
collectPersonNationalCodes,
|
|
parseJalaliDateParts,
|
|
pickPersonBirthday,
|
|
pickPersonNationalCode,
|
|
selectFanavaranDriverId,
|
|
} from "./fanavaran-driver-inquiry";
|
|
|
|
describe("selectFanavaranDriverId", () => {
|
|
const rows = [
|
|
{ Id: 10, RoleId: 161, Name: "insurer" },
|
|
{ Id: 20, RoleId: 166, Name: "driver" },
|
|
];
|
|
|
|
it("prefers insurer role 161 when the driver is the owner", () => {
|
|
expect(selectFanavaranDriverId(rows, true)).toBe(10);
|
|
});
|
|
|
|
it("prefers driver role 166 when the driver is not the owner", () => {
|
|
expect(selectFanavaranDriverId(rows, false)).toBe(20);
|
|
});
|
|
|
|
it("uses the other role when the preferred role is missing", () => {
|
|
expect(selectFanavaranDriverId([{ Id: 20, RoleId: 166 }], true)).toBe(20);
|
|
});
|
|
|
|
it("picks 4773521 from a real Fanavaran unique-identifier response", () => {
|
|
expect(
|
|
selectFanavaranDriverId(
|
|
[
|
|
{ Id: 4773521, RoleId: 161 },
|
|
{ Id: 4773521, RoleId: 163 },
|
|
{ Id: 4773521, RoleId: 166 },
|
|
],
|
|
true,
|
|
),
|
|
).toBe(4773521);
|
|
});
|
|
});
|
|
|
|
describe("pickPersonNationalCode / birthday", () => {
|
|
it("uses insurer national code when driverIsInsurer", () => {
|
|
expect(
|
|
pickPersonNationalCode({
|
|
driverIsInsurer: true,
|
|
nationalCodeOfInsurer: "0012345678",
|
|
nationalCodeOfDriver: "",
|
|
}),
|
|
).toBe("0012345678");
|
|
});
|
|
|
|
it("falls back across birthday fields", () => {
|
|
expect(
|
|
pickPersonBirthday({
|
|
driverBirthday: null,
|
|
birthday: "13480313",
|
|
}),
|
|
).toBe("13480313");
|
|
});
|
|
});
|
|
|
|
describe("asPartyInquiryRows", () => {
|
|
it("normalizes Persian digits and compact insurer birthday 13640628", () => {
|
|
expect(
|
|
collectPersonNationalCodes({
|
|
nationalCodeOfInsurer: "۰۰۸۰۰۸۶۵۱۹",
|
|
}),
|
|
).toEqual(["0080086519"]);
|
|
expect(parseJalaliDateParts(13640628)).toEqual({
|
|
year: 1364,
|
|
month: 6,
|
|
day: 28,
|
|
});
|
|
});
|
|
});
|