forked from Yara724/api
132 lines
4.3 KiB
TypeScript
132 lines
4.3 KiB
TypeScript
import { model } from "mongoose";
|
|
import { RequestManagementService } from "./request-management.service";
|
|
import { normalizeInquirySubmission } from "./inquiry-participant-resolver";
|
|
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
|
import {
|
|
BlameRequest,
|
|
BlameRequestSchema,
|
|
} from "./entities/schema/blame-cases.schema";
|
|
import { persianReportValue } from "src/case-expert-report/persian-report-labels";
|
|
|
|
describe("licence selection integrity", () => {
|
|
const types = [
|
|
{ Id: 3, Caption: "ریلی", IsActive: 1 },
|
|
{ Id: 10, Caption: "پایه ۳", IsActive: 1 },
|
|
];
|
|
|
|
const input = (licenseType = "10", hasDrivingLicense = true) => ({
|
|
driver: {
|
|
nationalCode: "0022324224",
|
|
birthday: "1378/04/26",
|
|
hasDrivingLicense,
|
|
...(hasDrivingLicense
|
|
? {
|
|
licenseType,
|
|
licenseNumber: "1001011111",
|
|
driverLicenseDate: "1400/01/01",
|
|
}
|
|
: {}),
|
|
},
|
|
vehicleOwner: { sameAs: "DRIVER" },
|
|
thirdPartyPolicyholder: { sameAs: "DRIVER" },
|
|
vehicle: {
|
|
currentPlate: {
|
|
leftDigits: "59",
|
|
centerAlphabet: "ی",
|
|
centerDigits: "419",
|
|
ir: "78",
|
|
},
|
|
isNewCar: false,
|
|
},
|
|
});
|
|
|
|
const service = () => {
|
|
const instance = Object.create(RequestManagementService.prototype) as any;
|
|
instance.lookupsService = {
|
|
getDrivingLicenceTypes: jest.fn().mockResolvedValue(types),
|
|
};
|
|
return instance;
|
|
};
|
|
|
|
it.each([BlameRequestType.THIRD_PARTY, BlameRequestType.CAR_BODY])(
|
|
"keeps the selected provider ID and verified caption through normalization and persistence for %s",
|
|
async (caseType) => {
|
|
const submission = normalizeInquirySubmission(caseType, {
|
|
...input(),
|
|
...(caseType === BlameRequestType.CAR_BODY
|
|
? { carBodyPolicyholder: { sameAs: "DRIVER" } }
|
|
: {}),
|
|
});
|
|
await service().validateDrivingLicenceType(submission);
|
|
expect(submission.driver.licenseType).toBe("10");
|
|
expect(submission.driver.licenseTypeLabel).toBe("پایه ۳");
|
|
expect(submission.dto.licenseTypeLabel).toBe("پایه ۳");
|
|
expect(
|
|
submission.participants.participants.find(
|
|
(p) => p.participantId === submission.driver.participantId,
|
|
)?.licenseTypeLabel,
|
|
).toBe("پایه ۳");
|
|
const RequestModel = model<BlameRequest>(
|
|
`LicenceTypePersistence${caseType}`,
|
|
BlameRequestSchema,
|
|
);
|
|
const request = new RequestModel({
|
|
requestNo: "BL-LICENCE",
|
|
publicId: "LICENCE",
|
|
type: caseType,
|
|
parties: [
|
|
{
|
|
role: "FIRST",
|
|
person: {
|
|
licenseType: submission.dto.licenseType,
|
|
licenseTypeLabel: submission.dto.licenseTypeLabel,
|
|
},
|
|
participants: submission.participants.participants,
|
|
participantRoles: submission.participants.roles,
|
|
},
|
|
],
|
|
});
|
|
expect(request.validateSync()).toBeUndefined();
|
|
expect(request.toObject().parties[0].participants?.[0].licenseType).toBe(
|
|
"10",
|
|
);
|
|
expect(
|
|
request.toObject().parties[0].participants?.[0].licenseTypeLabel,
|
|
).toBe("پایه ۳");
|
|
expect(request.toObject().parties[0].person.licenseTypeLabel).toBe(
|
|
"پایه ۳",
|
|
);
|
|
},
|
|
);
|
|
|
|
it("rejects IDs absent from the canonical lookup before inquiry work", async () => {
|
|
const submission = normalizeInquirySubmission(
|
|
BlameRequestType.THIRD_PARTY,
|
|
input("999"),
|
|
);
|
|
await expect(
|
|
service().validateDrivingLicenceType(submission),
|
|
).rejects.toThrow("فهرست استعلامشده");
|
|
expect(submission.driver.licenseTypeLabel).toBeUndefined();
|
|
});
|
|
|
|
it("does not require a lookup for a driver without a licence", async () => {
|
|
const instance = service();
|
|
const submission = normalizeInquirySubmission(
|
|
BlameRequestType.THIRD_PARTY,
|
|
input("", false),
|
|
);
|
|
await instance.validateDrivingLicenceType(submission);
|
|
expect(
|
|
instance.lookupsService.getDrivingLicenceTypes,
|
|
).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not guess numeric meanings in reports", () => {
|
|
expect(persianReportValue("participant.licenseType", "3")).toBe("3");
|
|
expect(persianReportValue("participant.licenseType", "BASE_3")).toBe(
|
|
"پایه سه",
|
|
);
|
|
});
|
|
});
|