fixed default values

This commit is contained in:
2026-09-07 17:15:41 +03:30
parent 3635dc2c10
commit f98712ba83
3 changed files with 46 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import {
collectPartyVinCandidates,
fanavaranIdOrConfigDefault,
filterPoliciesByLine,
insuranceLineLabel,
parseLastCarPolicyInput,
@@ -172,6 +173,12 @@ describe("fanavaran last car policy", () => {
});
});
it("uses tenant config default when the API id is missing", () => {
expect(fanavaranIdOrConfigDefault(15, 8)).toBe(15);
expect(fanavaranIdOrConfigDefault(null, 8)).toBe(8);
expect(fanavaranIdOrConfigDefault(0, 10)).toBe(10);
});
it("matches VIN against ChassisNo when VIN is empty", () => {
expect(
vehicleMatchesCar(

View File

@@ -162,6 +162,14 @@ export function parseFanavaranId(value: unknown): number | null {
return Number.isFinite(id) && id > 0 ? id : null;
}
/** Live Fanavaran / cache id wins; tenant `fanavaranClientConfigs.defaults` if the API returned nothing. */
export function fanavaranIdOrConfigDefault(
resolved: unknown,
configDefault: number,
): number {
return parseFanavaranId(resolved) ?? configDefault;
}
export function asObjectRecord(value: unknown): Record<string, unknown> | null {
if (!value || typeof value !== "object") {
return null;