forked from Yara724/api
Fixed Participants
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
resolveInquirySubjects,
|
||||
resolveInquiryVehicle,
|
||||
runPlateInquiryWithFallback,
|
||||
sanitizeStoredInquiryParticipants,
|
||||
vehiclePlateCandidates,
|
||||
} from "./inquiry-participant-resolver";
|
||||
|
||||
@@ -55,6 +56,27 @@ describe("inquiry participant resolver", () => {
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("requires the previous policyholder national code for a recent transfer", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
previousPlate: {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
},
|
||||
vin: "NAAM01E15HK123456",
|
||||
}),
|
||||
).toThrow("previousPolicyholderNationalCode");
|
||||
});
|
||||
|
||||
it("defaults an omitted registration state to CURRENT", () => {
|
||||
expect(
|
||||
resolveInquiryVehicle({
|
||||
@@ -68,6 +90,75 @@ describe("inquiry participant resolver", () => {
|
||||
).toBe(VehicleRegistrationState.CURRENT);
|
||||
});
|
||||
|
||||
it("requires an exact 17-character VIN whenever VIN is provided", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.CURRENT,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
vin: "TOO-SHORT",
|
||||
}),
|
||||
).toThrow("vehicle.vin must contain exactly 17 characters.");
|
||||
});
|
||||
|
||||
it("rejects an incomplete current plate", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "",
|
||||
ir: "22",
|
||||
},
|
||||
}),
|
||||
).toThrow("vehicle.currentPlate.centerDigits is required.");
|
||||
});
|
||||
|
||||
it("rejects invalid vehicle choice values", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: "SOLD" as any,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
}),
|
||||
).toThrow("vehicle.registrationState must be CURRENT or RECENTLY_TRANSFERRED.");
|
||||
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
isNewCar: "false" as any,
|
||||
}),
|
||||
).toThrow("vehicle.isNewCar must be a boolean.");
|
||||
});
|
||||
|
||||
it("rejects a previous policyholder national code for a current registration", () => {
|
||||
expect(() =>
|
||||
resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.CURRENT,
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("rejects the removed flat inquiry contract", () => {
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
@@ -238,6 +329,7 @@ describe("inquiry participant resolver", () => {
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
).toEqual([
|
||||
{ kind: "CURRENT", plate: currentPlate },
|
||||
@@ -293,6 +385,7 @@ describe("inquiry participant resolver", () => {
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
},
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
@@ -301,6 +394,8 @@ describe("inquiry participant resolver", () => {
|
||||
});
|
||||
|
||||
expect(query).toHaveBeenCalledTimes(2);
|
||||
expect(query).toHaveBeenNthCalledWith(1, currentPlate, "CURRENT");
|
||||
expect(query).toHaveBeenNthCalledWith(2, previousPlate, "PREVIOUS");
|
||||
expect(result.plateKind).toBe("PREVIOUS");
|
||||
expect(result.attempts).toMatchObject([
|
||||
{ plateKind: "CURRENT", succeeded: false, error: "not found" },
|
||||
@@ -449,6 +544,7 @@ describe("inquiry participant resolver", () => {
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
@@ -487,6 +583,7 @@ describe("inquiry participant resolver", () => {
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query: async () => ({ mapped: { CompanyName: "پارسیان" } }),
|
||||
@@ -526,6 +623,7 @@ describe("inquiry participant resolver", () => {
|
||||
ir: "33",
|
||||
},
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
@@ -536,7 +634,7 @@ describe("inquiry participant resolver", () => {
|
||||
expect(query).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("allows an explicitly unknown policyholder only for a damaged-party submission", () => {
|
||||
it("rejects the removed unknown policyholder option", () => {
|
||||
const input = {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
@@ -548,19 +646,24 @@ describe("inquiry participant resolver", () => {
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, input),
|
||||
).toThrow(BadRequestException);
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, input as any),
|
||||
).toThrow("THIRD_PARTY_POLICYHOLDER does not support the unknown option.");
|
||||
});
|
||||
|
||||
const resolved = resolveInquiryParticipants(
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
input,
|
||||
{ allowUnknownThirdPartyPolicyholder: true },
|
||||
);
|
||||
it("strips the removed unknown field from historical participant output", () => {
|
||||
expect(
|
||||
participantForRole(
|
||||
resolved,
|
||||
InquiryParticipantRole.THIRD_PARTY_POLICYHOLDER,
|
||||
),
|
||||
).toMatchObject({ unknown: true });
|
||||
sanitizeStoredInquiryParticipants([
|
||||
{
|
||||
participantId: "THIRD_PARTY_POLICYHOLDER",
|
||||
nationalCode: "0012345678",
|
||||
unknown: true,
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
participantId: "THIRD_PARTY_POLICYHOLDER",
|
||||
nationalCode: "0012345678",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user