-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_test.ts
64 lines (60 loc) · 1.38 KB
/
route_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
import { Context, createRoute } from "./mod.ts";
import {
add10Middleware,
connInfo,
divide5DelayedMiddleware,
tryMiddleware,
} from "./test_util.ts";
import { assertEquals } from "./test_deps.ts";
type State = { result: number };
const request = new Request("https:example.com/books");
class Ctx extends Context<State> {}
Deno.test("createRoute", async function () {
assertEquals(
(await createRoute("ALL")({ pathname: "/books" })(add10Middleware)(
new Ctx(request, connInfo, { result: 10 }),
)).state.result,
20,
);
assertEquals(
(await createRoute("GET")({ pathname: "/books" })(
add10Middleware,
divide5DelayedMiddleware,
)(
new Ctx(request, connInfo, { result: 10 }),
)).state.result,
12,
);
assertEquals(
(await createRoute("POST", "GET")({ pathname: "/books" })(tryMiddleware)(
new Ctx(
request,
connInfo,
{ result: 10 },
),
)).state.result,
28,
);
assertEquals(
(await createRoute("POST", "DELETE")({ pathname: "/books" })(
tryMiddleware,
)(
new Ctx(
request,
connInfo,
{ result: 10 },
),
)).state.result,
10,
);
assertEquals(
(await createRoute("GET")({ pathname: "/ups" })(tryMiddleware)(
new Ctx(
request,
connInfo,
{ result: 10 },
),
)).state.result,
10,
);
});