feat(blog): add bind-dev-seed binder + dev seed

Sets the canonical pattern for all 5 features. Three new files:

- src/__seeds__/dev.ts — buildDevArticles() function returning 3
  realistic articles (welcome, vertical-feature-architecture,
  wip-post) built from articleFactory with id/slug/title/status
  overrides only.
- src/di/bind-dev-seed.ts — bindDevSeedBlog() async function that
  unbinds IArticlesRepository, constructs MockArticlesRepository,
  seeds it via buildDevArticles(), and rebinds via .toConstantValue.
- src/di/bind-dev-seed.test.ts — 3 tests: populated repo, welcome
  article reachable by slug, idempotent (callable twice).

package.json adds the ./di/bind-dev-seed subpath export, parallel to
./di/bind-production.

Tests + use cases continue to construct MockArticlesRepository
directly — they never go through bindDevSeedBlog. The seed only attaches
when called explicitly at app boot.
This commit is contained in:
2026-05-06 19:00:31 +02:00
parent 449a4aedf5
commit e6560bc9cb
4 changed files with 138 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
import { articleFactory } from "../__factories__/article.factory.js";
import type { Article } from "../entities/models/article.js";
/**
* Realistic blog seed for dev mode + storybook stories.
*
* Built from `articleFactory` so factory defaults take care of the boring
* fields (createdAt, updatedAt, content, authorId) and we only override what
* makes the data look like a populated database.
*
* Lazily produced so importing this module is side-effect-free — the factory's
* sequence counter only advances when a binder calls `buildDevArticles()`.
*/
export function buildDevArticles(): Article[] {
return [
articleFactory.build({
id: "welcome",
slug: "welcome",
title: "Welcome to the blog",
status: "published",
}),
articleFactory.build({
id: "vertical-feature-architecture",
slug: "vertical-feature-architecture",
title: "Why vertical-feature packages",
status: "published",
}),
articleFactory.build({
id: "wip-post",
slug: "work-in-progress",
title: "A draft we haven't shipped yet",
status: "draft",
}),
];
}