From 2cdbc35d2ee7454b456b6836050598fed8ee0515 Mon Sep 17 00:00:00 2001 From: "s.hajizadeh" Date: Wed, 18 Nov 2026 12:31:44 +0330 Subject: [PATCH] fix: return inquiry-specific Persian not-found messages --- src/common/utils/inquiry-error.spec.ts | 55 +++++++++++++++++-- src/common/utils/inquiry-error.ts | 12 ++-- .../inquiry-refresh.service.ts | 4 +- ...st-management.policyholder-inquiry.spec.ts | 8 +-- .../request-management.service.ts | 23 ++++---- src/sand-hub/sand-hub.service.spec.ts | 31 +++++++++-- 6 files changed, 99 insertions(+), 34 deletions(-) diff --git a/src/common/utils/inquiry-error.spec.ts b/src/common/utils/inquiry-error.spec.ts index cce24da..2809fd0 100644 --- a/src/common/utils/inquiry-error.spec.ts +++ b/src/common/utils/inquiry-error.spec.ts @@ -4,13 +4,13 @@ import { } from "./inquiry-error"; describe("inquiry error messages", () => { - it("preserves a Persian ESG not-found response", () => { + it("contextualizes a Persian ESG not-found response", () => { expect( getInquiryErrorMessage( { success: false, message: "موردی یافت نشد" }, "thirdPartyPlate", ), - ).toBe("موردی یافت نشد"); + ).toBe("بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد."); }); it.each([ @@ -21,7 +21,7 @@ describe("inquiry error messages", () => { "Inquiry returned no matching result", ], ])( - "prefers ESG messageFa for %s over the technical message", + "contextualizes ESG %s even when messageFa is present", (code, messageFa, message) => { expect( getInquiryErrorMessage( @@ -39,7 +39,7 @@ describe("inquiry error messages", () => { }, "thirdPartyPlate", ), - ).toBe(messageFa); + ).toBe("بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد."); }, ); @@ -60,7 +60,7 @@ describe("inquiry error messages", () => { }, "thirdPartyPlate", ), - ).toBe("رکوردی یافت نشد"); + ).toBe("بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد."); }); it("distinguishes VIN and car-body not-found failures", () => { @@ -75,6 +75,51 @@ describe("inquiry error messages", () => { ).toBe("بیمه‌نامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد."); }); + it.each([ + [ + "thirdPartyPlate", + "بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.", + ], + [ + "thirdPartyVin", + "بیمه‌نامه شخص ثالثی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.", + ], + [ + "carBodyPlate", + "بیمه‌نامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد.", + ], + [ + "carBodyVin", + "بیمه‌نامه بدنه فعالی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.", + ], + ["personalIdentity", "استعلام مشخصات هویتی یافت نشد"], + [ + "drivingLicense", + "گواهینامه‌ای مطابق کد ملی و شماره گواهینامه واردشده یافت نشد.", + ], + ["carOwnership", "مالکیتی مطابق پلاک و کد ملی واردشده یافت نشد."], + ["sheba", "اطلاعاتی مطابق شماره شبا و کد ملی واردشده یافت نشد."], + ] as const)( + "uses the %s context for the same provider failure", + (context, expected) => { + expect( + getInquiryErrorMessage( + { + success: false, + data: null, + error: { + code: "RECORD_NOT_FOUND", + message: "Record not found", + messageFa: "رکوردی یافت نشد", + providerCode: "RECORD_NOT_FOUND", + }, + }, + context, + ), + ).toBe(expected); + }, + ); + it("preserves a specific Persian provider message", () => { expect( getInquiryErrorMessage( diff --git a/src/common/utils/inquiry-error.ts b/src/common/utils/inquiry-error.ts index 08ce261..7d2b6bb 100644 --- a/src/common/utils/inquiry-error.ts +++ b/src/common/utils/inquiry-error.ts @@ -18,7 +18,7 @@ const NOT_FOUND_MESSAGES: Record = { carBodyPlate: "بیمه‌نامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد.", carBodyVin: "بیمه‌نامه بدنه فعالی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.", - personalIdentity: "اطلاعات هویتی مطابق کد ملی و تاریخ تولد واردشده یافت نشد.", + personalIdentity: "استعلام مشخصات هویتی یافت نشد", drivingLicense: "گواهینامه‌ای مطابق کد ملی و شماره گواهینامه واردشده یافت نشد.", carOwnership: "مالکیتی مطابق پلاک و کد ملی واردشده یافت نشد.", @@ -201,13 +201,13 @@ export function getInquiryErrorMessage( ): string { const providerMessage = extractInquiryProviderMessage(error); - // Persian text supplied by the provider is already the intended client - // message. Preserve it verbatim instead of replacing it with a local - // contextual fallback such as "inquiry not found". - if (providerMessage && hasPersian(providerMessage)) return providerMessage; - + // Providers use the same generic Persian not-found text for every inquiry. + // Resolve that failure using the caller's context before preserving other + // Persian messages (for example, specific input validation details). if (isNotFound(error, providerMessage)) return NOT_FOUND_MESSAGES[context]; + if (providerMessage && hasPersian(providerMessage)) return providerMessage; + if ( context === "carOwnership" && /not the owner|مالک.*نیست/i.test(providerMessage) diff --git a/src/request-management/inquiry-refresh.service.ts b/src/request-management/inquiry-refresh.service.ts index e9e0776..5513466 100644 --- a/src/request-management/inquiry-refresh.service.ts +++ b/src/request-management/inquiry-refresh.service.ts @@ -256,9 +256,7 @@ export class InquiryRefreshService { inquiriesChanged = true; result.thirdParty = { ok: false, - message: - inquiry.mapped.Error.Message || - getInquiryErrorMessage(inquiry.mapped, "thirdPartyPlate"), + message: getInquiryErrorMessage(inquiry.mapped, "thirdPartyPlate"), }; } else { nextParty = this.applyThirdPartyToParty( diff --git a/src/request-management/request-management.policyholder-inquiry.spec.ts b/src/request-management/request-management.policyholder-inquiry.spec.ts index daefd17..dc9266f 100644 --- a/src/request-management/request-management.policyholder-inquiry.spec.ts +++ b/src/request-management/request-management.policyholder-inquiry.spec.ts @@ -79,7 +79,7 @@ describe("RequestManagementService policyholder inquiry routing", () => { ); }); - it("propagates the mapped ESG Persian error for third-party insurance", async () => { + it("contextualizes the mapped ESG not-found error for third-party insurance", async () => { const service = Object.create(RequestManagementService.prototype) as any; service.sandHubService = { getTejaratBlockInquiry: jest.fn().mockResolvedValue({ @@ -99,9 +99,9 @@ describe("RequestManagementService policyholder inquiry routing", () => { participantInput(BlameRequestType.THIRD_PARTY), ); - await expect( - service.getThirdPartyPlateInquiry(submission), - ).rejects.toThrow("رکوردی یافت نشد"); + await expect(service.getThirdPartyPlateInquiry(submission)).rejects.toThrow( + "بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.", + ); expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledTimes( 1, ); diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 6962258..1073543 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -147,10 +147,13 @@ import { sanitizeStoredInquiryParticipants, } from "./inquiry-participant-resolver"; -function mappedInquiryErrorMessage(value: any): string | undefined { +function mappedInquiryErrorMessage( + value: any, + context: "thirdPartyPlate" | "carBodyPlate", +): string | undefined { const message = value?.mapped?.Error?.Message; return typeof message === "string" && message.trim() - ? message.trim() + ? getInquiryErrorMessage(value.mapped, context) : undefined; } @@ -434,7 +437,7 @@ export class RequestManagementService { !value?.mapped?.Error && !!value?.mapped?.CompanyName && isMappedPolicyCurrent(value.mapped), - errorMessage: mappedInquiryErrorMessage, + errorMessage: (value) => mappedInquiryErrorMessage(value, "thirdPartyPlate"), }); return { ...result.value, @@ -469,7 +472,7 @@ export class RequestManagementService { value.mapped.CompanyName || value.mapped.companyId ), - errorMessage: mappedInquiryErrorMessage, + errorMessage: (value) => mappedInquiryErrorMessage(value, "carBodyPlate"), }); return { ...result.value, @@ -1944,8 +1947,7 @@ export class RequestManagementService { }); await this.persistBlameInquiryAudit(req); throw new HttpException( - inquiryMapped.Error.Message || - getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"), + getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"), HttpStatus.BAD_REQUEST, ); } @@ -2369,8 +2371,7 @@ export class RequestManagementService { }); await this.persistBlameInquiryAudit(req); throw new HttpException( - inquiryMapped.Error.Message || - getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"), + getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"), HttpStatus.BAD_REQUEST, ); } @@ -6771,8 +6772,7 @@ export class RequestManagementService { if (inquiryMapped?.Error) { const error = new BadRequestException( - inquiryMapped.Error.Message || - getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"), + getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"), ); this.recordPartyCaseInquiryStatus( req, @@ -7693,8 +7693,7 @@ export class RequestManagementService { if (inquiryMapped?.Error) { const error = new BadRequestException( - inquiryMapped.Error.Message || - getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"), + getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"), ); this.recordPartyCaseInquiryStatus( req, diff --git a/src/sand-hub/sand-hub.service.spec.ts b/src/sand-hub/sand-hub.service.spec.ts index 37bd395..82a5273 100644 --- a/src/sand-hub/sand-hub.service.spec.ts +++ b/src/sand-hub/sand-hub.service.spec.ts @@ -181,7 +181,28 @@ describe("SandHubService inquiry mocks", () => { ); }); - it("preserves ESG messageFa for a plate inquiry", async () => { + it("returns a contextual error for an ESG person inquiry with no match", async () => { + externalInquirySettings.isInquiryLive.mockResolvedValue(true); + jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({ + success: false, + provider: "PARSIAN", + trackingCode: "INQ-20261118-B5C117CC", + data: null, + error: { + code: "RECORD_NOT_FOUND", + message: "Record not found", + messageFa: "رکوردی یافت نشد", + providerMessage: "err.record.not.found", + providerCode: "RECORD_NOT_FOUND", + }, + }); + + await expect( + service.getPersonalInquiry("0012345678", "1370/01/01"), + ).rejects.toThrow("استعلام مشخصات هویتی یافت نشد"); + }); + + it("returns a contextual ESG not-found message for a plate inquiry", async () => { process.env.CLIENT_ID = "8"; externalInquirySettings.isInquiryLive.mockResolvedValue(true); jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({ @@ -199,10 +220,12 @@ describe("SandHubService inquiry mocks", () => { enforceDeploymentClientMatch: true, }); - expect(result.mapped.Error.Message).toBe("رکوردی یافت نشد"); + expect(result.mapped.Error.Message).toBe( + "بیمه‌نامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.", + ); }); - it("preserves ESG messageFa for a VIN inquiry", async () => { + it("returns a contextual ESG not-found message for a VIN inquiry", async () => { externalInquirySettings.isInquiryLive.mockResolvedValue(true); jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({ success: false, @@ -221,7 +244,7 @@ describe("SandHubService inquiry mocks", () => { }); expect(result.mapped.Error.Message).toBe( - "نتیجه‌ای مطابق با اطلاعات وارد شده یافت نشد", + "بیمه‌نامه شخص ثالثی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.", ); });