forked from Yara724/api
154 lines
4.7 KiB
TypeScript
154 lines
4.7 KiB
TypeScript
import { model, Types } from "mongoose";
|
|
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
|
import {
|
|
BlameRequest,
|
|
BlameRequestSchema,
|
|
} from "./entities/schema/blame-cases.schema";
|
|
import { PartyRole } from "./entities/schema/partyRole.enum";
|
|
import { normalizeInquirySubmission } from "./inquiry-participant-resolver";
|
|
|
|
describe("inquiry participant persistence", () => {
|
|
it("accepts slash-formatted Jalali birthdays from the structured payload", () => {
|
|
const submission = normalizeInquirySubmission(
|
|
BlameRequestType.THIRD_PARTY,
|
|
{
|
|
driver: {
|
|
nationalCode: "0022324224",
|
|
birthday: "1378/04/26",
|
|
hasDrivingLicense: true,
|
|
driverLicenseDate: "1400/01/01",
|
|
licenseNumber: "1001011111",
|
|
licenseType: "10",
|
|
},
|
|
vehicleOwner: {
|
|
nationalCode: "5560568341",
|
|
birthday: "1378/06/27",
|
|
},
|
|
thirdPartyPolicyholder: { sameAs: "VEHICLE_OWNER" },
|
|
vehicle: {
|
|
registrationState: "CURRENT",
|
|
currentPlate: {
|
|
leftDigits: "59",
|
|
centerAlphabet: "ی",
|
|
centerDigits: "419",
|
|
ir: "78",
|
|
},
|
|
isNewCar: false,
|
|
},
|
|
},
|
|
);
|
|
const BlameRequestModel = model<BlameRequest>(
|
|
"InquiryParticipantBirthdayPersistenceTest",
|
|
BlameRequestSchema,
|
|
);
|
|
const request = new BlameRequestModel({
|
|
requestNo: "BL-PARTICIPANT-BIRTHDAY",
|
|
publicId: "PARTICIPANT-BIRTHDAY",
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
person: {
|
|
insurerBirthday: submission.dto.insurerBirthday,
|
|
driverBirthday: submission.dto.driverBirthday,
|
|
},
|
|
participants: submission.participants.participants,
|
|
participantRoles: submission.participants.roles,
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(request.validateSync()).toBeUndefined();
|
|
expect(request.parties[0].person.insurerBirthday).toBe("1378/06/27");
|
|
expect(request.parties[0].person.driverBirthday).toBe("1378/04/26");
|
|
expect(request.parties[0].participants?.[0].driverLicenseDate).toBe(
|
|
"1400/01/01",
|
|
);
|
|
});
|
|
|
|
it("recasts populated party subdocuments during an inquiry-audit update", () => {
|
|
const BlameRequestModel = model<BlameRequest>(
|
|
"InquiryParticipantAuditPersistenceTest",
|
|
BlameRequestSchema,
|
|
);
|
|
const request = new BlameRequestModel({
|
|
requestNo: "BL-PARTICIPANT-AUDIT",
|
|
publicId: "PARTICIPANT-AUDIT",
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
person: {
|
|
userId: new Types.ObjectId(),
|
|
phoneNumber: "09120723528",
|
|
},
|
|
statement: {
|
|
acceptsExpertOpinion: false,
|
|
claimsDamage: false,
|
|
admitsGuilt: true,
|
|
},
|
|
participants: [
|
|
{
|
|
participantId: "DRIVER",
|
|
nationalCode: "0022324224",
|
|
birthday: "1378/04/26",
|
|
hasDrivingLicense: true,
|
|
driverLicenseDate: "1400/01/01",
|
|
licenseNumber: "1001011111",
|
|
licenseType: "10",
|
|
},
|
|
],
|
|
participantRoles: {
|
|
driver: "DRIVER",
|
|
vehicleOwner: "DRIVER",
|
|
thirdPartyPolicyholder: "DRIVER",
|
|
},
|
|
vehicle: {
|
|
registrationState: "CURRENT",
|
|
plateId: "78-59-ی-419",
|
|
},
|
|
},
|
|
],
|
|
inquiries: {},
|
|
});
|
|
const query = BlameRequestModel.findByIdAndUpdate(request._id, {
|
|
$set: {
|
|
inquiries: request.inquiries,
|
|
parties: request.parties,
|
|
},
|
|
});
|
|
|
|
expect(() => (query as any)._castUpdate(query.getUpdate())).not.toThrow();
|
|
});
|
|
|
|
it("stores the previous policyholder national code with transferred vehicle data", () => {
|
|
const BlameRequestModel = model<BlameRequest>(
|
|
"PreviousPolicyholderPersistenceTest",
|
|
BlameRequestSchema,
|
|
);
|
|
const request = new BlameRequestModel({
|
|
requestNo: "BL-PREVIOUS-POLICYHOLDER",
|
|
publicId: "PREVIOUS-POLICYHOLDER",
|
|
type: BlameRequestType.THIRD_PARTY,
|
|
parties: [
|
|
{
|
|
role: PartyRole.FIRST,
|
|
person: {},
|
|
vehicle: {
|
|
plateId: "22-44-ب-111",
|
|
previousPlateId: "33-55-ج-222",
|
|
previousPolicyholderNationalCode: "0098765432",
|
|
registrationState: "RECENTLY_TRANSFERRED",
|
|
vin: "NAAM01E15HK123456",
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(request.validateSync()).toBeUndefined();
|
|
expect(request.parties[0].vehicle?.previousPolicyholderNationalCode).toBe(
|
|
"0098765432",
|
|
);
|
|
});
|
|
});
|