fix(inquiries): route all tenants through ESG and Fanavaran

This commit is contained in:
SepehrYahyaee
2026-11-21 15:27:06 +03:30
parent 61ef4faaf4
commit 1a38b98829
15 changed files with 675 additions and 860 deletions
+24 -53
View File
@@ -60,6 +60,7 @@ describe("SandHubService inquiry mocks", () => {
beforeEach(() => {
jest.clearAllMocks();
process.env.CLIENT_ID = "8";
process.env.ESG_URL = "http://esg.example.test";
delete process.env.FANAVARAN_CLIENT;
service = new SandHubService(
httpService as any,
@@ -77,7 +78,7 @@ describe("SandHubService inquiry mocks", () => {
});
it("keeps disabled-live third-party mock policy usable", async () => {
const result = await service.getTejaratBlockInquiry(userDetail, {
const result = await service.getCarByPlateInquiry(userDetail, {
enforceDeploymentClientMatch: true,
});
@@ -87,7 +88,7 @@ describe("SandHubService inquiry mocks", () => {
});
it("returns car-body mock without HTTP when carBodyPlate is off", async () => {
const result = await service.getTejaratCarBodyInquiry(userDetail);
const result = await service.getCarBodyInquiry(userDetail);
expect(httpService.post).not.toHaveBeenCalled();
expect(externalInquirySettings.isInquiryLive).toHaveBeenCalledWith(
@@ -107,7 +108,7 @@ describe("SandHubService inquiry mocks", () => {
expect(result.mapped.platePartThree).toBe(498);
});
it("uses the processed ESG CAR_BODY lookup and preserves it as raw data", async () => {
it("uses the processed Fanavaran CAR_BODY lookup and preserves it as raw data", async () => {
process.env.CLIENT_ID = "8";
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
lookupsService.findLastProcessedCarPolicy.mockResolvedValue({
@@ -140,7 +141,7 @@ describe("SandHubService inquiry mocks", () => {
plaqueSerial: "60",
},
);
expect(result.source).toBe("ESG_CAR_BODY_INQUIRY");
expect(result.source).toBe("FANAVARAN_CAR_BODY_INQUIRY");
expect(result.raw.policyId).toBe(15292336);
expect(result.mapped.policyNumber).toBe("70019846985");
expect(httpService.post).not.toHaveBeenCalled();
@@ -170,7 +171,7 @@ describe("SandHubService inquiry mocks", () => {
data: { PrntCmpDocNo: "REAL-ESG-POLICY" },
});
const result = await service.getTejaratBlockInquiry(userDetail);
const result = await service.getCarByPlateInquiry(userDetail);
expect(esg).toHaveBeenCalled();
expect(result.raw).not.toEqual({ mocked: true });
@@ -185,7 +186,7 @@ describe("SandHubService inquiry mocks", () => {
data: { PrntCmpDocNo: "ESG-PLATE-POLICY" },
});
await service.getTejaratBlockInquiry(userDetail);
await service.getCarByPlateInquiry(userDetail);
expect(esg).toHaveBeenCalledWith(
expect.stringMatching(/\/inquiry\/carByPlate$/),
@@ -236,7 +237,7 @@ describe("SandHubService inquiry mocks", () => {
},
});
const result = await service.getTejaratBlockInquiry(userDetail, {
const result = await service.getCarByPlateInquiry(userDetail, {
enforceDeploymentClientMatch: true,
});
@@ -271,14 +272,14 @@ describe("SandHubService inquiry mocks", () => {
it("rejects a guilty third-party policy issued by another insurer", async () => {
process.env.CLIENT_ID = "15";
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
jest.spyOn(service as any, "makeTejaratRequest").mockResolvedValue({
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
CompanyCode: "8",
CompanyName: "بیمه پارسیان",
PrntPlcyCmpDocNo: "OTHER-INSURER-POLICY",
});
await expect(
service.getTejaratBlockInquiry(userDetail, {
service.getCarByPlateInquiry(userDetail, {
enforceDeploymentClientMatch: true,
} as any),
).rejects.toBeInstanceOf(ForbiddenException);
@@ -287,12 +288,12 @@ describe("SandHubService inquiry mocks", () => {
it("allows an unchecked third-party policy from another insurer", async () => {
process.env.CLIENT_ID = "15";
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
jest.spyOn(service as any, "makeTejaratRequest").mockResolvedValue({
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
CompanyCode: "8",
CompanyName: "بیمه پارسیان",
});
await expect(service.getTejaratBlockInquiry(userDetail)).resolves.toEqual(
await expect(service.getCarByPlateInquiry(userDetail)).resolves.toEqual(
expect.objectContaining({
mapped: expect.objectContaining({ CompanyCode: "8" }),
}),
@@ -344,10 +345,7 @@ describe("SandHubService inquiry mocks", () => {
it("does not accept a policy when CLIENT_ID is not configured", async () => {
delete process.env.CLIENT_ID;
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
jest.spyOn(service, "getTejaratCarBodyInquiry").mockResolvedValue({
raw: { data: { companyId: "15" } },
mapped: { companyId: "15", CompanyCode: "15" },
});
await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf(
ServiceUnavailableException,
@@ -372,10 +370,8 @@ describe("SandHubService inquiry mocks", () => {
it("rejects a CAR_BODY policy from another insurer on the Tejarat lookup route", async () => {
process.env.CLIENT_ID = "15";
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
jest.spyOn(service, "getTejaratCarBodyInquiry").mockResolvedValue({
raw: { data: { companyId: "8" } },
mapped: { companyId: "8", CompanyCode: "8" },
});
lookupsService.findLastProcessedCarPolicy.mockResolvedValue({ policy: { CompanyId: "8" }, customer: {}, vehicle: {} });
await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf(
ForbiddenException,
@@ -393,7 +389,7 @@ describe("SandHubService inquiry mocks", () => {
await expect(service.getCarBodyInquiry(userDetail)).resolves.toEqual(
expect.objectContaining({
source: "ESG_CAR_BODY_INQUIRY",
source: "FANAVARAN_CAR_BODY_INQUIRY",
mapped: expect.objectContaining({ companyId: 15 }),
}),
);
@@ -408,9 +404,7 @@ describe("SandHubService inquiry mocks", () => {
customer: {},
vehicle: {},
});
const tejarat = jest
.spyOn(service, "getTejaratCarBodyInquiry")
.mockResolvedValue({ raw: { mocked: true }, mapped: {} });
const result = await service.getCarBodyInquiry(userDetail);
@@ -418,22 +412,21 @@ describe("SandHubService inquiry mocks", () => {
"car-body",
expect.objectContaining({ nationalCode: "1234567890" }),
);
expect(tejarat).not.toHaveBeenCalled();
expect(result.raw).not.toEqual({ mocked: true });
});
it("keeps ESG car-body inquiry in mock mode when the per-client toggle is off", async () => {
it("keeps Fanavaran car-body inquiry in mock mode when the per-client toggle is off", async () => {
process.env.CLIENT_ID = "8";
const result = await service.getCarBodyInquiry(userDetail);
expect(lookupsService.findLastProcessedCarPolicy).not.toHaveBeenCalled();
expect(result.source).toBe("ESG_CAR_BODY_INQUIRY");
expect(result.source).toBe("FANAVARAN_CAR_BODY_INQUIRY");
expect(result.raw?.isSuccess).toBe(true);
expect(httpService.post).not.toHaveBeenCalled();
});
it("uses the VIN lookup and VIN audit source for ESG car-body VIN inquiries", async () => {
it("uses the VIN lookup and VIN audit source for Fanavaran car-body VIN inquiries", async () => {
process.env.CLIENT_ID = "8";
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
lookupsService.findLastProcessedCarPolicy.mockResolvedValue({
@@ -451,7 +444,7 @@ describe("SandHubService inquiry mocks", () => {
"car-body",
{ nationalCode: "1234567890", vin: "NAAR03HFFRDE07024" },
);
expect(result.source).toBe("ESG_CAR_BODY_VIN_INQUIRY");
expect(result.source).toBe("FANAVARAN_CAR_BODY_VIN_INQUIRY");
});
it("uses the tenant Fanavaran VIN lookup for non-Parsian car-body inquiries", async () => {
@@ -463,7 +456,6 @@ describe("SandHubService inquiry mocks", () => {
customer: {},
vehicle: { VIN: "NAAR03HFFRDE07024" },
});
const tejarat = jest.spyOn(service, "getTejaratCarBodyInquiry");
const result = await service.getCarBodyInquiry({
nationalCodeOfInsurer: "0012345678",
@@ -474,47 +466,26 @@ describe("SandHubService inquiry mocks", () => {
"car-body",
{ nationalCode: "0012345678", vin: "NAAR03HFFRDE07024" },
);
expect(tejarat).not.toHaveBeenCalled();
expect(result.source).toBe("TEJARAT_CAR_BODY_VIN_INQUIRY");
expect(result.source).toBe("FANAVARAN_CAR_BODY_VIN_INQUIRY");
});
it("returns a VIN-shaped car-body mock without invoking a plate adapter", async () => {
process.env.CLIENT_ID = "15";
process.env.FANAVARAN_CLIENT = "tejaratno";
const tejarat = jest.spyOn(service, "getTejaratCarBodyInquiry");
const result = await service.getCarBodyInquiry({
nationalCodeOfInsurer: "0012345678",
plate: "NAAR03HFFRDE07024",
});
expect(tejarat).not.toHaveBeenCalled();
expect(lookupsService.findLastProcessedCarPolicy).not.toHaveBeenCalled();
expect(result.source).toBe("TEJARAT_CAR_BODY_VIN_INQUIRY");
expect(result.source).toBe("FANAVARAN_CAR_BODY_VIN_INQUIRY");
expect(result.mapped.VinNumberField).toBe("NAAR03HFFRDE07024");
expect(result.mapped.insurerNationalCode).toBe("0012345678");
});
it("uses car-body mock shape in Tejarat helper when inquiry is off", async () => {
const raw = await (service as any).makeTejaratRequest(
"http://example/block-inquiry-tejarat/badane",
{
part1: 16,
part2: 12,
part3: 498,
part4: 60,
nationalCode: "1234567890",
},
"carBodyPlate",
);
expect(httpService.post).not.toHaveBeenCalled();
expect(raw?.data?.printNumber).toBe("1405/1143-70591/220/1/0");
expect(raw?.data?.companyName).toBe("بیمه پارسیان");
});
it("returns third-party plate mock for block inquiry when inquiry is off", async () => {
const result = await service.getTejaratBlockInquiry(userDetail);
const result = await service.getCarByPlateInquiry(userDetail);
expect(httpService.post).not.toHaveBeenCalled();
expect(result.mapped?.CompanyName).toBe("بیمه پارسیان");