feat(blog): add tRPC router with articleBySlug + listArticles + createArticle
This commit is contained in:
51
packages/blog/src/integrations/api/router.test.ts
Normal file
51
packages/blog/src/integrations/api/router.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { blogContainer } from "@/di/container";
|
||||
import { BLOG_SYMBOLS } from "@/di/symbols";
|
||||
import { MockArticlesRepository } from "@/infrastructure/repositories/mock-articles.repository";
|
||||
import type { IArticlesRepository } from "@/application/repositories/articles-repository.interface";
|
||||
import { blogRouter } from "./router";
|
||||
|
||||
describe("blogRouter", () => {
|
||||
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("exposes articleBySlug, listArticles, createArticle procedures", () => {
|
||||
const procedureNames = Object.keys(blogRouter._def.procedures);
|
||||
expect(procedureNames).toContain("articleBySlug");
|
||||
expect(procedureNames).toContain("listArticles");
|
||||
expect(procedureNames).toContain("createArticle");
|
||||
});
|
||||
|
||||
it("articleBySlug returns the article when present", async () => {
|
||||
const now = new Date();
|
||||
await repo.createArticle({
|
||||
id: "1",
|
||||
title: "T",
|
||||
slug: "t",
|
||||
content: null,
|
||||
status: "draft",
|
||||
authorId: "u1",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
|
||||
const caller = blogRouter.createCaller({});
|
||||
const result = await caller.articleBySlug({ slug: "t" });
|
||||
expect(result?.id).toBe("1");
|
||||
});
|
||||
|
||||
it("listArticles returns all articles when no input is given", async () => {
|
||||
const caller = blogRouter.createCaller({});
|
||||
const result = await caller.listArticles();
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user