forked from Yara724/api
enforced matching client id for moving on with the case
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { SandHubService } from "./sand-hub.service";
|
||||
import {
|
||||
ForbiddenException,
|
||||
ServiceUnavailableException,
|
||||
} from "@nestjs/common";
|
||||
import { ExternalInquirySettingsService } from "src/client/external-inquiry-settings.service";
|
||||
import { SandHubDetailDto } from "./dto/sand-hub.dto";
|
||||
|
||||
@@ -34,7 +38,7 @@ describe("SandHubService inquiry mocks", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
delete process.env.CLIENT_ID;
|
||||
process.env.CLIENT_ID = "8";
|
||||
delete process.env.FANAVARAN_CLIENT;
|
||||
service = new SandHubService(
|
||||
httpService as any,
|
||||
@@ -132,6 +136,87 @@ describe("SandHubService inquiry mocks", () => {
|
||||
expect(result.mapped.PrntPlcyCmpDocNo).toBe("REAL-ESG-POLICY");
|
||||
});
|
||||
|
||||
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({
|
||||
CompanyCode: "8",
|
||||
CompanyName: "بیمه پارسیان",
|
||||
PrntPlcyCmpDocNo: "OTHER-INSURER-POLICY",
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.getTejaratBlockInquiry(userDetail, {
|
||||
enforceDeploymentClientMatch: true,
|
||||
} as any),
|
||||
).rejects.toBeInstanceOf(ForbiddenException);
|
||||
});
|
||||
|
||||
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({
|
||||
CompanyCode: "8",
|
||||
CompanyName: "بیمه پارسیان",
|
||||
});
|
||||
|
||||
await expect(service.getTejaratBlockInquiry(userDetail)).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
mapped: expect.objectContaining({ CompanyCode: "8" }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a guilty VIN third-party policy issued by another insurer", async () => {
|
||||
process.env.CLIENT_ID = "15";
|
||||
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||
jest.spyOn(service as any, "makeEsgRequest").mockResolvedValue({
|
||||
success: true,
|
||||
data: { CmpCod: "8", CmpNam: "بیمه پارسیان" },
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.getPolicyByChassisInquiry("NAAR03HFFRDE07024", {
|
||||
enforceDeploymentClientMatch: true,
|
||||
}),
|
||||
).rejects.toBeInstanceOf(ForbiddenException);
|
||||
});
|
||||
|
||||
it("does not accept a policy when CLIENT_ID is not configured", async () => {
|
||||
delete process.env.CLIENT_ID;
|
||||
|
||||
await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf(
|
||||
ServiceUnavailableException,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a CAR_BODY policy from another insurer on the Parsian lookup route", async () => {
|
||||
process.env.CLIENT_ID = "15";
|
||||
process.env.FANAVARAN_CLIENT = "parsian";
|
||||
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||
lookupsService.findLastProcessedCarPolicy.mockResolvedValue({
|
||||
policy: { CINumber: "70019846985" },
|
||||
customer: {},
|
||||
vehicle: {},
|
||||
});
|
||||
|
||||
await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a CAR_BODY policy from another insurer on the Tejarat lookup route", async () => {
|
||||
process.env.CLIENT_ID = "15";
|
||||
jest.spyOn(service, "getTejaratCarBodyInquiry").mockResolvedValue({
|
||||
raw: { data: { companyId: "8" } },
|
||||
mapped: { companyId: "8", CompanyCode: "8" },
|
||||
});
|
||||
|
||||
await expect(service.getCarBodyInquiry(userDetail)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
it("uses the processed CAR_BODY lookup when the active Fanavaran client is Parsian", async () => {
|
||||
process.env.FANAVARAN_CLIENT = "parsian";
|
||||
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||
|
||||
Reference in New Issue
Block a user