forked from Yara724/api
fix: query policies only for current holder
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||
import { RequestManagementService } from "./request-management.service";
|
||||
|
||||
describe("RequestManagementService policyholder inquiry routing", () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
};
|
||||
const previousPlate = {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
};
|
||||
const vehicle = {
|
||||
registrationState: "RECENTLY_TRANSFERRED",
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
vin: "NAAM01E15HK123456",
|
||||
};
|
||||
|
||||
function participantInput(caseType: BlameRequestType) {
|
||||
return {
|
||||
driver: {
|
||||
nationalCode: "0011111111",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: { sameAs: "DRIVER" },
|
||||
thirdPartyPolicyholder: {
|
||||
nationalCode: "0022222222",
|
||||
birthday: "1360/02/02",
|
||||
},
|
||||
...(caseType === BlameRequestType.CAR_BODY
|
||||
? {
|
||||
carBodyPolicyholder: {
|
||||
nationalCode: "0033333333",
|
||||
birthday: "1350/03/03",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
vehicle,
|
||||
};
|
||||
}
|
||||
|
||||
it("does not fall back from the current plate for third-party insurance", async () => {
|
||||
const service = Object.create(RequestManagementService.prototype) as any;
|
||||
service.sandHubService = {
|
||||
getTejaratBlockInquiry: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ raw: {}, mapped: {} })
|
||||
.mockResolvedValueOnce({
|
||||
raw: {},
|
||||
mapped: { CompanyName: "پارسیان", VinNumberField: vehicle.vin },
|
||||
}),
|
||||
};
|
||||
const submission = service.normalizeInquiryInput(
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
participantInput(BlameRequestType.THIRD_PARTY),
|
||||
);
|
||||
|
||||
await expect(service.getThirdPartyPlateInquiry(submission)).rejects.toThrow(
|
||||
"بیمهنامه معتبر و فعالی مطابق مشخصات خودرو و کد ملی واردشده یافت نشد.",
|
||||
);
|
||||
|
||||
expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledTimes(
|
||||
1,
|
||||
);
|
||||
expect(service.sandHubService.getTejaratBlockInquiry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
plate: currentPlate,
|
||||
nationalCodeOfInsurer: "0022222222",
|
||||
}),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it("does not fall back from the current plate for car-body insurance", async () => {
|
||||
const service = Object.create(RequestManagementService.prototype) as any;
|
||||
service.sandHubService = {
|
||||
getCarBodyInquiry: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ raw: {}, mapped: {} })
|
||||
.mockResolvedValueOnce({
|
||||
raw: {},
|
||||
mapped: { policyNumber: "BODY-1", VinNumberField: vehicle.vin },
|
||||
}),
|
||||
};
|
||||
const submission = service.normalizeInquiryInput(
|
||||
BlameRequestType.CAR_BODY,
|
||||
participantInput(BlameRequestType.CAR_BODY),
|
||||
);
|
||||
|
||||
await expect(service.getCarBodyPlateInquiry(submission)).rejects.toThrow(
|
||||
"بیمهنامه معتبر و فعالی مطابق مشخصات خودرو و کد ملی واردشده یافت نشد.",
|
||||
);
|
||||
|
||||
expect(service.sandHubService.getCarBodyInquiry).toHaveBeenCalledTimes(1);
|
||||
expect(service.sandHubService.getCarBodyInquiry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
plate: currentPlate,
|
||||
nationalCodeOfInsurer: "0033333333",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("queries VIN with the third-party policyholder", async () => {
|
||||
const service = Object.create(RequestManagementService.prototype) as any;
|
||||
service.sandHubService = {
|
||||
getPolicyByChassisInquiry: jest.fn().mockResolvedValue({
|
||||
raw: {},
|
||||
mapped: { CompanyName: "پارسیان" },
|
||||
}),
|
||||
};
|
||||
const submission = service.normalizeInquiryInput(
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
participantInput(BlameRequestType.THIRD_PARTY),
|
||||
);
|
||||
|
||||
await service.getThirdPartyVinInquiry(submission);
|
||||
|
||||
expect(
|
||||
service.sandHubService.getPolicyByChassisInquiry,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
service.sandHubService.getPolicyByChassisInquiry,
|
||||
).toHaveBeenCalledWith(
|
||||
{
|
||||
nationalCode: "0022222222",
|
||||
chassis: vehicle.vin,
|
||||
},
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user