feat(blog): add getArticlesUseCase (test red until DI + mock repo exist)
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
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 { getArticlesUseCase } from "./get-articles.use-case";
|
||||
|
||||
describe("getArticlesUseCase", () => {
|
||||
let repo: MockArticlesRepository;
|
||||
|
||||
beforeEach(() => {
|
||||
if (blogContainer.isBound(BLOG_SYMBOLS.IArticlesRepository)) {
|
||||
blogContainer.unbind(BLOG_SYMBOLS.IArticlesRepository);
|
||||
}
|
||||
repo = new MockArticlesRepository();
|
||||
blogContainer
|
||||
.bind<IArticlesRepository>(BLOG_SYMBOLS.IArticlesRepository)
|
||||
.toConstantValue(repo);
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
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,
|
||||
});
|
||||
const result = await getArticlesUseCase({ status: "published" });
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.id).toBe("2");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user