fix inquiry integration and insurer case details

This commit is contained in:
SepehrYahyaee
2026-09-19 16:06:04 +03:30
parent cd36a0f2d4
commit 8071215803
18 changed files with 141 additions and 167 deletions

View File

@@ -114,7 +114,7 @@ export class CallCenterBlameV6Controller {
description:
"VIN alternative to `run-inquiry`. " +
"The agent supplies the chassis number and personal data collected from the caller. " +
"ESG chassis lookup (`policyByChassis`) is executed and the result is stored on the " +
"ESG two-factor chassis lookup (`carByChassis`) is executed and the result is stored on the " +
"blame document under `vehicle.vin` (plateId is left empty). " +
"Identical eligibility guards and insurer-company validation as the plate variant. " +
"After this call, proceed to `send-link` exactly as in the plate flow.",

View File

@@ -1,4 +1,5 @@
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
import { PartyRole } from "./entities/schema/partyRole.enum";
import { RequestManagementService } from "./request-management.service";
describe("RequestManagementService policyholder inquiry routing", () => {
@@ -138,7 +139,7 @@ describe("RequestManagementService policyholder inquiry routing", () => {
it("queries VIN with the third-party policyholder", async () => {
const service = Object.create(RequestManagementService.prototype) as any;
service.sandHubService = {
getPolicyByChassisInquiry: jest.fn().mockResolvedValue({
getCarByChassisInquiry: jest.fn().mockResolvedValue({
raw: {},
mapped: { CompanyName: "پارسیان" },
}),
@@ -151,10 +152,10 @@ describe("RequestManagementService policyholder inquiry routing", () => {
await service.getThirdPartyVinInquiry(submission);
expect(
service.sandHubService.getPolicyByChassisInquiry,
service.sandHubService.getCarByChassisInquiry,
).toHaveBeenCalledTimes(1);
expect(
service.sandHubService.getPolicyByChassisInquiry,
service.sandHubService.getCarByChassisInquiry,
).toHaveBeenCalledWith(
{
nationalCode: "0022222222",
@@ -163,4 +164,62 @@ describe("RequestManagementService policyholder inquiry routing", () => {
undefined,
);
});
it("runs both third-party and car-body inquiries for a car-body VIN", async () => {
const service = Object.create(RequestManagementService.prototype) as any;
service.getThirdPartyVinInquiry = jest.fn().mockResolvedValue({
raw: { success: true },
mapped: {
CompanyCode: "8",
CompanyName: "بیمه پارسیان",
PrntPlcyCmpDocNo: "TP-1",
},
});
service.sandHubService = {
getCarBodyInquiry: jest.fn().mockResolvedValue({
source: "ESG_CAR_BODY_VIN_INQUIRY",
raw: { policyId: 123 },
mapped: {
policyNumber: "BODY-1",
companyId: "8",
CompanyName: "بیمه پارسیان",
VinNumberField: vehicle.vin,
},
}),
};
service.clientService = {
findOrCreateClientByCompanyCode: jest
.fn()
.mockResolvedValue({ _id: "client-third-party" }),
};
service.resolveCarBodyPolicyClientId = jest
.fn()
.mockResolvedValue("client-car-body");
service.runParticipantPersonalInquiries = jest.fn().mockResolvedValue(undefined);
service.runVehicleOwnershipInquiry = jest.fn().mockResolvedValue(undefined);
const req: any = {
_id: "car-body-vin-request",
type: BlameRequestType.CAR_BODY,
inquiries: {},
};
const party: any = { person: {}, vehicle: {}, insurance: {} };
await service.runPartyInquiriesVinV3Internal(
req,
participantInput(BlameRequestType.CAR_BODY),
PartyRole.FIRST,
party,
);
expect(service.getThirdPartyVinInquiry).toHaveBeenCalledTimes(1);
expect(service.sandHubService.getCarBodyInquiry).toHaveBeenCalledWith({
nationalCodeOfInsurer: "0033333333",
plate: vehicle.vin,
});
expect(req.inquiries.thirdParty.has).toBe(true);
expect(req.inquiries.carBody.has).toBe(true);
expect(party.insurance.policyNumber).toBe("TP-1");
expect(party.insurance.carBodyInsurance.policyNumber).toBe("BODY-1");
});
});

View File

@@ -465,7 +465,7 @@ export class RequestManagementService {
);
}
const subjects = resolveInquirySubjects(submission);
const result = await this.sandHubService.getPolicyByChassisInquiry(
const result = await this.sandHubService.getCarByChassisInquiry(
{
nationalCode: subjects.thirdPartyPolicyNationalCode,
chassis,
@@ -2142,7 +2142,7 @@ export class RequestManagementService {
* V2 initial-form submitted with a VIN/chassis number instead of a plate.
*
* Performs:
* 1. ESG `/inquiry/policyByChassis` (or its mock when `vinChassis` is off)
* 1. ESG two-factor `/inquiry/carByChassis` (or its mock when `vinChassis` is off)
* 2. Personal identity inquiry (same as the plate path)
*
* The inquiry result is mapped through the same `mapEsgPolicyByPlateToOldFormat`
@@ -2236,7 +2236,7 @@ export class RequestManagementService {
}
}
// ---- External inquiry: ESG policyByChassis ----
// ---- External inquiry: ESG two-factor carByChassis ----
const inquiryClientId = party.person?.clientId
? String(party.person.clientId)
: undefined;
@@ -2256,10 +2256,10 @@ export class RequestManagementService {
inquiryRaw = inquiry.raw;
inquiryMapped = inquiry.mapped;
this.logger.log(
`[ESG] policyByChassis raw for request=${req._id}: ${JSON.stringify(inquiryRaw)}`,
`[ESG] carByChassis raw for request=${req._id}: ${JSON.stringify(inquiryRaw)}`,
);
this.logger.log(
`[ESG] policyByChassis mapped for request=${req._id}: ${JSON.stringify(inquiryMapped)}`,
`[ESG] carByChassis mapped for request=${req._id}: ${JSON.stringify(inquiryMapped)}`,
);
this.recordPartyCaseInquiryStatus(
req,
@@ -2274,11 +2274,11 @@ export class RequestManagementService {
);
} catch (err: any) {
this.logger.error(
`[ESG] policyByChassis failed for request=${req._id}: ${err?.message || err}`,
`[ESG] carByChassis failed for request=${req._id}: ${err?.message || err}`,
);
if (err?.response) {
this.logger.error(
`[ESG] policyByChassis response for request=${req._id}: status=${
`[ESG] carByChassis response for request=${req._id}: status=${
err.response.status
}, data=${JSON.stringify(err.response.data)}`,
);
@@ -2300,7 +2300,7 @@ export class RequestManagementService {
if (inquiryMapped?.Error) {
this.logger.warn(
`[ESG] policyByChassis error for request=${req._id}: ${JSON.stringify(inquiryMapped.Error)}`,
`[ESG] carByChassis error for request=${req._id}: ${JSON.stringify(inquiryMapped.Error)}`,
);
this.recordPartyCaseInquiryStatus(req, "thirdParty", role, false, {
source: "ESG_VIN_INQUIRY",
@@ -10645,7 +10645,7 @@ export class RequestManagementService {
/**
* VIN variant of `runInquiriesV3`.
* Identical flow, but calls `getPolicyByChassisInquiry` instead of
* Identical flow, but calls the two-factor `getCarByChassisInquiry` instead of
* `getTejaratBlockInquiry` for the primary policy lookup.
*/
async runInquiriesVinV3(
@@ -10788,7 +10788,7 @@ export class RequestManagementService {
/**
* VIN variant of `runPartyInquiriesV3Internal`.
* Calls `getPolicyByChassisInquiry` (ESG chassis lookup) instead of
* Calls `getCarByChassisInquiry` (ESG two-factor chassis lookup) instead of
* `getTejaratBlockInquiry` (plate-based). All other inquiries (personal,
* driving licence, car-body for CAR_BODY) are unchanged.
*/