form export 수정 및 통합테스트
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user