forked from Yara724/api
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import { Types } from "mongoose";
|
|
import { ExternalInquirySettingsService } from "./external-inquiry-settings.service";
|
|
import { SystemSettingsService } from "src/system-settings/system-settings.service";
|
|
|
|
describe("ExternalInquirySettingsService", () => {
|
|
const systemSettings = {
|
|
isSandHubLiveEnabled: jest.fn(),
|
|
};
|
|
const clientDb = {
|
|
findOne: jest.fn(),
|
|
};
|
|
|
|
let service: ExternalInquirySettingsService;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
delete process.env.CLIENT_ID;
|
|
delete process.env.CLIENT_NAME;
|
|
service = new ExternalInquirySettingsService(
|
|
systemSettings as unknown as SystemSettingsService,
|
|
clientDb as any,
|
|
);
|
|
service.invalidateClientCache();
|
|
});
|
|
|
|
it("returns false when global master switch is off", async () => {
|
|
systemSettings.isSandHubLiveEnabled.mockResolvedValue(false);
|
|
clientDb.findOne.mockResolvedValue({
|
|
clientCode: 8,
|
|
settings: { externalInquiries: { sheba: true } },
|
|
});
|
|
|
|
await expect(service.isInquiryLive("sheba", "client-id")).resolves.toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("returns true only when global and per-insurer flags are on", async () => {
|
|
const clientId = new Types.ObjectId().toString();
|
|
systemSettings.isSandHubLiveEnabled.mockResolvedValue(true);
|
|
clientDb.findOne.mockResolvedValue({
|
|
clientCode: 8,
|
|
clientName: { persian: "بیمه پارسیان" },
|
|
settings: {
|
|
externalInquiries: {
|
|
thirdPartyPlate: true,
|
|
sheba: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
await expect(
|
|
service.isInquiryLive("thirdPartyPlate", clientId),
|
|
).resolves.toBe(true);
|
|
await expect(service.isInquiryLive("sheba", clientId)).resolves.toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("uses client document for mock company context", async () => {
|
|
const clientId = new Types.ObjectId().toString();
|
|
clientDb.findOne.mockResolvedValue({
|
|
clientCode: 8,
|
|
clientName: { persian: "بیمه پارسیان" },
|
|
});
|
|
|
|
await expect(service.getMockCompanyContext(clientId)).resolves.toEqual({
|
|
companyId: "8",
|
|
companyName: "بیمه پارسیان",
|
|
});
|
|
});
|
|
|
|
it("falls back to deployment env when client is missing", async () => {
|
|
process.env.CLIENT_ID = "15";
|
|
process.env.CLIENT_NAME = "بیمه سامان";
|
|
clientDb.findOne.mockResolvedValue(null);
|
|
|
|
await expect(service.getMockCompanyContext()).resolves.toEqual({
|
|
companyId: "15",
|
|
companyName: "بیمه سامان",
|
|
});
|
|
});
|
|
});
|