forked from Yara724/api
Implement role-complete inquiry participants
This commit is contained in:
264
src/request-management/inquiry-participant-resolver.spec.ts
Normal file
264
src/request-management/inquiry-participant-resolver.spec.ts
Normal file
@@ -0,0 +1,264 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||
import {
|
||||
InquiryParticipantRole,
|
||||
VehicleRegistrationState,
|
||||
} from "./dto/inquiry-participants.dto";
|
||||
import {
|
||||
assertPreviousPlateInquiryMatchesVin,
|
||||
normalizeInquirySubmission,
|
||||
participantForRole,
|
||||
resolveInquiryParticipants,
|
||||
resolveInquiryVehicle,
|
||||
runPlateInquiryWithFallback,
|
||||
vehiclePlateCandidates,
|
||||
} from "./inquiry-participant-resolver";
|
||||
|
||||
describe("inquiry participant resolver", () => {
|
||||
it("links several roles to one explicitly shared person", () => {
|
||||
const resolved = resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: true,
|
||||
licenseNumber: "123456789",
|
||||
licenseType: "1",
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
sameAs: InquiryParticipantRole.VEHICLE_OWNER,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resolved.participants).toHaveLength(1);
|
||||
expect(resolved.roles).toEqual({
|
||||
driver: "DRIVER",
|
||||
vehicleOwner: "DRIVER",
|
||||
thirdPartyPolicyholder: "DRIVER",
|
||||
});
|
||||
});
|
||||
|
||||
it("requires both previous plate and VIN for a recent transfer", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("keeps legacy driver/policyholder payloads working during rollout", () => {
|
||||
const resolved = resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
nationalCodeOfDriver: "0012345678",
|
||||
driverBirthday: "1370/01/01",
|
||||
driverLicense: "123456789",
|
||||
nationalCodeOfInsurer: "0098765432",
|
||||
insurerBirthday: "1360/02/02",
|
||||
driverIsInsurer: false,
|
||||
} as any);
|
||||
|
||||
expect(resolved.legacy).toBe(true);
|
||||
expect(resolved.roles.driver).toBe("DRIVER");
|
||||
expect(resolved.roles.thirdPartyPolicyholder).toBe(
|
||||
"THIRD_PARTY_POLICYHOLDER",
|
||||
);
|
||||
expect(resolved.roles.vehicleOwner).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps third-party and car-body policyholders distinct", () => {
|
||||
const resolved = resolveInquiryParticipants(BlameRequestType.CAR_BODY, {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
nationalCode: "0023456789",
|
||||
birthday: "1360/02/02",
|
||||
},
|
||||
carBodyPolicyholder: {
|
||||
nationalCode: "0034567890",
|
||||
birthday: "1350/03/03",
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
participantForRole(
|
||||
resolved,
|
||||
InquiryParticipantRole.THIRD_PARTY_POLICYHOLDER,
|
||||
)?.nationalCode,
|
||||
).toBe("0023456789");
|
||||
expect(
|
||||
participantForRole(resolved, InquiryParticipantRole.CAR_BODY_POLICYHOLDER)
|
||||
?.nationalCode,
|
||||
).toBe("0034567890");
|
||||
});
|
||||
|
||||
it("projects role-complete input onto the existing inquiry fields", () => {
|
||||
const normalized = normalizeInquirySubmission(BlameRequestType.CAR_BODY, {
|
||||
plate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: true,
|
||||
licenseNumber: "D-1",
|
||||
licenseType: "1",
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
nationalCode: "0023456789",
|
||||
birthday: "1360/02/02",
|
||||
},
|
||||
carBodyPolicyholder: {
|
||||
nationalCode: "0034567890",
|
||||
birthday: "1350/03/03",
|
||||
},
|
||||
});
|
||||
|
||||
expect(normalized.dto.nationalCodeOfInsurer).toBe("0023456789");
|
||||
expect(normalized.dto.nationalCodeOfDriver).toBe("0012345678");
|
||||
expect(normalized.carBodyPolicyholder?.nationalCode).toBe("0034567890");
|
||||
expect(normalized.vehicleOwner?.nationalCode).toBe("0012345678");
|
||||
});
|
||||
|
||||
it("orders the current plate before the previous-plate fallback", () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
};
|
||||
const previousPlate = {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
};
|
||||
|
||||
expect(
|
||||
vehiclePlateCandidates({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
}),
|
||||
).toEqual([
|
||||
{ kind: "CURRENT", plate: currentPlate },
|
||||
{ kind: "PREVIOUS", plate: previousPlate },
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects a previous-plate result for another chassis", () => {
|
||||
expect(() =>
|
||||
assertPreviousPlateInquiryMatchesVin("NAAM01E15HK123456", {
|
||||
VinNumberField: "DIFFERENTVIN00001",
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("requires the driver's licence status in the new contract", () => {
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
driver: { nationalCode: "0012345678", birthday: "1370/01/01" },
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
sameAs: InquiryParticipantRole.VEHICLE_OWNER,
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("falls back to the previous plate and accepts only a matching VIN", async () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
};
|
||||
const previousPlate = {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
};
|
||||
const query = jest
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error("not found"))
|
||||
.mockResolvedValueOnce({
|
||||
mapped: { VinNumberField: "NAAM01E15HK123456", CompanyName: "پارسیان" },
|
||||
});
|
||||
|
||||
const result = await runPlateInquiryWithFallback<{
|
||||
mapped: { VinNumberField?: string; CompanyName?: string };
|
||||
}>({
|
||||
vehicle: {
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
},
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
isUsable: (value) => !!value.mapped.CompanyName,
|
||||
mappedValue: (value) => value.mapped,
|
||||
});
|
||||
|
||||
expect(query).toHaveBeenCalledTimes(2);
|
||||
expect(result.plateKind).toBe("PREVIOUS");
|
||||
expect(result.attempts).toEqual([
|
||||
{ plateKind: "CURRENT", succeeded: false, error: "not found" },
|
||||
{ plateKind: "PREVIOUS", succeeded: true, usable: true },
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects a car-body policyholder on a third-party case", () => {
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
sameAs: InquiryParticipantRole.VEHICLE_OWNER,
|
||||
},
|
||||
carBodyPolicyholder: {
|
||||
nationalCode: "0034567890",
|
||||
birthday: "1350/03/03",
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("does not accept a previous plate unless recent transfer is declared", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.CURRENT,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
previousPlate: {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user