video 블록 및 리펙터링
CI / pr_and_merge (push) Has been skipped
CI / test (push) Failing after 46m46s
CI / test (pull_request) Failing after 43m8s
CI / pr_and_merge (pull_request) Has been skipped

This commit is contained in:
2025-11-27 10:07:59 +09:00
parent 672cca5271
commit 48e13d2a75
223 changed files with 8979 additions and 2125 deletions
+52
View File
@@ -0,0 +1,52 @@
import "dotenv/config";
import { describe, it, expect, vi } from "vitest";
import { promises as fs } from "fs";
import path from "path";
const BASE_URL = "http://localhost";
// /api/video 업로드 TDD
// - POST /api/video 로 FormData(file) 를 전송하면 업로드 파일이 uploads 디렉터리에 저장되고
// id / servedUrl(`/api/video/:id`) 을 반환해야 한다.
// Prisma 엔진이 실제로 로드되지 않도록 PrismaClient 를 목 처리한다.
vi.mock("@/generated/prisma/client", () => {
class PrismaClient {
project = {
upsert: async () => ({ id: "project-mock" }),
};
asset = {
create: async () => ({ id: "asset-mock" }),
};
}
return { PrismaClient };
});
describe("/api/video 업로드", () => {
it("POST /api/video 는 업로드된 비디오 파일을 저장하고 id/servedUrl 을 반환해야 한다", async () => {
const { POST: handleUpload } = await import("@/app/api/video/route");
const formData = new FormData();
const blob = new Blob(["dummy-video"], { type: "video/mp4" });
// FormData 에서는 File/Blob 모두 허용되므로, Blob 을 그대로 사용한다.
formData.append("file", blob as any);
const res = await handleUpload(
new Request(`${BASE_URL}/api/video`, {
method: "POST",
body: formData,
}),
);
expect(res.status).toBe(201);
const json = (await res.json()) as { id: string; servedUrl?: string | null };
expect(json.id).toBeTruthy();
expect(json.servedUrl).toBe(`/api/video/${json.id}`);
const filePath = path.join(process.cwd(), "uploads", json.id);
const stat = await fs.stat(filePath);
expect(stat.isFile()).toBe(true);
});
});