forked from Yara724/api
fix: return inquiry-specific Persian not-found messages
This commit is contained in:
@@ -4,13 +4,13 @@ import {
|
|||||||
} from "./inquiry-error";
|
} from "./inquiry-error";
|
||||||
|
|
||||||
describe("inquiry error messages", () => {
|
describe("inquiry error messages", () => {
|
||||||
it("preserves a Persian ESG not-found response", () => {
|
it("contextualizes a Persian ESG not-found response", () => {
|
||||||
expect(
|
expect(
|
||||||
getInquiryErrorMessage(
|
getInquiryErrorMessage(
|
||||||
{ success: false, message: "موردی یافت نشد" },
|
{ success: false, message: "موردی یافت نشد" },
|
||||||
"thirdPartyPlate",
|
"thirdPartyPlate",
|
||||||
),
|
),
|
||||||
).toBe("موردی یافت نشد");
|
).toBe("بیمهنامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
@@ -21,7 +21,7 @@ describe("inquiry error messages", () => {
|
|||||||
"Inquiry returned no matching result",
|
"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) => {
|
(code, messageFa, message) => {
|
||||||
expect(
|
expect(
|
||||||
getInquiryErrorMessage(
|
getInquiryErrorMessage(
|
||||||
@@ -39,7 +39,7 @@ describe("inquiry error messages", () => {
|
|||||||
},
|
},
|
||||||
"thirdPartyPlate",
|
"thirdPartyPlate",
|
||||||
),
|
),
|
||||||
).toBe(messageFa);
|
).toBe("بیمهنامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ describe("inquiry error messages", () => {
|
|||||||
},
|
},
|
||||||
"thirdPartyPlate",
|
"thirdPartyPlate",
|
||||||
),
|
),
|
||||||
).toBe("رکوردی یافت نشد");
|
).toBe("بیمهنامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("distinguishes VIN and car-body not-found failures", () => {
|
it("distinguishes VIN and car-body not-found failures", () => {
|
||||||
@@ -75,6 +75,51 @@ describe("inquiry error messages", () => {
|
|||||||
).toBe("بیمهنامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد.");
|
).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", () => {
|
it("preserves a specific Persian provider message", () => {
|
||||||
expect(
|
expect(
|
||||||
getInquiryErrorMessage(
|
getInquiryErrorMessage(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const NOT_FOUND_MESSAGES: Record<InquiryErrorContext, string> = {
|
|||||||
carBodyPlate: "بیمهنامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد.",
|
carBodyPlate: "بیمهنامه بدنه فعالی مطابق پلاک و کد ملی واردشده یافت نشد.",
|
||||||
carBodyVin:
|
carBodyVin:
|
||||||
"بیمهنامه بدنه فعالی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.",
|
"بیمهنامه بدنه فعالی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.",
|
||||||
personalIdentity: "اطلاعات هویتی مطابق کد ملی و تاریخ تولد واردشده یافت نشد.",
|
personalIdentity: "استعلام مشخصات هویتی یافت نشد",
|
||||||
drivingLicense:
|
drivingLicense:
|
||||||
"گواهینامهای مطابق کد ملی و شماره گواهینامه واردشده یافت نشد.",
|
"گواهینامهای مطابق کد ملی و شماره گواهینامه واردشده یافت نشد.",
|
||||||
carOwnership: "مالکیتی مطابق پلاک و کد ملی واردشده یافت نشد.",
|
carOwnership: "مالکیتی مطابق پلاک و کد ملی واردشده یافت نشد.",
|
||||||
@@ -201,13 +201,13 @@ export function getInquiryErrorMessage(
|
|||||||
): string {
|
): string {
|
||||||
const providerMessage = extractInquiryProviderMessage(error);
|
const providerMessage = extractInquiryProviderMessage(error);
|
||||||
|
|
||||||
// Persian text supplied by the provider is already the intended client
|
// Providers use the same generic Persian not-found text for every inquiry.
|
||||||
// message. Preserve it verbatim instead of replacing it with a local
|
// Resolve that failure using the caller's context before preserving other
|
||||||
// contextual fallback such as "inquiry not found".
|
// Persian messages (for example, specific input validation details).
|
||||||
if (providerMessage && hasPersian(providerMessage)) return providerMessage;
|
|
||||||
|
|
||||||
if (isNotFound(error, providerMessage)) return NOT_FOUND_MESSAGES[context];
|
if (isNotFound(error, providerMessage)) return NOT_FOUND_MESSAGES[context];
|
||||||
|
|
||||||
|
if (providerMessage && hasPersian(providerMessage)) return providerMessage;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
context === "carOwnership" &&
|
context === "carOwnership" &&
|
||||||
/not the owner|مالک.*نیست/i.test(providerMessage)
|
/not the owner|مالک.*نیست/i.test(providerMessage)
|
||||||
|
|||||||
@@ -256,9 +256,7 @@ export class InquiryRefreshService {
|
|||||||
inquiriesChanged = true;
|
inquiriesChanged = true;
|
||||||
result.thirdParty = {
|
result.thirdParty = {
|
||||||
ok: false,
|
ok: false,
|
||||||
message:
|
message: getInquiryErrorMessage(inquiry.mapped, "thirdPartyPlate"),
|
||||||
inquiry.mapped.Error.Message ||
|
|
||||||
getInquiryErrorMessage(inquiry.mapped, "thirdPartyPlate"),
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
nextParty = this.applyThirdPartyToParty(
|
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;
|
const service = Object.create(RequestManagementService.prototype) as any;
|
||||||
service.sandHubService = {
|
service.sandHubService = {
|
||||||
getTejaratBlockInquiry: jest.fn().mockResolvedValue({
|
getTejaratBlockInquiry: jest.fn().mockResolvedValue({
|
||||||
@@ -99,9 +99,9 @@ describe("RequestManagementService policyholder inquiry routing", () => {
|
|||||||
participantInput(BlameRequestType.THIRD_PARTY),
|
participantInput(BlameRequestType.THIRD_PARTY),
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(service.getThirdPartyPlateInquiry(submission)).rejects.toThrow(
|
||||||
service.getThirdPartyPlateInquiry(submission),
|
"بیمهنامه شخص ثالثی مطابق پلاک و کد ملی واردشده یافت نشد.",
|
||||||
).rejects.toThrow("رکوردی یافت نشد");
|
);
|
||||||
expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledTimes(
|
expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledTimes(
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -147,10 +147,13 @@ import {
|
|||||||
sanitizeStoredInquiryParticipants,
|
sanitizeStoredInquiryParticipants,
|
||||||
} from "./inquiry-participant-resolver";
|
} 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;
|
const message = value?.mapped?.Error?.Message;
|
||||||
return typeof message === "string" && message.trim()
|
return typeof message === "string" && message.trim()
|
||||||
? message.trim()
|
? getInquiryErrorMessage(value.mapped, context)
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +437,7 @@ export class RequestManagementService {
|
|||||||
!value?.mapped?.Error &&
|
!value?.mapped?.Error &&
|
||||||
!!value?.mapped?.CompanyName &&
|
!!value?.mapped?.CompanyName &&
|
||||||
isMappedPolicyCurrent(value.mapped),
|
isMappedPolicyCurrent(value.mapped),
|
||||||
errorMessage: mappedInquiryErrorMessage,
|
errorMessage: (value) => mappedInquiryErrorMessage(value, "thirdPartyPlate"),
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...result.value,
|
...result.value,
|
||||||
@@ -469,7 +472,7 @@ export class RequestManagementService {
|
|||||||
value.mapped.CompanyName ||
|
value.mapped.CompanyName ||
|
||||||
value.mapped.companyId
|
value.mapped.companyId
|
||||||
),
|
),
|
||||||
errorMessage: mappedInquiryErrorMessage,
|
errorMessage: (value) => mappedInquiryErrorMessage(value, "carBodyPlate"),
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...result.value,
|
...result.value,
|
||||||
@@ -1944,8 +1947,7 @@ export class RequestManagementService {
|
|||||||
});
|
});
|
||||||
await this.persistBlameInquiryAudit(req);
|
await this.persistBlameInquiryAudit(req);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
inquiryMapped.Error.Message ||
|
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
|
||||||
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
|
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2369,8 +2371,7 @@ export class RequestManagementService {
|
|||||||
});
|
});
|
||||||
await this.persistBlameInquiryAudit(req);
|
await this.persistBlameInquiryAudit(req);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
inquiryMapped.Error.Message ||
|
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
|
||||||
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
|
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6771,8 +6772,7 @@ export class RequestManagementService {
|
|||||||
|
|
||||||
if (inquiryMapped?.Error) {
|
if (inquiryMapped?.Error) {
|
||||||
const error = new BadRequestException(
|
const error = new BadRequestException(
|
||||||
inquiryMapped.Error.Message ||
|
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
|
||||||
getInquiryErrorMessage(inquiryMapped, "thirdPartyPlate"),
|
|
||||||
);
|
);
|
||||||
this.recordPartyCaseInquiryStatus(
|
this.recordPartyCaseInquiryStatus(
|
||||||
req,
|
req,
|
||||||
@@ -7693,8 +7693,7 @@ export class RequestManagementService {
|
|||||||
|
|
||||||
if (inquiryMapped?.Error) {
|
if (inquiryMapped?.Error) {
|
||||||
const error = new BadRequestException(
|
const error = new BadRequestException(
|
||||||
inquiryMapped.Error.Message ||
|
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
|
||||||
getInquiryErrorMessage(inquiryMapped, "thirdPartyVin"),
|
|
||||||
);
|
);
|
||||||
this.recordPartyCaseInquiryStatus(
|
this.recordPartyCaseInquiryStatus(
|
||||||
req,
|
req,
|
||||||
|
|||||||
@@ -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";
|
process.env.CLIENT_ID = "8";
|
||||||
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||||
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
|
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
|
||||||
@@ -199,10 +220,12 @@ describe("SandHubService inquiry mocks", () => {
|
|||||||
enforceDeploymentClientMatch: true,
|
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);
|
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||||
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
|
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -221,7 +244,7 @@ describe("SandHubService inquiry mocks", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.mapped.Error.Message).toBe(
|
expect(result.mapped.Error.Message).toBe(
|
||||||
"نتیجهای مطابق با اطلاعات وارد شده یافت نشد",
|
"بیمهنامه شخص ثالثی مطابق شماره شاسی (VIN) و کد ملی واردشده یافت نشد.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user