fix(car-body): validate policy coverage on accident date

Validate hull coverage against the accident date, select the covering renewal, and defer validation until that date is collected.
This commit is contained in:
2026-11-21 12:04:09 +03:30
parent 8f15040080
commit 5c6e21dd14
13 changed files with 499 additions and 56 deletions
@@ -1,5 +1,8 @@
import { BadRequestException } from "@nestjs/common";
import { selectLatestActiveFanavaranPolicy } from "./fanavaran-policy-selection";
import {
selectLatestActiveFanavaranPolicy,
selectFanavaranPolicyForAccident,
} from "./fanavaran-policy-selection";
describe("selectLatestActiveFanavaranPolicy", () => {
const today = "2026-06-30";
@@ -61,3 +64,29 @@ describe("selectLatestActiveFanavaranPolicy", () => {
).toThrow(BadRequestException);
});
});
describe("car-body accident policy selection", () => {
const policies = [
{ PolicyId: 2, BeginDate: "1401/01/02", EndDate: "1402/01/02" },
{ PolicyId: 1, BeginDate: "1400/01/01", EndDate: "1401/01/01" },
];
it("selects the previous renewal covering the accident, even when both expired today", () => {
expect(
selectFanavaranPolicyForAccident(policies, "1400/12/28").policyId,
).toBe(1);
});
it.each(["1400/01/01", "1401/01/01"])(
"includes the coverage boundary %s",
(date) => {
expect(selectFanavaranPolicyForAccident(policies, date).policyId).toBe(1);
},
);
it.each(["1399/12/29", "1402/01/03", "invalid", undefined])(
"rejects an uncovered or missing accident date %s",
(date) => {
expect(() => selectFanavaranPolicyForAccident(policies, date)).toThrow(
BadRequestException,
);
},
);
});