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 { // Pages repository — MockPagesRepository accepts an initial array. if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.IPagesRepository)) { marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.IPagesRepository); } marketingPagesContainer .bind(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(MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository) .toConstantValue({ getSiteSettings: async () => settings, }); }