forked from Yara724/api
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import {
|
|
asVehicleKindRows,
|
|
isVehicleKindsSyncStale,
|
|
normalizeVehicleKindCaptionSearch,
|
|
VEHICLE_KINDS_REFRESH_MS,
|
|
} from "./vehicle-kind-search";
|
|
|
|
describe("vehicle-kind-search", () => {
|
|
it("normalizes Arabic yeh/keheh so كاميون matches کامیون", () => {
|
|
expect(normalizeVehicleKindCaptionSearch("كاميون")).toBe(
|
|
normalizeVehicleKindCaptionSearch("کامیون"),
|
|
);
|
|
expect(normalizeVehicleKindCaptionSearch("ولوو")).toContain("ولوو");
|
|
});
|
|
|
|
it("treats missing or old syncedAt as stale after one week", () => {
|
|
expect(isVehicleKindsSyncStale(null)).toBe(true);
|
|
const now = new Date("2026-09-28T12:00:00Z");
|
|
expect(
|
|
isVehicleKindsSyncStale(
|
|
new Date("2026-09-20T12:00:00Z"),
|
|
now,
|
|
VEHICLE_KINDS_REFRESH_MS,
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
isVehicleKindsSyncStale(
|
|
new Date("2026-09-25T12:00:00Z"),
|
|
now,
|
|
VEHICLE_KINDS_REFRESH_MS,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("maps Fanavaran rows and drops invalid Ids", () => {
|
|
const rows = asVehicleKindRows([
|
|
{ Id: 6645, Caption: "کاميون کشنده ولوو FH12 4*2", IsActive: 1 },
|
|
{ Id: "bad", Caption: "x", IsActive: 1 },
|
|
{ Id: 1, Caption: "سایر", IsActive: 0 },
|
|
]);
|
|
expect(rows).toHaveLength(2);
|
|
expect(rows[0]).toMatchObject({
|
|
Id: 6645,
|
|
Caption: "کاميون کشنده ولوو FH12 4*2",
|
|
IsActive: 1,
|
|
});
|
|
expect(rows[1].IsActive).toBe(0);
|
|
});
|
|
});
|