forked from Yara724/api
Merge pull request 'FIXED mock problem' (#293) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#293
This commit is contained in:
@@ -15,6 +15,9 @@ describe("SandHubService inquiry mocks", () => {
|
|||||||
const lookupsService = {
|
const lookupsService = {
|
||||||
findLastProcessedCarPolicy: jest.fn(),
|
findLastProcessedCarPolicy: jest.fn(),
|
||||||
};
|
};
|
||||||
|
const offlineInquiryService = {
|
||||||
|
findPlateInquiry: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
let service: SandHubService;
|
let service: SandHubService;
|
||||||
|
|
||||||
@@ -32,17 +35,17 @@ describe("SandHubService inquiry mocks", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
delete process.env.CLIENT_ID;
|
delete process.env.CLIENT_ID;
|
||||||
|
delete process.env.FANAVARAN_CLIENT;
|
||||||
service = new SandHubService(
|
service = new SandHubService(
|
||||||
httpService as any,
|
httpService as any,
|
||||||
sandHubDbService as any,
|
sandHubDbService as any,
|
||||||
externalInquirySettings as unknown as ExternalInquirySettingsService,
|
externalInquirySettings as unknown as ExternalInquirySettingsService,
|
||||||
plateNormalizer as any,
|
plateNormalizer as any,
|
||||||
{
|
offlineInquiryService as any,
|
||||||
findPlateInquiry: jest.fn().mockResolvedValue(null),
|
|
||||||
} as any,
|
|
||||||
lookupsService as any,
|
lookupsService as any,
|
||||||
);
|
);
|
||||||
externalInquirySettings.isInquiryLive.mockResolvedValue(false);
|
externalInquirySettings.isInquiryLive.mockResolvedValue(false);
|
||||||
|
offlineInquiryService.findPlateInquiry.mockResolvedValue(null);
|
||||||
externalInquirySettings.getMockCompanyContext.mockResolvedValue({
|
externalInquirySettings.getMockCompanyContext.mockResolvedValue({
|
||||||
companyId: "8",
|
companyId: "8",
|
||||||
companyName: "بیمه پارسیان",
|
companyName: "بیمه پارسیان",
|
||||||
@@ -107,6 +110,50 @@ describe("SandHubService inquiry mocks", () => {
|
|||||||
expect(httpService.post).not.toHaveBeenCalled();
|
expect(httpService.post).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not let an offline third-party seed override a live ESG inquiry", async () => {
|
||||||
|
process.env.CLIENT_ID = "8";
|
||||||
|
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||||
|
offlineInquiryService.findPlateInquiry.mockResolvedValue({
|
||||||
|
source: "OFFLINE_SEED_INQUIRY",
|
||||||
|
raw: { mocked: true },
|
||||||
|
mapped: { PrntPlcyCmpDocNo: "MOCK-POLICY" },
|
||||||
|
});
|
||||||
|
const esg = jest
|
||||||
|
.spyOn(service as any, "makeEsgRequest")
|
||||||
|
.mockResolvedValue({
|
||||||
|
success: true,
|
||||||
|
data: { PrntCmpDocNo: "REAL-ESG-POLICY" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await service.getTejaratBlockInquiry(userDetail);
|
||||||
|
|
||||||
|
expect(esg).toHaveBeenCalled();
|
||||||
|
expect(result.raw).not.toEqual({ mocked: true });
|
||||||
|
expect(result.mapped.PrntPlcyCmpDocNo).toBe("REAL-ESG-POLICY");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the processed CAR_BODY lookup when the active Fanavaran client is Parsian", async () => {
|
||||||
|
process.env.FANAVARAN_CLIENT = "parsian";
|
||||||
|
externalInquirySettings.isInquiryLive.mockResolvedValue(true);
|
||||||
|
lookupsService.findLastProcessedCarPolicy.mockResolvedValue({
|
||||||
|
policy: { CINumber: "70019846985" },
|
||||||
|
customer: {},
|
||||||
|
vehicle: {},
|
||||||
|
});
|
||||||
|
const tejarat = jest
|
||||||
|
.spyOn(service, "getTejaratCarBodyInquiry")
|
||||||
|
.mockResolvedValue({ raw: { mocked: true }, mapped: {} });
|
||||||
|
|
||||||
|
const result = await service.getCarBodyInquiry(userDetail);
|
||||||
|
|
||||||
|
expect(lookupsService.findLastProcessedCarPolicy).toHaveBeenCalledWith(
|
||||||
|
"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 ESG car-body inquiry in mock mode when the per-client toggle is off", async () => {
|
||||||
process.env.CLIENT_ID = "8";
|
process.env.CLIENT_ID = "8";
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,15 @@ export class SandHubService {
|
|||||||
return String(process.env.CLIENT_ID ?? "") === "8";
|
return String(process.env.CLIENT_ID ?? "") === "8";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The processed Fanavaran CAR_BODY lookup belongs only to the Parsian
|
||||||
|
* Fanavaran profile. Do not use the deployment-wide ESG selector here:
|
||||||
|
* `FANAVARAN_CLIENT=parsian` is valid even when CLIENT_ID is not 8.
|
||||||
|
*/
|
||||||
|
private shouldUseParsianCarBodyLookup(): boolean {
|
||||||
|
return resolveFanavaranClientKey() === "parsian";
|
||||||
|
}
|
||||||
|
|
||||||
/** Fixed plate/insurance inquiry payload used everywhere we mock block-inquiry style APIs. */
|
/** Fixed plate/insurance inquiry payload used everywhere we mock block-inquiry style APIs. */
|
||||||
private buildMockPlateInquiryRaw(
|
private buildMockPlateInquiryRaw(
|
||||||
ctx: MockInquiryCompanyContext,
|
ctx: MockInquiryCompanyContext,
|
||||||
@@ -757,6 +766,10 @@ export class SandHubService {
|
|||||||
person?: Record<string, unknown>;
|
person?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
}> {
|
}> {
|
||||||
|
const live = await this.isInquiryLive("thirdPartyPlate", options);
|
||||||
|
// Offline records are a fallback for disabled inquiry mode only. They must
|
||||||
|
// never override a configured live ESG/Tejarat inquiry.
|
||||||
|
if (!live) {
|
||||||
const offlineHit = await this.offlineInquiryService.findPlateInquiry({
|
const offlineHit = await this.offlineInquiryService.findPlateInquiry({
|
||||||
clientKey: resolveFanavaranClientKey(),
|
clientKey: resolveFanavaranClientKey(),
|
||||||
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
nationalCode: String(userDetail.nationalCodeOfInsurer),
|
||||||
@@ -777,6 +790,7 @@ export class SandHubService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const ctx = await this.mockCompanyContext(options);
|
const ctx = await this.mockCompanyContext(options);
|
||||||
if (this.shouldUseEsgInquiryProvider()) {
|
if (this.shouldUseEsgInquiryProvider()) {
|
||||||
@@ -790,7 +804,6 @@ export class SandHubService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const requestUrl = `${baseUrl}/inquiry/policyByPlate`;
|
const requestUrl = `${baseUrl}/inquiry/policyByPlate`;
|
||||||
const live = await this.isInquiryLive("thirdPartyPlate", options);
|
|
||||||
const raw = live
|
const raw = live
|
||||||
? await this.makeEsgRequest(
|
? await this.makeEsgRequest(
|
||||||
requestUrl,
|
requestUrl,
|
||||||
@@ -819,7 +832,6 @@ export class SandHubService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const requestUrl = `${baseUrl}/block-inquiry-tejarat`;
|
const requestUrl = `${baseUrl}/block-inquiry-tejarat`;
|
||||||
const live = await this.isInquiryLive("thirdPartyPlate", options);
|
|
||||||
const raw = live
|
const raw = live
|
||||||
? await this.makeTejaratRequest(
|
? await this.makeTejaratRequest(
|
||||||
requestUrl,
|
requestUrl,
|
||||||
@@ -857,7 +869,7 @@ export class SandHubService {
|
|||||||
raw: any;
|
raw: any;
|
||||||
mapped: Record<string, unknown>;
|
mapped: Record<string, unknown>;
|
||||||
}> {
|
}> {
|
||||||
if (!this.shouldUseEsgInquiryProvider()) {
|
if (!this.shouldUseParsianCarBodyLookup()) {
|
||||||
const result = await this.getTejaratCarBodyInquiry(
|
const result = await this.getTejaratCarBodyInquiry(
|
||||||
userDetail as SandHubDetailDto,
|
userDetail as SandHubDetailDto,
|
||||||
options,
|
options,
|
||||||
|
|||||||
Reference in New Issue
Block a user