fix: align inquiry errors and expert review rules

This commit is contained in:
SepehrYahyaee
2026-09-19 12:11:43 +03:30
parent 45e0ad883a
commit 406b139b3d
21 changed files with 457 additions and 55 deletions

View File

@@ -495,6 +495,26 @@ describe("inquiry participant resolver", () => {
});
});
it("preserves a mapped provider message when the current result is unusable", async () => {
const currentPlate = {
leftDigits: "44",
centerAlphabet: "ب",
centerDigits: "111",
ir: "22",
};
await expect(
runCurrentPlateInquiry({
currentPlate,
query: async () => ({
mapped: { Error: { Message: "رکوردی یافت نشد" } },
}),
isUsable: () => false,
errorMessage: (value) => value.mapped.Error.Message,
}),
).rejects.toThrow("رکوردی یافت نشد");
});
it("retains one failed current-plate attempt after a provider outage", async () => {
const currentPlate = {
leftDigits: "44",

View File

@@ -446,6 +446,7 @@ export async function runCurrentPlateInquiry<T>(options: {
vin?: string;
query: (plate: InquiryVehicleInputDto["currentPlate"]) => Promise<T>;
isUsable: (value: T) => boolean;
errorMessage?: (value: T) => string | undefined;
}): Promise<{
value: T;
plateKind: "CURRENT";
@@ -479,7 +480,8 @@ export async function runCurrentPlateInquiry<T>(options: {
usable: false,
});
const error = new BadRequestException(
"بیمه‌نامه معتبر و فعالی مطابق مشخصات خودرو و کد ملی واردشده یافت نشد.",
options.errorMessage?.(value) ||
"بیمه‌نامه معتبر و فعالی مطابق مشخصات خودرو و کد ملی واردشده یافت نشد.",
) as BadRequestException & { attempts?: typeof attempts };
error.attempts = attempts;
throw error;

View File

@@ -78,6 +78,34 @@ describe("RequestManagementService policyholder inquiry routing", () => {
);
});
it("propagates the mapped ESG Persian error for third-party insurance", async () => {
const service = Object.create(RequestManagementService.prototype) as any;
service.sandHubService = {
getTejaratBlockInquiry: jest.fn().mockResolvedValue({
raw: {
success: false,
error: {
code: "RECORD_NOT_FOUND",
message: "Provider request failed",
messageFa: "رکوردی یافت نشد",
},
},
mapped: { Error: { Message: "رکوردی یافت نشد" } },
}),
};
const submission = service.normalizeInquiryInput(
BlameRequestType.THIRD_PARTY,
participantInput(BlameRequestType.THIRD_PARTY),
);
await expect(
service.getThirdPartyPlateInquiry(submission),
).rejects.toThrow("رکوردی یافت نشد");
expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledTimes(
1,
);
});
it("does not fall back from the current plate for car-body insurance", async () => {
const service = Object.create(RequestManagementService.prototype) as any;
service.sandHubService = {

View File

@@ -147,6 +147,13 @@ import {
getInquiryErrorMessage,
} from "src/common/utils/inquiry-error";
function mappedInquiryErrorMessage(value: any): string | undefined {
const message = value?.mapped?.Error?.Message;
return typeof message === "string" && message.trim()
? message.trim()
: undefined;
}
/**
* Formats a compact Jalali date (number or string like 13780624) as YYYY/MM/DD.
* Returns the original value as a string if it cannot be parsed.
@@ -401,6 +408,7 @@ export class RequestManagementService {
!value?.mapped?.Error &&
!!value?.mapped?.CompanyName &&
isMappedPolicyCurrent(value.mapped),
errorMessage: mappedInquiryErrorMessage,
});
return {
...result.value,
@@ -435,6 +443,7 @@ export class RequestManagementService {
value.mapped.CompanyName ||
value.mapped.companyId
),
errorMessage: mappedInquiryErrorMessage,
});
return {
...result.value,