test(medications): reach the actions of moved handler bodies in the activity inventory

The inventory reads a delegated route and its direct imports. With the medication handlers moved into lib/medications, the lifecycle reconciliation a dose write files was two levels from its route and dropped out of the walk. A route's handler-body modules now count at the route's own level, listed in one map whose every entry must be a direct import of its route.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 14:49:42 +02:00
1 parent 24af254249
commit a1ab7136f5
1 file changed
+50
@@ -309,9 +309,44 @@ function actionsReachableFrom(
out.push(...packageActions(reexported, read));
}
}
for (const body of HANDLER_BODY_MODULES[relative(SRC, file)] ?? []) {
out.push(...actionsReachableFrom(join(SRC, body), read));
}
return out;
}
/**
* Delegated routes whose handler bodies live in service modules under
* `src/lib/`, keyed by the route relative to `src/`. A handler body is the
* route's own code moved, so it counts at the route's level: its actions and
* those of its direct imports (the medication lifecycle a dose write
* reconciles through) are reached as they were before the move. Each module
* has to be a direct import of its route (leg below), so an entry cannot
* outlive the delegation it describes.
*/
const HANDLER_BODY_MODULES: Record<string, readonly string[]> = {
"app/api/medications/route.ts": ["lib/medications/create-medication.ts"],
"app/api/medications/[id]/route.ts": [
"lib/medications/read-medication.ts",
"lib/medications/update-medication/update-medication.ts",
"lib/medications/delete-medication.ts",
],
"app/api/medications/[id]/intake/route.ts": [
"lib/medications/record-intake/record-intake.ts",
"lib/medications/list-intake-events.ts",
],
"app/api/medications/[id]/intake/[eventId]/route.ts": [
"lib/medications/update-intake-event.ts",
"lib/medications/delete-intake-event.ts",
],
"app/api/medications/intake/route.ts": [
"lib/medications/intake-today.ts",
"lib/medications/intake-compliance.ts",
"lib/medications/update-intake-status/admission.ts",
"lib/medications/update-intake-status/update-intake-status.ts",
],
};
/**
* The actions of a re-exported module together with the sibling modules it
* imports from its own folder. The re-exported module is a package's public
@@ -553,6 +588,21 @@ describe("every delegated action has a sentence of its own", () => {
expect(manageOnly).not.toContain(anchor);
});
it("reads each moved handler body where its route imports it from", () => {
const entries = Object.entries(HANDLER_BODY_MODULES);
expect(entries.length).toBeGreaterThan(0);
for (const [route, bodies] of entries) {
const file = join(SRC, route);
expect(delegatedModules, route).toContain(file);
for (const body of bodies) {
expect(
read(file).imports,
`${route} does not import ${body}`,
).toContain(join(SRC, body));
}
}
});
it("reaches the actions a route files through what it imports", () => {
// Both halves of the fix, pinned against the two that were invisible.
expect(actions).toContain("medication.intake.import.kickoff.denied");