에디터 MVP 골격 및 프로젝트 저장/로드 기능 구현
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import "dotenv/config";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { POST as createProject } from "@/app/api/projects/route";
|
||||
import { GET as getProjectBySlug } from "@/app/api/projects/[slug]/route";
|
||||
|
||||
const BASE_URL = "http://localhost";
|
||||
|
||||
describe("/api/projects", () => {
|
||||
it("POST /api/projects 로 프로젝트를 생성하고 GET /api/projects/[slug] 로 조회할 수 있어야 한다", async () => {
|
||||
const payload = {
|
||||
title: "테스트 프로젝트",
|
||||
slug: `test-slug-${Date.now()}`,
|
||||
contentJson: [
|
||||
{
|
||||
id: "blk_test",
|
||||
type: "text",
|
||||
props: { text: "JSON에서 온 텍스트", align: "left", size: "base" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const createResponse = await createProject(
|
||||
new Request(`${BASE_URL}/api/projects`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
);
|
||||
|
||||
if (createResponse.status !== 201) {
|
||||
// 디버깅을 위해 에러 응답을 한번 출력해 둔다.
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("createResponse status", createResponse.status, await createResponse.text());
|
||||
}
|
||||
expect(createResponse.status).toBe(201);
|
||||
const created = (await createResponse.json()) as any;
|
||||
expect(created.title).toBe(payload.title);
|
||||
expect(created.slug).toBe(payload.slug);
|
||||
|
||||
const getResponse = await getProjectBySlug(
|
||||
new Request(`${BASE_URL}/api/projects/${payload.slug}`),
|
||||
{ params: { slug: payload.slug } } as any,
|
||||
);
|
||||
|
||||
expect(getResponse.status).toBe(200);
|
||||
const fetched = (await getResponse.json()) as any;
|
||||
expect(fetched.slug).toBe(payload.slug);
|
||||
expect(fetched.contentJson).toEqual(payload.contentJson);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user