fix: return inquiry-specific Persian not-found messages

This commit is contained in:
2026-11-18 12:31:44 +03:30
parent 7631a94071
commit 2cdbc35d2e
6 changed files with 99 additions and 34 deletions
+50 -5
View File
@@ -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(
+6 -6
View File
@@ -18,7 +18,7 @@ const NOT_FOUND_MESSAGES: Record<InquiryErrorContext, string> = {
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)
@@ -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(
@@ -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,
);
@@ -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,7 +1947,6 @@ export class RequestManagementService {
});
await this.persistBlameInquiryAudit(req);
throw new HttpException(
inquiryMapped.Error.Message ||
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
HttpStatus.BAD_REQUEST,
);
@@ -2369,7 +2371,6 @@ export class RequestManagementService {
});
await this.persistBlameInquiryAudit(req);
throw new HttpException(
inquiryMapped.Error.Message ||
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
HttpStatus.BAD_REQUEST,
);
@@ -6771,7 +6772,6 @@ export class RequestManagementService {
if (inquiryMapped?.Error) {
const error = new BadRequestException(
inquiryMapped.Error.Message ||
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
);
this.recordPartyCaseInquiryStatus(
@@ -7693,7 +7693,6 @@ export class RequestManagementService {
if (inquiryMapped?.Error) {
const error = new BadRequestException(
inquiryMapped.Error.Message ||
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
);
this.recordPartyCaseInquiryStatus(
+27 -4
View File
@@ -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) و کد ملی واردشده یافت نشد.",
);
});