feat(core): add content controller with tests (articles CRUD)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import "reflect-metadata";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
destroyContainer,
|
||||
initializeContainer,
|
||||
} from "@/di/container.js";
|
||||
import {
|
||||
createArticleController,
|
||||
getArticlesController,
|
||||
} from "@/interface-adapters/controllers/content/articles.controller.js";
|
||||
import { InputParseError } from "@/entities/errors/common.js";
|
||||
|
||||
beforeEach(() => {
|
||||
initializeContainer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
destroyContainer();
|
||||
});
|
||||
|
||||
describe("createArticleController", () => {
|
||||
it("creates an article with valid input", async () => {
|
||||
const result = await createArticleController({
|
||||
title: "Test Article",
|
||||
content: "Some content",
|
||||
authorId: "1",
|
||||
});
|
||||
expect(result.title).toBe("Test Article");
|
||||
expect(result.slug).toBe("test-article");
|
||||
});
|
||||
|
||||
it("throws InputParseError for missing title", async () => {
|
||||
await expect(
|
||||
createArticleController({ content: "content", authorId: "1" } as any)
|
||||
).rejects.toBeInstanceOf(InputParseError);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getArticlesController", () => {
|
||||
it("returns articles", async () => {
|
||||
await createArticleController({
|
||||
title: "Article",
|
||||
content: "Content",
|
||||
authorId: "1",
|
||||
});
|
||||
const result = await getArticlesController({});
|
||||
expect(result).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user