-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontext.test.ts
46 lines (43 loc) · 1.4 KB
/
context.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
// Copyright 2018-2024 the oak authors. All rights reserved.
import { assertEquals } from "@std/assert/equals";
import { Schema } from "./schema.ts";
import { MockRequestEvent } from "./testing_utils.ts";
import { Context } from "./context.ts";
Deno.test({
name: "Context - should be able to create a new context",
async fn() {
const requestEvent = new MockRequestEvent(
"http://localhost/item/123?a=1&b=2",
{
method: "POST",
body: JSON.stringify({ c: 3 }),
headers: { "content-type": "application/json" },
},
);
const responseHeaders = new Headers();
const schema = new Schema(undefined, false);
const context = new Context(
requestEvent,
responseHeaders,
true,
{ item: "123" },
schema,
undefined,
false,
);
assertEquals(context.addr, {
hostname: "localhost",
port: 80,
transport: "tcp",
});
assertEquals(await context.cookies.size, 0);
assertEquals(context.env, {});
assertEquals(context.params, { item: "123" });
assertEquals(context.url, new URL("http://localhost/item/123?a=1&b=2"));
assertEquals(context.userAgent.toString(), "");
assertEquals(context.request, requestEvent.request);
assertEquals(await context.body(), { c: 3 });
assertEquals(await context.queryParams(), { a: "1", b: "2" });
assertEquals(requestEvent.responded, false);
},
});