forked from Yara724/api
Harden inquiry participant edge cases
This commit is contained in:
@@ -3,9 +3,10 @@ import { BlameRequestType } from "src/Types&Enums/blame-request-management/blame
|
||||
import {
|
||||
InquiryParticipantRole,
|
||||
VehicleRegistrationState,
|
||||
} from "./dto/inquiry-participants.dto";
|
||||
} from "src/common/dto/inquiry-participants.dto";
|
||||
import {
|
||||
assertPreviousPlateInquiryMatchesVin,
|
||||
isMappedPolicyCurrent,
|
||||
normalizeInquirySubmission,
|
||||
participantForRole,
|
||||
resolveInquiryParticipants,
|
||||
@@ -52,6 +53,19 @@ describe("inquiry participant resolver", () => {
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("defaults an omitted registration state to CURRENT", () => {
|
||||
expect(
|
||||
resolveInquiryVehicle({
|
||||
currentPlate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
}).registrationState,
|
||||
).toBe(VehicleRegistrationState.CURRENT);
|
||||
});
|
||||
|
||||
it("keeps legacy driver/policyholder payloads working during rollout", () => {
|
||||
const resolved = resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
nationalCodeOfDriver: "0012345678",
|
||||
@@ -261,4 +275,177 @@ describe("inquiry participant resolver", () => {
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("rejects sameAs together with any person-specific fields", () => {
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: {
|
||||
sameAs: InquiryParticipantRole.DRIVER,
|
||||
fullName: "Duplicate details must not be silently discarded",
|
||||
},
|
||||
thirdPartyPolicyholder: {
|
||||
sameAs: InquiryParticipantRole.DRIVER,
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("rejects conflicting legacy and structured current plates", () => {
|
||||
expect(() =>
|
||||
normalizeInquirySubmission(BlameRequestType.THIRD_PARTY, {
|
||||
plate: {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
},
|
||||
vehicle: {
|
||||
registrationState: VehicleRegistrationState.CURRENT,
|
||||
currentPlate: {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
},
|
||||
},
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: {
|
||||
sameAs: InquiryParticipantRole.DRIVER,
|
||||
},
|
||||
}),
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("treats an expired policy result as stale", () => {
|
||||
expect(isMappedPolicyCurrent({ EndDate: "1404/01/01" }, "2026-09-13")).toBe(
|
||||
false,
|
||||
);
|
||||
expect(isMappedPolicyCurrent({ EndDate: "1406/01/01" }, "2026-09-13")).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back from a stale current policy to a current previous-plate policy", async () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
};
|
||||
const previousPlate = {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
};
|
||||
const query = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({
|
||||
mapped: { CompanyName: "پارسیان", EndDate: "1404/01/01" },
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
mapped: {
|
||||
CompanyName: "پارسیان",
|
||||
EndDate: "1406/01/01",
|
||||
VinNumberField: "NAAM01E15HK123456",
|
||||
},
|
||||
});
|
||||
|
||||
const result = await runPlateInquiryWithFallback<{
|
||||
mapped: Record<string, any>;
|
||||
}>({
|
||||
vehicle: resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
isUsable: (value) =>
|
||||
!!value.mapped.CompanyName &&
|
||||
isMappedPolicyCurrent(value.mapped, "2026-09-13"),
|
||||
mappedValue: (value) => value.mapped,
|
||||
});
|
||||
|
||||
expect(result.plateKind).toBe("PREVIOUS");
|
||||
expect(result.attempts[0]).toMatchObject({
|
||||
plateKind: "CURRENT",
|
||||
succeeded: true,
|
||||
usable: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects the result and retains audit attempts when every plate is unusable", async () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
centerDigits: "111",
|
||||
ir: "22",
|
||||
};
|
||||
const previousPlate = {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
};
|
||||
|
||||
await expect(
|
||||
runPlateInquiryWithFallback({
|
||||
vehicle: resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query: async () => ({ mapped: { CompanyName: "پارسیان" } }),
|
||||
isUsable: () => false,
|
||||
mappedValue: (value) => value.mapped,
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
attempts: [
|
||||
{ plateKind: "CURRENT", succeeded: true, usable: false },
|
||||
{ plateKind: "PREVIOUS", succeeded: true, usable: false },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("allows an explicitly unknown policyholder only for a damaged-party submission", () => {
|
||||
const input = {
|
||||
driver: {
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
hasDrivingLicense: false,
|
||||
},
|
||||
vehicleOwner: { sameAs: InquiryParticipantRole.DRIVER },
|
||||
thirdPartyPolicyholder: { unknown: true },
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
resolveInquiryParticipants(BlameRequestType.THIRD_PARTY, input),
|
||||
).toThrow(BadRequestException);
|
||||
|
||||
const resolved = resolveInquiryParticipants(
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
input,
|
||||
{ allowUnknownThirdPartyPolicyholder: true },
|
||||
);
|
||||
expect(
|
||||
participantForRole(
|
||||
resolved,
|
||||
InquiryParticipantRole.THIRD_PARTY_POLICYHOLDER,
|
||||
),
|
||||
).toMatchObject({ unknown: true });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user