import { blogContainer } from "./container.js"; import { BLOG_SYMBOLS } from "./symbols.js"; import { MockArticlesRepository } from "../infrastructure/repositories/articles.repository.mock.js"; import { buildDevArticles } from "../__seeds__/dev.js"; import type { IArticlesRepository } from "../application/repositories/articles.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 * `bindProductionBlog(config)`. Tests must NOT call this — they construct * `new MockArticlesRepository()` 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 bindDevSeedBlog(): Promise { if (blogContainer.isBound(BLOG_SYMBOLS.IArticlesRepository)) { blogContainer.unbind(BLOG_SYMBOLS.IArticlesRepository); } const repo = new MockArticlesRepository(); for (const article of buildDevArticles()) { await repo.createArticle(article); } blogContainer .bind(BLOG_SYMBOLS.IArticlesRepository) .toConstantValue(repo); }