From 7e3b308572d712cd893f2ca7c01be79c2036863f Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Mon, 7 Sep 2026 13:08:23 +0330 Subject: [PATCH] Fixed car body inquiry --- .../lookups.service.last-car-policy.spec.ts | 39 +++++++++++++++++++ src/lookups/lookups.service.ts | 14 +++++++ 2 files changed, 53 insertions(+) diff --git a/src/lookups/lookups.service.last-car-policy.spec.ts b/src/lookups/lookups.service.last-car-policy.spec.ts index e407d27..76b58e6 100644 --- a/src/lookups/lookups.service.last-car-policy.spec.ts +++ b/src/lookups/lookups.service.last-car-policy.spec.ts @@ -135,6 +135,45 @@ describe("LookupsService.findLastProcessedCarPolicy", () => { expect(lookup.inquiryByVin).not.toHaveBeenCalled(); }); + it("rejects an expired car-body policy instead of treating it as active coverage", async () => { + const lookup = { + myPolicies: jest.fn().mockResolvedValue([ + { + PolicyId: 44, + InsuranceLineId: 4, + BeginDate: "1400/01/01", + EndDate: "1401/01/01", + }, + ]), + inquiryByVin: jest.fn(), + bodyPolicyById: jest.fn().mockResolvedValue({ + PolicyId: 44, + VehicleId: 8, + BeginDate: "1400/01/01", + EndDate: "1401/01/01", + }), + vehicleById: jest.fn().mockResolvedValue({ + Id: 8, + PlaqueLeftNo: "12", + PlaqueMiddleCodeId: 2, + PlaqueRightNo: "345", + PlaqueSerial: "67", + }), + getRemoteLookup: jest.fn().mockResolvedValue([]), + customerById: jest.fn().mockResolvedValue(null), + }; + + await expect( + createService(lookup).findLastProcessedCarPolicy("car-body", { + nationalCode: "0012345678", + plaqueLeft: "12", + plaqueLetter: "ب", + plaqueRight: "345", + plaqueSerial: "67", + }), + ).rejects.toBeInstanceOf(NotFoundException); + }); + it("accepts the policy when VIN inquiry VehicleId matches and GEN.15 VIN is empty", async () => { const lookup = { myPolicies: jest.fn().mockResolvedValue([ diff --git a/src/lookups/lookups.service.ts b/src/lookups/lookups.service.ts index 35e0eb0..b532cc8 100644 --- a/src/lookups/lookups.service.ts +++ b/src/lookups/lookups.service.ts @@ -20,6 +20,7 @@ import { filterPoliciesByLine, insuranceLineIdForProduct, insuranceLineLabel, + isPolicyActiveOn, parseFanavaranId, parseLastCarPolicyInput, pickVehicleId, @@ -30,6 +31,7 @@ import { type FanavaranCarPolicyProduct, type HydratedFanavaranCarPolicy, } from "./fanavaran-last-car-policy"; +import { gregorianDateInIran } from "src/helpers/iran-datetime"; type TejaratAccidentReasonRow = { id: number; @@ -357,6 +359,18 @@ export class LookupsService { ); } + // A CAR_BODY case is payable only with current hull coverage. The generic + // selector may intentionally return the latest expired policy for history; + // that fallback is not valid for a new CAR_BODY case. + if ( + product === "car-body" && + !isPolicyActiveOn(selected, gregorianDateInIran(new Date())) + ) { + throw new NotFoundException( + "No active Fanavaran car-body policy was found for this car.", + ); + } + return { product, insuranceLine: insuranceLineLabel(insuranceLineId),