CI: feature/builder-10-block-types #4
@@ -1,7 +1,26 @@
|
||||
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";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
// PrismaClient를 실제 DB 대신 메모리 기반 저장소를 사용하는 목으로 대체한다.
|
||||
// 이렇게 하면 CI/로컬 어디에서도 DATABASE_URL 이나 실제 DB 없이 API 테스트를 실행할 수 있다.
|
||||
const inMemoryProjects: any[] = [];
|
||||
|
||||
vi.mock("@/generated/prisma/client", () => {
|
||||
class PrismaClientMock {
|
||||
project = {
|
||||
create: async ({ data }: any) => {
|
||||
const project = { id: inMemoryProjects.length + 1, ...data };
|
||||
inMemoryProjects.push(project);
|
||||
return project;
|
||||
},
|
||||
findUnique: async ({ where: { slug } }: any) => {
|
||||
return inMemoryProjects.find((p) => p.slug === slug) ?? null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return { PrismaClient: PrismaClientMock };
|
||||
});
|
||||
|
||||
const BASE_URL = "http://localhost";
|
||||
|
||||
@@ -19,6 +38,8 @@ describe("/api/projects", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const { POST: createProject } = await import("@/app/api/projects/route");
|
||||
|
||||
const createResponse = await createProject(
|
||||
new Request(`${BASE_URL}/api/projects`, {
|
||||
method: "POST",
|
||||
@@ -37,6 +58,8 @@ describe("/api/projects", () => {
|
||||
expect(created.title).toBe(payload.title);
|
||||
expect(created.slug).toBe(payload.slug);
|
||||
|
||||
const { GET: getProjectBySlug } = await import("@/app/api/projects/[slug]/route");
|
||||
|
||||
const getResponse = await getProjectBySlug(
|
||||
new Request(`${BASE_URL}/api/projects/${payload.slug}`),
|
||||
{ params: { slug: payload.slug } } as any,
|
||||
|
||||
Reference in New Issue
Block a user