form export 수정 및 통합테스트
CI / test (push) Successful in 49m26s
CI / pr_and_merge (push) Has been skipped

This commit is contained in:
2025-11-28 14:25:30 +09:00
parent c7b6097bd9
commit c9a62d479c
16 changed files with 234 additions and 5 deletions
+43
View File
@@ -185,6 +185,49 @@ describe("/api/forms/submit", () => {
expect(json.message).toBe(config.successMessage);
});
it("both 모드에서는 internal 처리 후 webhook 으로도 전송되어야 한다", async () => {
const destinationUrl = `${BASE_URL}/webhook-both`;
const config: FormBlockProps = {
kind: "contact",
submitTarget: "both",
destinationUrl,
method: "POST",
headers: { Authorization: "Bearer both-token" },
extraParams: { source: "builder-both" },
successMessage: "양쪽 모두 전송되었습니다.",
errorMessage: "both 모드 전송 실패",
fieldIds: [],
submitButtonId: null,
};
const fetchMock = vi.fn(async () => new Response("ok", { status: 200 }));
(globalThis as any).fetch = fetchMock;
const formData = new FormData();
formData.append("email_address", "both@example.com");
formData.append("__config", JSON.stringify(config));
const { POST: handleSubmit } = await import("@/app/api/forms/submit/route");
const res = await handleSubmit(
new Request(`${BASE_URL}/api/forms/submit`, {
method: "POST",
body: formData,
}),
);
expect(res.status).toBe(200);
const json = (await res.json()) as any;
expect(json.ok).toBe(true);
expect(json.message).toBe(config.successMessage);
expect(fetchMock).toHaveBeenCalledTimes(1);
const [url, options] = fetchMock.mock.calls[0] as [string, RequestInit];
expect(url).toBe(destinationUrl);
expect(options.method).toBe("POST");
});
it("webhook 모드에서 destinationUrl 이 없으면 400 과 destinationUrl_missing 및 errorMessage 가 포함되어야 한다", async () => {
const config: FormBlockProps = {
kind: "contact",