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:
2026-05-06 19:04:33 +02:00
parent e6560bc9cb
commit 10479c4d55
16 changed files with 603 additions and 4 deletions

View File

@@ -0,0 +1,46 @@
import { marketingPagesContainer } from "./container.js";
import { MARKETING_PAGES_SYMBOLS } from "./symbols.js";
import { MockPagesRepository } from "../infrastructure/repositories/pages.repository.mock.js";
import { buildDevPages, buildDevSiteSettings } from "../__seeds__/dev.js";
import type { IPagesRepository } from "../application/repositories/pages.repository.interface.js";
import type { ISiteSettingsRepository } from "../application/repositories/site-settings.repository.interface.js";
/**
* Replace the default empty mocks with populated ones for dev mode + storybook.
*
* Call this from app boot when `USE_DEV_SEED=true`, mutually exclusive with
* `bindProductionMarketingPages(config)`. Tests must NOT call this — they
* construct mocks directly and seed via factories per-test.
*
* Idempotent: safe to call multiple times; each call rebuilds fresh populated
* repos and rebinds both symbols.
*/
export async function bindDevSeedMarketingPages(): Promise<void> {
// Pages repository — MockPagesRepository accepts an initial array.
if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.IPagesRepository)) {
marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.IPagesRepository);
}
marketingPagesContainer
.bind<IPagesRepository>(MARKETING_PAGES_SYMBOLS.IPagesRepository)
.toConstantValue(new MockPagesRepository(buildDevPages()));
// Site settings repository — MockSiteSettingsRepository has no mutable
// storage so we bind a constant-value implementation directly.
if (
marketingPagesContainer.isBound(
MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository,
)
) {
marketingPagesContainer.unbind(
MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository,
);
}
const settings = buildDevSiteSettings();
marketingPagesContainer
.bind<ISiteSettingsRepository>(MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository)
.toConstantValue({
getSiteSettings: async () => settings,
});
}