-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
payload_test.ts
76 lines (70 loc) · 1.94 KB
/
payload_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Fastro } from "../mod.ts";
import { assertEquals, assertStringContains } from "../deps.ts";
const { test } = Deno;
const port = 3002;
const base = `http://localhost:${port}`;
const server = new Fastro();
Deno.env.set("DENO_ENV", "test");
test({
name: "MULTIPART FORM",
async fn() {
const data = new FormData();
const file = await Deno.readFile("readme.md");
const blob = new Blob([file.buffer]);
data.append("file", blob, "file_name.txt");
data.append("name", "agus");
server.listen({ port });
const result = await fetch(`${base}/form/post`, {
body: data,
method: "POST",
});
const text = await result.text();
const [v1, v2] = JSON.parse(text);
assertStringContains(v1.value, "# High perfomance deno web framework");
assertStringContains(v2.value, "agus");
server.close();
},
sanitizeResources: false,
sanitizeOps: false,
});
test({
name: "URL ENCODED FORM",
async fn() {
server.listen({ port });
var data = new URLSearchParams();
data.append("userName", "test@gmail.com");
data.append("password", "Password");
data.append("grant_type", "password");
const result = await fetch(`${base}/form/post`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: data,
});
const text = await result.text();
const [c] = JSON.parse(text);
assertEquals(c, { userName: "test@gmail.com" });
server.close();
},
sanitizeResources: false,
sanitizeOps: false,
});
test({
name: "JSON FORM",
async fn() {
server.listen({ port });
const result = await fetch(`${base}/form/post`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ msg: "hello" }),
});
const text = await result.text();
assertEquals(text, '{"msg":"hello"}');
server.close();
},
sanitizeResources: false,
sanitizeOps: false,
});