Files
pedwfrontend/tests/phase22/representation-appeal-type-entry-gating.test.cjs
T
Robert Bond c39e4bcc9a Merged PR 2375: update representation policy
## 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...
2026-06-08 10:51:02 +00:00

127 lines
3.3 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const vm = require("vm");
const assert = require("assert");
const rootDir = path.resolve(__dirname, "..", "..");
const loadGatingModule = () => {
const filePath = path.join(
rootDir,
"lib",
"domain",
"representation-policy",
"canShowRepresentationButtonForAppealType.js"
);
let source = fs.readFileSync(filePath, "utf8");
source = source.replace(
/export function\s+canShowRepresentationButtonForAppealType/,
"function canShowRepresentationButtonForAppealType"
);
source += `
module.exports = {
canShowRepresentationButtonForAppealType
};
`;
const context = {
module: { exports: {} },
exports: {},
require,
Number,
Set
};
vm.runInNewContext(source, context, { filename: filePath });
return context.module.exports;
};
const tests = [];
const test = (name, fn) => tests.push({ name, fn });
const { canShowRepresentationButtonForAppealType } = loadGatingModule();
const excludedAppealTypes = [
846040012, 846040013, 846040014, 846040020, 846040021, 846040023, 846040024
];
test("excluded appeal types return false", () => {
for (const appealType of excludedAppealTypes) {
assert.strictEqual(
canShowRepresentationButtonForAppealType(appealType),
false,
`Expected excluded appeal type ${appealType} to return false`
);
}
});
test("representative allowed appeal types return true", () => {
for (const appealType of [
846040002, 846040004, 846040011, 846040015, 846040018, 846040019
]) {
assert.strictEqual(
canShowRepresentationButtonForAppealType(appealType),
true,
`Expected allowed appeal type ${appealType} to return true`
);
}
});
test("unknown appeal types preserve default allowed behaviour", () => {
assert.strictEqual(
canShowRepresentationButtonForAppealType(999999999),
true
);
assert.strictEqual(canShowRepresentationButtonForAppealType(-1), true);
});
test("null and undefined preserve default allowed behaviour", () => {
assert.strictEqual(canShowRepresentationButtonForAppealType(null), true);
assert.strictEqual(
canShowRepresentationButtonForAppealType(undefined),
true
);
});
test("string and number appeal type values behave the same", () => {
assert.strictEqual(
canShowRepresentationButtonForAppealType("846040012"),
false
);
assert.strictEqual(
canShowRepresentationButtonForAppealType("846040002"),
true
);
});
test("non-numeric strings preserve default allowed behaviour", () => {
assert.strictEqual(
canShowRepresentationButtonForAppealType("unknown"),
true
);
assert.strictEqual(canShowRepresentationButtonForAppealType(""), true);
});
const run = async () => {
let passed = 0;
for (const currentTest of tests) {
await currentTest.fn();
passed += 1;
}
console.log(
`Phase 22 representation-appeal-type-entry-gating tests passed (${passed}/${tests.length}).`
);
};
module.exports = run;
if (require.main === module) {
run().catch((error) => {
console.error(error);
process.exit(1);
});
}