Files
TREK/server/tests/helpers/module-providers.ts
Maurice d4a1601855 Give the packing templates and the feature flags back to their domains
Twelve admin packing-template routes sat on AdminController and reached
PackingService through eleven pass-through methods on AdminService that did
nothing but forward and cast. PackingService already owns all three template
tables, so the routes move to AdminPackingTemplatesController next to it and the
pass-through block is gone. AdminService no longer injects PackingService at all.

The three places flags were raw app_settings SQL on AdminService, sitting beside
bag-tracking and collab-features which it already delegated to AddonsService.
They move to AddonsService, which owns every other flag, and AdminController now
calls it directly rather than through delegating methods.

The toggle ROUTES stay on AdminController, which is a departure from the plan and
worth stating: an admin-gated controller in AddonsModule makes that module import
AuthModule, and PluginGuardsModule imports AddonsModule precisely because it is a
leaf — Nest refused to build the graph. Same for the addon CRUD, whose PUT
cascades into PluginRuntimeService. Both notes are in the code.

Paths, response shapes, the {error,status} envelope, the create-201 split and
every audit action are unchanged.
2026-08-09 20:54:39 +02:00

29 lines
1.5 KiB
TypeScript

import { expect } from 'vitest';
/**
* Asserts that `moduleClass` lists `provider` in its `providers: []`.
*
* This is the one failure the compiler cannot see: a `@PluginController()` or
* `@McpController()` class that no module registers is invisible to discovery, and
* every call to it comes back PERMISSION_DENIED with no other symptom.
*
* It is a helper rather than an inline `expect(...).toContain(...)` because that form
* is unsound here. `Reflect.getMetadata('providers', M)` is `undefined` for a module
* declared without a `providers` key, and `expect(undefined).toContain(SomeClass)`
* PASSES in this vitest version (it only throws for a string needle). Every guard
* written that way silently stopped guarding the moment its class moved to another
* module. Asserting the array shape first is what makes the check real.
*/
export function expectRegisteredProvider(moduleClass: object, provider: object): void {
const providers = Reflect.getMetadata('providers', moduleClass) as unknown[] | undefined;
expect(Array.isArray(providers)).toBe(true);
expect(providers).toEqual(expect.arrayContaining([provider]));
}
/** The same check for a module's `controllers: []`, with the same soundness caveat. */
export function expectRegisteredController(moduleClass: object, controller: object): void {
const controllers = Reflect.getMetadata('controllers', moduleClass) as unknown[] | undefined;
expect(Array.isArray(controllers)).toBe(true);
expect(controllers).toEqual(expect.arrayContaining([controller]));
}