forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-data-test.ts
60 lines (52 loc) · 1.76 KB
/
form-data-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { test, expect } from "@playwright/test";
import { createFixture, js } from "./helpers/create-fixture";
import type { Fixture } from "./helpers/create-fixture";
let fixture: Fixture;
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/routes/index.jsx": js`
import { json } from "@remix-run/node";
export async function action({ request }) {
try {
await request.formData()
} catch (err) {
return json("no pizza");
}
return json("pizza");
}
`,
},
});
});
test("invalid content-type does not crash server", async () => {
let response = await fixture.requestDocument("/", {
method: "post",
headers: { "content-type": "application/json" },
});
expect(await response.text()).toMatch("no pizza");
});
test("invalid urlencoded body does not crash server", async () => {
let response = await fixture.requestDocument("/", {
method: "post",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: "$rofl this is totally invalid$",
});
expect(await response.text()).toMatch("pizza");
});
test("invalid multipart content-type does not crash server", async () => {
let response = await fixture.requestDocument("/", {
method: "post",
headers: { "content-type": "multipart/form-data" },
body: "$rofl this is totally invalid$",
});
expect(await response.text()).toMatch("pizza");
});
test("invalid multipart body does not crash server", async () => {
let response = await fixture.requestDocument("/", {
method: "post",
headers: { "content-type": "multipart/form-data; boundary=abc" },
body: "$rofl this is totally invalid$",
});
expect(await response.text()).toMatch("pizza");
});