deno.land / x / alosaur@v1.1.1 / e2e / basic.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { assert, assertEquals } from "../src/deps_test.ts";import { killServer, startServer } from "./test.utils.ts";const { test } = Deno;
const ContentTypeJson = "application/json; charset=utf-8";
/** * Test cases */test({ name: "[http] basic server, requests to home controller", async fn(t): Promise<void> { const process = await startServer("./examples/basic/app.ts"); const baseUrl = "http://localhost:8000/app/home";
try { // It await t.step("/text?name=john&test=test", async () => { let response = await fetch(baseUrl + "/text?name=john&test=test"); let text = await response.text();
assertEquals(response.status, 200); assertEquals(text, "Hello world, john test undefined"); });
// It await t.step("/json", async () => { let response = await fetch(baseUrl + "/json"); let json = await response.json();
assertEquals(response.headers.get("content-type"), ContentTypeJson); assert(Object.keys(json)[0] == "headers"); });
// It await t.step("/error", async () => { const response = await fetch(baseUrl + "/error");
const json = await response.json();
assertEquals(response.status, 403); assertEquals(response.headers.get("content-type"), ContentTypeJson); assertEquals(json.httpCode, 403); assertEquals(json.name, "ForbiddenError"); assertEquals(json.message, "error"); });
// It await t.step("/query?b=b&c=c&a=a", async () => { const response = await fetch(baseUrl + "/query?b=b&c=c&a=a"); const json = await response.json();
assertEquals(response.status, 200); assertEquals(response.headers.get("content-type"), ContentTypeJson); assertEquals(json.a, "a"); assertEquals(json.b, "b"); assertEquals(json.c, "c"); assertEquals(json.all.a, "a"); assertEquals(json.all.b, "b"); assertEquals(json.all.c, "c"); });
// It await t.step("/test", async () => { const response = await fetch(baseUrl + "/test"); const text = await response.text();
assertEquals(text, "test"); });
// It await t.step("/test/1", async () => { const response = await fetch(baseUrl + "/test/1"); const text = await response.text();
assertEquals(text, "1"); });
// It await t.step("/test/1/john", async () => { const response = await fetch(baseUrl + "/test/1/john"); const text = await response.text(); assertEquals(text, "1 john"); });
// It await t.step("/test/1/john/detail", async () => { const response = await fetch(baseUrl + "/test/1/john/detail"); const text = await response.text();
assertEquals(text, "1 john this is details page"); });
// It await t.step("/post", async () => { let body = JSON.stringify({ username: "john" }); const response = await fetch(baseUrl + "/post", { method: "POST", body }); const json = await response.json();
assertEquals(response.headers.get("content-type"), ContentTypeJson); // TODO fix it // assertEquals(json.username, 'john'); }); } finally { killServer(process); } },});
/** * Test cases */test({ name: "[http] basic server, requests to info controller", async fn(t): Promise<void> { const process = await startServer("./examples/basic/app.ts"); const baseUrl = "http://localhost:8000/test/info";
try { await t.step("/test/info", async () => { const response = await fetch(baseUrl); const text = await response.text();
assertEquals(response.status, 200); assertEquals(text, "Hello info"); });
await t.step("/test/info/", async () => { const response = await fetch(baseUrl + "/"); const text = await response.text();
assertEquals(response.status, 200); assertEquals(text, "Hello info"); }); } finally { killServer(process); } },});
test({ name: "[http] basic server, request to health controller to test undefined controller and action route", async fn(t): Promise<void> { const process = await startServer("./examples/basic/app.ts"); const baseUrl = "http://localhost:8000/health";
try { await t.step("/health", async () => { const response = await fetch(baseUrl); const json = await response.json();
assertEquals(response.status, 200); assertEquals(json.status, "pass"); }); } finally { killServer(process); } },});
test({ name: "[http] basic server, request to root controller to test empty full route", async fn(t): Promise<void> { const process = await startServer("./examples/basic/app.ts"); const baseUrl = "http://localhost:8000";
try { await t.step("", async () => { const response = await fetch(baseUrl); const text = await response.text(); assertEquals(response.status, 200); assertEquals(text, "root page"); });
await t.step("/", async () => { const response = await fetch(`${baseUrl}/`); const text = await response.text(); assertEquals(response.status, 200); assertEquals(text, "root page"); }); } finally { killServer(process); } },});
test({ name: "[http] basic server, return native response", async fn(t): Promise<void> { const process = await startServer("./examples/basic/app.ts");
try { await t.step("app/home/response-test", async () => { let response = await fetch( "http://localhost:8000/app/home/response-test", ); let text = await response.text(); assertEquals(response.status, 201); assertEquals(response.headers.get("x-alosaur-header"), "test"); assertEquals(text, "Object created"); }); } finally { killServer(process); } },});
alosaur

Version Info

Tagged at
2 months ago