-
Notifications
You must be signed in to change notification settings - Fork 230
/
helpers_test.ts
39 lines (34 loc) · 944 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
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2018-2023 the oak authors. All rights reserved. MIT license.
import { getQuery } from "./helpers.ts";
import { assertEquals } from "./test_deps.ts";
import { createMockContext } from "./testing.ts";
const { test } = Deno;
test({
name: "getQuery - basic",
fn() {
const ctx = createMockContext({ path: "/?foo=bar&bar=baz" });
assertEquals(getQuery(ctx), { foo: "bar", bar: "baz" });
},
});
test({
name: "getQuery - asMap",
fn() {
const ctx = createMockContext({ path: "/?foo=bar&bar=baz" });
assertEquals(
Array.from(getQuery(ctx, { asMap: true })),
[["foo", "bar"], ["bar", "baz"]],
);
},
});
test({
name: "getQuery - merge params",
fn() {
const ctx = createMockContext(
{ params: { foo: "qat", baz: "qat" }, path: "/?foo=bar&bar=baz" },
);
assertEquals(
getQuery(ctx, { mergeParams: true }),
{ foo: "bar", baz: "qat", bar: "baz" },
);
},
});