feat(features): add test factories to all 5 features
Adds src/__factories__/<entity>.factory.ts to auth, blog, marketing-pages, navigation, media. Each factory uses defineFactory from @repo/core-testing with stable date defaults (2026-01-01) so snapshot diffs reflect SUT behavior only. Refactors mechanical inline-fixture tests to use factories. Also adds vitest.config.ts and tsconfig path alias to @repo/media (lacked both), and adds @repo/core-testing devDependency to @repo/media. Spec: §5.1, §6.3
This commit is contained in:
@@ -3,6 +3,7 @@ import { blogContainer } from "../../di/container";
|
||||
import { BLOG_SYMBOLS } from "../../di/symbols";
|
||||
import type { IArticlesRepository } from "../../application/repositories/articles-repository.interface";
|
||||
import { MockArticlesRepository } from "../../infrastructure/repositories/mock-articles.repository";
|
||||
import { articleFactory } from "../../__factories__/article.factory";
|
||||
import { getArticlesUseCase } from "./get-articles.use-case";
|
||||
|
||||
describe("getArticlesUseCase", () => {
|
||||
@@ -16,47 +17,19 @@ describe("getArticlesUseCase", () => {
|
||||
blogContainer
|
||||
.bind<IArticlesRepository>(BLOG_SYMBOLS.IArticlesRepository)
|
||||
.toConstantValue(repo);
|
||||
articleFactory.reset();
|
||||
});
|
||||
|
||||
it("returns all articles with no filters", async () => {
|
||||
const now = new Date();
|
||||
await repo.createArticle({
|
||||
id: "1",
|
||||
title: "A",
|
||||
slug: "a",
|
||||
content: null,
|
||||
status: "draft",
|
||||
authorId: "u1",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
await repo.createArticle(articleFactory.build({ id: "1", title: "A", slug: "a" }));
|
||||
const result = await getArticlesUseCase();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.id).toBe("1");
|
||||
});
|
||||
|
||||
it("filters by status", async () => {
|
||||
const now = new Date();
|
||||
await repo.createArticle({
|
||||
id: "1",
|
||||
title: "A",
|
||||
slug: "a",
|
||||
content: null,
|
||||
status: "draft",
|
||||
authorId: "u1",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
await repo.createArticle({
|
||||
id: "2",
|
||||
title: "B",
|
||||
slug: "b",
|
||||
content: null,
|
||||
status: "published",
|
||||
authorId: "u1",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
await repo.createArticle(articleFactory.build({ id: "1", title: "A", slug: "a", status: "draft" }));
|
||||
await repo.createArticle(articleFactory.build({ id: "2", title: "B", slug: "b", status: "published" }));
|
||||
const result = await getArticlesUseCase({ status: "published" });
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.id).toBe("2");
|
||||
|
||||
Reference in New Issue
Block a user