forked from Yara724/api
149 lines
5.2 KiB
TypeScript
149 lines
5.2 KiB
TypeScript
import { SandHubService } from "./sand-hub.service";
|
|
import { ExternalInquirySettingsService } from "src/client/external-inquiry-settings.service";
|
|
import { SandHubDetailDto } from "./dto/sand-hub.dto";
|
|
|
|
describe("SandHubService inquiry mocks", () => {
|
|
const httpService = { post: jest.fn() };
|
|
const sandHubDbService = { findOneBySandHubId: jest.fn() };
|
|
const externalInquirySettings = {
|
|
isInquiryLive: jest.fn(),
|
|
getMockCompanyContext: jest.fn(),
|
|
};
|
|
const plateNormalizer = {
|
|
normalizePlateText: (text: string) => text,
|
|
};
|
|
|
|
let service: SandHubService;
|
|
|
|
const userDetail = {
|
|
nationalCodeOfInsurer: "1234567890",
|
|
plate: {
|
|
leftDigits: 16,
|
|
centerAlphabet: "12",
|
|
centerDigits: 498,
|
|
ir: 60,
|
|
nationalCode: "1234567890",
|
|
},
|
|
} as SandHubDetailDto;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
delete process.env.CLIENT_ID;
|
|
service = new SandHubService(
|
|
httpService as any,
|
|
sandHubDbService as any,
|
|
externalInquirySettings as unknown as ExternalInquirySettingsService,
|
|
plateNormalizer as any,
|
|
{
|
|
findPlateInquiry: jest.fn().mockResolvedValue(null),
|
|
} as any,
|
|
);
|
|
externalInquirySettings.isInquiryLive.mockResolvedValue(false);
|
|
externalInquirySettings.getMockCompanyContext.mockResolvedValue({
|
|
companyId: "8",
|
|
companyName: "بیمه پارسیان",
|
|
});
|
|
});
|
|
|
|
it("returns car-body mock without HTTP when carBodyPlate is off", async () => {
|
|
const result = await service.getTejaratCarBodyInquiry(userDetail);
|
|
|
|
expect(httpService.post).not.toHaveBeenCalled();
|
|
expect(externalInquirySettings.isInquiryLive).toHaveBeenCalledWith(
|
|
"carBodyPlate",
|
|
undefined,
|
|
);
|
|
expect(result.raw?.isSuccess).toBe(true);
|
|
expect(result.raw?.data?.companyId).toBe(8);
|
|
expect(result.raw?.data?.companyName).toBe("بیمه پارسیان");
|
|
expect(result.mapped.policyNumber).toBe("1405/1143-70591/220/1/0");
|
|
expect(result.mapped.CompanyName).toBe("بیمه پارسیان");
|
|
expect(result.mapped.companyId).toBe(8);
|
|
expect(result.mapped.insurerNationalCode).toBe("1234567890");
|
|
expect(result.mapped.platePartOne).toBe(16);
|
|
expect(result.mapped.platePartThree).toBe(498);
|
|
});
|
|
|
|
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);
|
|
|
|
expect(httpService.post).not.toHaveBeenCalled();
|
|
expect(result.mapped?.CompanyName).toBe("بیمه پارسیان");
|
|
expect(result.mapped?.CompanyCode).toBe("8");
|
|
// PrntPlcyCmpDocNo must be populated from the mock raw field
|
|
expect(result.mapped?.PrntPlcyCmpDocNo).toBe("1404/1143-70591/200/123");
|
|
});
|
|
|
|
it("maps printNumber → PrntPlcyCmpDocNo when raw response uses new field name", async () => {
|
|
// Simulate a real-API response where the policy number arrives as printNumber
|
|
const rawNewFormat = {
|
|
printNumber: "1405/1143-NEWAPI/200/1",
|
|
CompanyName: "بیمه آزمایشی",
|
|
CompanyCode: "99",
|
|
FinancialCvrCptl: "5000000000",
|
|
IssueDate: "1405/01/01",
|
|
EndDate: "1406/01/01",
|
|
};
|
|
const mapped = (service as any).mapNewApiResponseToOldFormat(rawNewFormat);
|
|
|
|
expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-NEWAPI/200/1");
|
|
});
|
|
|
|
it("maps insuranceNumber → PrntPlcyCmpDocNo when raw response uses legacy field name", async () => {
|
|
const rawLegacy = {
|
|
insuranceNumber: "1405/1143-LEGACY/200/1",
|
|
CompanyName: "بیمه آزمایشی",
|
|
CompanyCode: "99",
|
|
};
|
|
const mapped = (service as any).mapNewApiResponseToOldFormat(rawLegacy);
|
|
|
|
expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-LEGACY/200/1");
|
|
});
|
|
|
|
it("maps ESG PrntCmpDocNo → PrntPlcyCmpDocNo and preserves begin/end dates", () => {
|
|
const mapped = (service as any).mapEsgPolicyByPlateToOldFormat({
|
|
success: true,
|
|
data: {
|
|
PrntCmpDocNo: "1110/111130/404/003412",
|
|
LastCmpDocNo: "1110/111130/403/002650",
|
|
PlcyUnqCod: "16018466143",
|
|
HBgnDte: "1404/10/23",
|
|
HEndDte: "1405/10/23",
|
|
HIsuDte: "1404/10/21",
|
|
VIN: "IRFC891V7D2301065",
|
|
MtrNum: "13389030167",
|
|
ShsNum: "NAAP41FD5BJ301065",
|
|
PrdDte: "1389",
|
|
CmpCod: "8",
|
|
CmpNam: "بيمه پارسيان",
|
|
},
|
|
});
|
|
|
|
expect(mapped.PrntPlcyCmpDocNo).toBe("1110/111130/404/003412");
|
|
expect(mapped.ThirdPolicyCode).toBe("16018466143");
|
|
expect(mapped.StartDate).toBe("1404/10/23");
|
|
expect(mapped.EndDate).toBe("1405/10/23");
|
|
expect(mapped.IssueDate).toBe("1404/10/21");
|
|
expect(mapped.VIN).toBe("IRFC891V7D2301065");
|
|
expect(mapped.ModelField).toBe("1389");
|
|
});
|
|
});
|