## Summary Introduces a new `representation-policy` domain boundary and incrementally extracts low-risk representation entry policy logic while preserving existing behaviour. This PR intentionally stops before extracting ROW and Advert entry rules because characterization uncovered behavioural differences between consumers that require a separate business decision. ## What Changed Added: ```text lib/domain/representation-policy/ ``` Including: - `resolveRepresentationWindow(...)` - `isRepresentationWindowOpen(...)` - `isRepresentationWindowClosed(...)` - `canShowRepresentationButtonForAppealType(...)` - `canStartHouseholderRepresentation(...)` - `canStartCpoRepresentation(...)` Updated consumers: ```text components/case/summary/utils/representationEntry.js components/search/repsonresults.js ``` ## Extracted Behaviour ### Representation Window Calculation Centralised shared representation window logic and adopted it in both consumers. ### Appeal Type Entry Gating Centralised excluded appeal-type logic while preserving existing behaviour. ### Householder Rule Centralised Householder (`846040004`) entry rule. Preserved behaviour: ```text Householder representations can only be started by LPAs. ``` ### CPO Rule Centralised CPO (`846040019`) entry rule. Preserved behaviour using: ```text pinswg_startdate pinswg_statementduedate ``` No fallback date broadening introduced. ## Characterization Added ### ROW (`846040015`) Documented: - hearing vs non-hearing behaviour - specialist-process field behaviour - date gating - appeal-type coercion behaviour ### Advert (`846040018`) Documented: - LPA/non-LPA behaviour - specialist-process behaviour - appeal-type coercion behaviour ## Important Findings ### ROW Divergence Summary and Search consumers currently behave differently when only: ```text pinswg_speacialistcaseprocess ``` exists. ### Advert Divergence Summary and Search consumers currently use different specialist-process resolution paths. ### CRM Compatibility Both fields remain in production use and must be preserved: ```text pinswg_specialistcaseprocess pinswg_speacialistcaseprocess ``` ## Documentation Added: ```text lib/domain/representation-policy/README.md ``` Documenting: - ownership - non-goals - CRM compatibility requirements - ROW divergence - Advert divergence - future extraction constraints ## Validation Executed during the slice series: ```bash node tests/phase22/representation-window.test.cjs node tests/phase22/representation-appeal-type-entry-gating.test.cjs node tests/phase22/representation-householder-entry-rule.test.cjs node tests/phase22/representation-cpo-entry-rule.test.cjs node tests/phase22/representation-row-entry-rule.test.cjs node tests/phase22/representation-advert-entry-rule.test.cjs npm run lint ``` All passing. ## Out of Scope No changes to: - submission/finalisation - uploads - dashboards - CRM/OData queries - API routes - Redux state - translations - blocked-message rendering - CTA l...
215 lines
6.1 KiB
JavaScript
215 lines
6.1 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const vm = require("vm");
|
|
const assert = require("assert");
|
|
|
|
const rootDir = path.resolve(__dirname, "..", "..");
|
|
|
|
const createFakeDate = (isoString) => {
|
|
const RealDate = Date;
|
|
|
|
function FakeDate(...args) {
|
|
if (!(this instanceof FakeDate)) {
|
|
return new RealDate(...args);
|
|
}
|
|
|
|
if (args.length === 0) {
|
|
return new RealDate(isoString);
|
|
}
|
|
|
|
return new RealDate(...args);
|
|
}
|
|
|
|
FakeDate.UTC = RealDate.UTC;
|
|
FakeDate.parse = RealDate.parse;
|
|
FakeDate.now = () => new RealDate(isoString).getTime();
|
|
FakeDate.prototype = RealDate.prototype;
|
|
|
|
return FakeDate;
|
|
};
|
|
|
|
const loadRepresentationWindowModule = () => {
|
|
const filePath = path.join(
|
|
rootDir,
|
|
"lib",
|
|
"domain",
|
|
"representation-policy",
|
|
"resolveRepresentationWindow.js"
|
|
);
|
|
|
|
let source = fs.readFileSync(filePath, "utf8");
|
|
source = source.replace(
|
|
/export function\s+isRepresentationWindowOpen/,
|
|
"function isRepresentationWindowOpen"
|
|
);
|
|
source = source.replace(
|
|
/export function\s+isRepresentationWindowClosed/,
|
|
"function isRepresentationWindowClosed"
|
|
);
|
|
source = source.replace(
|
|
/export function\s+resolveRepresentationWindow/,
|
|
"function resolveRepresentationWindow"
|
|
);
|
|
source += `
|
|
module.exports = {
|
|
isRepresentationWindowOpen,
|
|
isRepresentationWindowClosed,
|
|
resolveRepresentationWindow
|
|
};
|
|
`;
|
|
|
|
const context = {
|
|
module: { exports: {} },
|
|
exports: {},
|
|
require,
|
|
Date
|
|
};
|
|
|
|
vm.runInNewContext(source, context, { filename: filePath });
|
|
return context.module.exports;
|
|
};
|
|
|
|
const tests = [];
|
|
const test = (name, fn) => tests.push({ name, fn });
|
|
|
|
const {
|
|
isRepresentationWindowOpen,
|
|
isRepresentationWindowClosed,
|
|
resolveRepresentationWindow
|
|
} = loadRepresentationWindowModule();
|
|
|
|
test("general window is open when today falls inclusively between start and end", () => {
|
|
const FakeDate = createFakeDate("2026-04-15T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_startdate: "2026-04-01T00:00:00.000Z",
|
|
pinswg_finalcommentsduedate: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.hasStartDate, true);
|
|
assert.strictEqual(result.startDate, "2026-04-01T00:00:00.000Z");
|
|
assert.strictEqual(result.endDate, "2026-04-30T00:00:00.000Z");
|
|
assert.strictEqual(result.isOpen, true);
|
|
assert.strictEqual(result.isClosed, false);
|
|
});
|
|
|
|
test("general window is not open before the start date", () => {
|
|
const FakeDate = createFakeDate("2026-03-31T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_startdate: "2026-04-01T00:00:00.000Z",
|
|
pinswg_finalcommentsduedate: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.isOpen, false);
|
|
assert.strictEqual(result.isClosed, false);
|
|
});
|
|
|
|
test("general window is closed after the end date", () => {
|
|
const FakeDate = createFakeDate("2026-05-01T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_startdate: "2026-04-01T00:00:00.000Z",
|
|
pinswg_finalcommentsduedate: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.isOpen, false);
|
|
assert.strictEqual(result.isClosed, true);
|
|
});
|
|
|
|
test("missing start-related properties preserve false open state", () => {
|
|
const FakeDate = createFakeDate("2026-04-15T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_finalcommentsduedate: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.hasStartDate, false);
|
|
assert.strictEqual(result.startDate, undefined);
|
|
assert.strictEqual(result.endDate, "2026-04-30T00:00:00.000Z");
|
|
assert.strictEqual(result.isOpen, false);
|
|
assert.strictEqual(result.isClosed, false);
|
|
});
|
|
|
|
test("future window from fallback startdate field preserves open=false closed=false", () => {
|
|
const FakeDate = createFakeDate("2026-04-15T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_startdates: "2026-04-20T00:00:00.000Z",
|
|
pinswg_finalcommentsduedate: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.startDate, "2026-04-20T00:00:00.000Z");
|
|
assert.strictEqual(result.isOpen, false);
|
|
assert.strictEqual(result.isClosed, false);
|
|
});
|
|
|
|
test("application accepted as valid is used as fallback start date with representation-period end date", () => {
|
|
const FakeDate = createFakeDate("2026-04-15T10:00:00.000Z");
|
|
const result = resolveRepresentationWindow(
|
|
{
|
|
pinswg_applicationacceptedasvalid: "2026-04-01T00:00:00.000Z",
|
|
pinswg_endofrepresentationperiod: "2026-04-30T00:00:00.000Z"
|
|
},
|
|
FakeDate
|
|
);
|
|
|
|
assert.strictEqual(result.startDate, "2026-04-01T00:00:00.000Z");
|
|
assert.strictEqual(result.endDate, "2026-04-30T00:00:00.000Z");
|
|
assert.strictEqual(result.isOpen, true);
|
|
assert.strictEqual(result.isClosed, false);
|
|
});
|
|
|
|
test("consultation-like direct window helpers preserve inclusive same-day opening behaviour", () => {
|
|
const FakeDate = createFakeDate("2026-04-30T10:00:00.000Z");
|
|
|
|
assert.strictEqual(
|
|
isRepresentationWindowOpen(
|
|
"2026-04-01T00:00:00.000Z",
|
|
"2026-04-30T00:00:00.000Z",
|
|
FakeDate
|
|
),
|
|
true
|
|
);
|
|
assert.strictEqual(
|
|
isRepresentationWindowClosed(
|
|
"2026-04-01T00:00:00.000Z",
|
|
"2026-04-30T00:00:00.000Z",
|
|
FakeDate
|
|
),
|
|
false
|
|
);
|
|
});
|
|
|
|
const run = async () => {
|
|
let passed = 0;
|
|
|
|
for (const currentTest of tests) {
|
|
await currentTest.fn();
|
|
passed += 1;
|
|
}
|
|
|
|
console.log(
|
|
`Phase 22 representation-window tests passed (${passed}/${tests.length}).`
|
|
);
|
|
};
|
|
|
|
module.exports = run;
|
|
|
|
if (require.main === module) {
|
|
run().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
}
|