From 55da8188a9914471a2550bab78ea65343bbf7980 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Tue, 8 Sep 2026 14:51:51 +0330 Subject: [PATCH] YARA-1267, YARA-1268 --- .../claim-request-management.controller.ts | 17 +++++--- src/sand-hub/sand-hub.service.spec.ts | 24 +++++++++++ src/sand-hub/sand-hub.service.ts | 43 +++++++++++-------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/claim-request-management/claim-request-management.controller.ts b/src/claim-request-management/claim-request-management.controller.ts index a9d37e1..a00e6c7 100644 --- a/src/claim-request-management/claim-request-management.controller.ts +++ b/src/claim-request-management/claim-request-management.controller.ts @@ -481,12 +481,17 @@ export class ClaimRequestManagementController { ); } - // @ApiOperation({ deprecated: true }) - @Get("branches/:insuranceId") - // @ApiParam({ name: "insuranceId" }) - async insuranceBranches(@Param("insuranceId") insuranceId: string) { - return await this.claimRequestManagementService.retrieveInsuranceBranches(insuranceId); - } + // Legacy V1 owner branch picker — intentionally disabled. + // A claim is handled by an expert assigned to the insurer branch, so the + // owner must not choose an insurer branch while signing. This does not apply + // to the separate expert-only `daghi.branchId` choice in pricing flows. + // + // @Get("branches/:insuranceId") + // async insuranceBranches(@Param("insuranceId") insuranceId: string) { + // return await this.claimRequestManagementService.retrieveInsuranceBranches( + // insuranceId, + // ); + // } // @ApiOperation({ deprecated: true }) @Get("fanavaran-submit/:claimRequestId") diff --git a/src/sand-hub/sand-hub.service.spec.ts b/src/sand-hub/sand-hub.service.spec.ts index be19633..6710528 100644 --- a/src/sand-hub/sand-hub.service.spec.ts +++ b/src/sand-hub/sand-hub.service.spec.ts @@ -184,6 +184,11 @@ describe("SandHubService inquiry mocks", () => { it("does not accept a policy when CLIENT_ID is not configured", async () => { delete process.env.CLIENT_ID; + externalInquirySettings.isInquiryLive.mockResolvedValue(true); + jest.spyOn(service, "getTejaratCarBodyInquiry").mockResolvedValue({ + raw: { data: { companyId: "15" } }, + mapped: { companyId: "15", CompanyCode: "15" }, + }); await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf( ServiceUnavailableException, @@ -207,6 +212,7 @@ describe("SandHubService inquiry mocks", () => { it("rejects a CAR_BODY policy from another insurer on the Tejarat lookup route", async () => { process.env.CLIENT_ID = "15"; + externalInquirySettings.isInquiryLive.mockResolvedValue(true); jest.spyOn(service, "getTejaratCarBodyInquiry").mockResolvedValue({ raw: { data: { companyId: "8" } }, mapped: { companyId: "8", CompanyCode: "8" }, @@ -217,6 +223,24 @@ describe("SandHubService inquiry mocks", () => { ); }); + it("accepts a mocked Parsian CAR_BODY inquiry for the deployment client", async () => { + process.env.CLIENT_ID = "15"; + process.env.FANAVARAN_CLIENT = "parsian"; + externalInquirySettings.isInquiryLive.mockResolvedValue(false); + externalInquirySettings.getMockCompanyContext.mockResolvedValue({ + companyId: "15", + companyName: "بیمه سامان", + }); + + await expect(service.getCarBodyInquiry(userDetail)).resolves.toEqual( + expect.objectContaining({ + source: "ESG_CAR_BODY_INQUIRY", + mapped: expect.objectContaining({ companyId: 15 }), + }), + ); + expect(lookupsService.findLastProcessedCarPolicy).not.toHaveBeenCalled(); + }); + it("uses the processed CAR_BODY lookup when the active Fanavaran client is Parsian", async () => { process.env.FANAVARAN_CLIENT = "parsian"; externalInquirySettings.isInquiryLive.mockResolvedValue(true); diff --git a/src/sand-hub/sand-hub.service.ts b/src/sand-hub/sand-hub.service.ts index 40b0706..ce40108 100644 --- a/src/sand-hub/sand-hub.service.ts +++ b/src/sand-hub/sand-hub.service.ts @@ -931,7 +931,31 @@ export class SandHubService { raw: any; mapped: Record; }> { - if (!this.shouldUseParsianCarBodyLookup()) { + const useParsianCarBodyLookup = this.shouldUseParsianCarBodyLookup(); + const live = await this.isInquiryLive("carBodyPlate", options); + + if (!live) { + // Mock results are generated for the active deployment. They must not be + // treated as evidence of a real insurer and therefore do not go through + // the live-policy insurer gate. + const result = await this.getTejaratCarBodyInquiry( + userDetail as SandHubDetailDto, + options, + ); + return { + source: + typeof userDetail.plate === "string" + ? useParsianCarBodyLookup + ? "ESG_CAR_BODY_VIN_INQUIRY" + : "TEJARAT_CAR_BODY_VIN_INQUIRY" + : useParsianCarBodyLookup + ? "ESG_CAR_BODY_INQUIRY" + : "TEJARAT_CAR_BODY_INQUIRY", + ...result, + }; + } + + if (!useParsianCarBodyLookup) { const result = await this.getTejaratCarBodyInquiry( userDetail as SandHubDetailDto, options, @@ -946,23 +970,6 @@ export class SandHubService { }; } - const live = await this.isInquiryLive("carBodyPlate", options); - if (!live) { - // Reuse the established local mock contract without sending an HTTP request. - const result = await this.getTejaratCarBodyInquiry( - userDetail as SandHubDetailDto, - options, - ); - this.assertParsianCarBodyLookupMatchesDeployment(); - return { - source: - typeof userDetail.plate === "string" - ? "ESG_CAR_BODY_VIN_INQUIRY" - : "ESG_CAR_BODY_INQUIRY", - ...result, - }; - } - const plateOrVin = userDetail.plate; const query = typeof plateOrVin === "string"