forked from Yara724/api
fix: query policies only for current holder
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
VehicleRegistrationState,
|
||||
} from "src/common/dto/inquiry-participants.dto";
|
||||
import {
|
||||
assertPreviousPlateInquiryMatchesVin,
|
||||
isMappedPolicyCurrent,
|
||||
normalizeInquirySubmission,
|
||||
participantForRole,
|
||||
@@ -13,9 +12,8 @@ import {
|
||||
resolveInquiryParticipants,
|
||||
resolveInquirySubjects,
|
||||
resolveInquiryVehicle,
|
||||
runPlateInquiryWithFallback,
|
||||
runCurrentPlateInquiry,
|
||||
sanitizeStoredInquiryParticipants,
|
||||
vehiclePlateCandidates,
|
||||
} from "./inquiry-participant-resolver";
|
||||
|
||||
describe("inquiry participant resolver", () => {
|
||||
@@ -309,42 +307,6 @@ describe("inquiry participant resolver", () => {
|
||||
).toBe("0022222222");
|
||||
});
|
||||
|
||||
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",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
).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, {
|
||||
@@ -357,58 +319,36 @@ describe("inquiry participant resolver", () => {
|
||||
).toThrow(BadRequestException);
|
||||
});
|
||||
|
||||
it("falls back to the previous plate and accepts only a matching VIN", async () => {
|
||||
it("runs only one inquiry for the current plate", 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",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
},
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
query,
|
||||
isUsable: (value) => !!value.mapped.CompanyName,
|
||||
mappedValue: (value) => value.mapped,
|
||||
const query = jest.fn().mockResolvedValue({
|
||||
mapped: { CompanyName: "پارسیان" },
|
||||
});
|
||||
|
||||
expect(query).toHaveBeenCalledTimes(2);
|
||||
expect(query).toHaveBeenNthCalledWith(1, currentPlate, "CURRENT");
|
||||
expect(query).toHaveBeenNthCalledWith(2, previousPlate, "PREVIOUS");
|
||||
expect(result.plateKind).toBe("PREVIOUS");
|
||||
const result = await runCurrentPlateInquiry<{
|
||||
mapped: { CompanyName?: string };
|
||||
}>({
|
||||
currentPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
query,
|
||||
isUsable: (value) => !!value.mapped.CompanyName,
|
||||
});
|
||||
|
||||
expect(query).toHaveBeenCalledTimes(1);
|
||||
expect(query).toHaveBeenCalledWith(currentPlate);
|
||||
expect(result.plateKind).toBe("CURRENT");
|
||||
expect(result.attempts).toMatchObject([
|
||||
{ plateKind: "CURRENT", succeeded: false, error: "not found" },
|
||||
{ plateKind: "PREVIOUS", succeeded: true, usable: true },
|
||||
{ plateKind: "CURRENT", succeeded: true, usable: true },
|
||||
]);
|
||||
expect(result.attempts[0]).toMatchObject({
|
||||
plate: currentPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
});
|
||||
expect(result.attempts[1]).toMatchObject({
|
||||
plate: previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a car-body policyholder on a third-party case", () => {
|
||||
@@ -510,95 +450,52 @@ describe("inquiry participant resolver", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back from a stale current policy to a current previous-plate policy", async () => {
|
||||
it("rejects a stale current policy without trying another plate", 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 query = jest.fn().mockResolvedValue({
|
||||
mapped: { CompanyName: "پارسیان", EndDate: "1404/01/01" },
|
||||
});
|
||||
|
||||
const result = await runPlateInquiryWithFallback<{
|
||||
mapped: Record<string, any>;
|
||||
}>({
|
||||
vehicle: resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
await expect(
|
||||
runCurrentPlateInquiry<{ mapped: Record<string, any> }>({
|
||||
currentPlate,
|
||||
previousPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
query,
|
||||
isUsable: (value) =>
|
||||
!!value.mapped.CompanyName &&
|
||||
isMappedPolicyCurrent(value.mapped, "2026-09-13"),
|
||||
}),
|
||||
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,
|
||||
).rejects.toMatchObject({
|
||||
attempts: [{ plateKind: "CURRENT", succeeded: true, usable: false }],
|
||||
});
|
||||
expect(query).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("rejects the result and retains audit attempts when every plate is unusable", async () => {
|
||||
it("retains the current-plate audit attempt when the result 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",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
runCurrentPlateInquiry({
|
||||
currentPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
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 },
|
||||
],
|
||||
attempts: [{ plateKind: "CURRENT", succeeded: true, usable: false }],
|
||||
});
|
||||
});
|
||||
|
||||
it("does not use the previous plate after a transport or provider outage", async () => {
|
||||
it("retains one failed current-plate attempt after a provider outage", async () => {
|
||||
const currentPlate = {
|
||||
leftDigits: "44",
|
||||
centerAlphabet: "ب",
|
||||
@@ -612,23 +509,11 @@ describe("inquiry participant resolver", () => {
|
||||
);
|
||||
|
||||
await expect(
|
||||
runPlateInquiryWithFallback({
|
||||
vehicle: resolveInquiryVehicle({
|
||||
registrationState: VehicleRegistrationState.RECENTLY_TRANSFERRED,
|
||||
currentPlate,
|
||||
previousPlate: {
|
||||
leftDigits: "55",
|
||||
centerAlphabet: "ج",
|
||||
centerDigits: "222",
|
||||
ir: "33",
|
||||
},
|
||||
vin: "NAAM01E15HK123456",
|
||||
previousPolicyholderNationalCode: "0098765432",
|
||||
}),
|
||||
fallbackCurrentPlate: currentPlate,
|
||||
runCurrentPlateInquiry({
|
||||
currentPlate,
|
||||
vin: "NAAM01E15HK123456",
|
||||
query,
|
||||
isUsable: () => false,
|
||||
mappedValue: () => ({}),
|
||||
}),
|
||||
).rejects.toThrow("upstream timeout");
|
||||
expect(query).toHaveBeenCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user