/
helpers_test.ts
28 lines (21 loc) · 799 Bytes
/
helpers_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
import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts";
import { App, get } from "./mod.ts";
import { redirect } from "./helpers.ts";
const testPort = 8376;
const host = `http://localhost:${testPort}`;
Deno.test("Redirection does return new endpoint", async () => {
const app = new App(testPort);
app.serve();
const originalEndpoint = "/original";
const newEndpoint = "/new_endpoint";
const expectedBody = `body at ${newEndpoint}`;
app.register(get(originalEndpoint, () => redirect(newEndpoint)));
app.register(get(newEndpoint, () => expectedBody));
const response = await fetch(
`${host}${originalEndpoint}`,
{ method: "GET" },
);
assertEquals(response.status, 200);
assertEquals(await response.text(), expectedBody);
app.close();
});