From 5b114c2069573a5fc3c305c00eb9ac49a0f6194d Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Sat, 18 Jul 2026 14:30:26 +0330 Subject: [PATCH] YARA-1061 --- .../inquiry-refresh.service.ts | 2 ++ src/sand-hub/sand-hub.service.spec.ts | 28 +++++++++++++++++++ src/sand-hub/sand-hub.service.ts | 11 +++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/request-management/inquiry-refresh.service.ts b/src/request-management/inquiry-refresh.service.ts index 3d94ab2..5353c37 100644 --- a/src/request-management/inquiry-refresh.service.ts +++ b/src/request-management/inquiry-refresh.service.ts @@ -368,6 +368,8 @@ export class InquiryRefreshService { next.insurance.policyNumber = mapped.PrntPlcyCmpDocNo || + mapped.printNumber || + mapped.insuranceNumber || next.insurance.policyNumber; next.insurance.company = mapped.companyPersianName || mapped.CompanyName || next.insurance.company; diff --git a/src/sand-hub/sand-hub.service.spec.ts b/src/sand-hub/sand-hub.service.spec.ts index 34dfda8..3e09e01 100644 --- a/src/sand-hub/sand-hub.service.spec.ts +++ b/src/sand-hub/sand-hub.service.spec.ts @@ -81,5 +81,33 @@ describe("SandHubService inquiry mocks", () => { expect(httpService.post).not.toHaveBeenCalled(); expect(result.mapped?.CompanyName).toBe("بیمه پارسیان"); expect(result.mapped?.CompanyCode).toBe("8"); + // PrntPlcyCmpDocNo must be populated from the mock raw field + expect(result.mapped?.PrntPlcyCmpDocNo).toBe("1404/1143-70591/200/123"); + }); + + it("maps printNumber → PrntPlcyCmpDocNo when raw response uses new field name", async () => { + // Simulate a real-API response where the policy number arrives as printNumber + const rawNewFormat = { + printNumber: "1405/1143-NEWAPI/200/1", + CompanyName: "بیمه آزمایشی", + CompanyCode: "99", + FinancialCvrCptl: "5000000000", + IssueDate: "1405/01/01", + EndDate: "1406/01/01", + }; + const mapped = (service as any).mapNewApiResponseToOldFormat(rawNewFormat); + + expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-NEWAPI/200/1"); + }); + + it("maps insuranceNumber → PrntPlcyCmpDocNo when raw response uses legacy field name", async () => { + const rawLegacy = { + insuranceNumber: "1405/1143-LEGACY/200/1", + CompanyName: "بیمه آزمایشی", + CompanyCode: "99", + }; + const mapped = (service as any).mapNewApiResponseToOldFormat(rawLegacy); + + expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-LEGACY/200/1"); }); }); diff --git a/src/sand-hub/sand-hub.service.ts b/src/sand-hub/sand-hub.service.ts index 9bad94b..a6f8b5e 100644 --- a/src/sand-hub/sand-hub.service.ts +++ b/src/sand-hub/sand-hub.service.ts @@ -1012,11 +1012,20 @@ export class SandHubService { IssueDate: newResponse.persianStartDate || newResponse.IssueDate, EndDate: newResponse.persianEndDate || newResponse.EndDate, + // Insurance policy number — canonical Tejarat name is PrntPlcyCmpDocNo; + // newer API formats surface it as printNumber or insuranceNumber. + PrntPlcyCmpDocNo: + newResponse.PrntPlcyCmpDocNo || + newResponse.printNumber || + newResponse.insuranceNumber || + null, + // Insurance details LastCompanyDocumentNumber: newResponse.lastCompanyInsuranceNumber || newResponse.LastCompanyDocumentNumber || - newResponse.insuranceNumber, + newResponse.insuranceNumber || + null, // Technical details MtrNum: newResponse.MtrNum || newResponse.mtrnum,