feat(features): add bind-dev-seed binders for auth/marketing-pages/navigation/media
Mirrors the canonical blog pattern landed earlier on this branch. Per feature: - src/__seeds__/dev.ts — lazy buildDev<Entities>() function using the feature's existing factory for sensible defaults - src/di/bind-dev-seed.ts — bindDevSeed<Feature>() async function that rebinds the repo symbol(s) to a populated MockXRepository via .toConstantValue - src/di/bind-dev-seed.test.ts — 3+ tests per feature (populates, reachable by id/slug, idempotent) - package.json — adds ./di/bind-dev-seed subpath export Tests + use cases continue to construct mocks directly; the seed never runs from a *.test.ts path. App boot wiring (USE_DEV_SEED env branch) follows in a separate commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
30
packages/media/src/di/bind-dev-seed.ts
Normal file
30
packages/media/src/di/bind-dev-seed.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { mediaContainer } from "./container.js";
|
||||
import { MEDIA_SYMBOLS } from "./symbols.js";
|
||||
import { MockMediaRepository } from "../infrastructure/repositories/media.repository.mock.js";
|
||||
import { buildDevMedia } from "../__seeds__/dev.js";
|
||||
import type { IMediaRepository } from "../application/repositories/media.repository.interface.js";
|
||||
|
||||
/**
|
||||
* Replace the default empty mock with a populated one for dev mode + storybook.
|
||||
*
|
||||
* Call this from app boot when `USE_DEV_SEED=true`, mutually exclusive with
|
||||
* `bindProductionMedia(config)`. Tests must NOT call this — they construct
|
||||
* `new MockMediaRepository()` directly and seed via factories per-test.
|
||||
*
|
||||
* Idempotent: safe to call multiple times; each call rebuilds a fresh
|
||||
* populated repo and rebinds the symbol.
|
||||
*/
|
||||
export async function bindDevSeedMedia(): Promise<void> {
|
||||
if (mediaContainer.isBound(MEDIA_SYMBOLS.IMediaRepository)) {
|
||||
mediaContainer.unbind(MEDIA_SYMBOLS.IMediaRepository);
|
||||
}
|
||||
|
||||
const repo = new MockMediaRepository();
|
||||
for (const media of buildDevMedia()) {
|
||||
await repo._store(media);
|
||||
}
|
||||
|
||||
mediaContainer
|
||||
.bind<IMediaRepository>(MEDIA_SYMBOLS.IMediaRepository)
|
||||
.toConstantValue(repo);
|
||||
}
|
||||
Reference in New Issue
Block a user