-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_test.ts
49 lines (47 loc) · 1.19 KB
/
middleware_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
import { HttpError } from "./middleware_deps.ts";
import { serveOgImage } from "./middleware.ts";
import { assertEquals, assertRejects, connInfo } from "./test_deps.ts";
import { Context, createRoute } from "./server_deps.ts";
const url =
"https://example.com/portrait/Hello World.png?theme=Light&font-size=100px";
const getRoute = createRoute("GET");
const ctx = new Context(new Request(url), connInfo);
Deno.test("overview", async function () {
assertEquals(
(await getRoute({
pathname: "/portrait/*",
search: "INVALID=*",
})(
serveOgImage,
)(ctx)).response.ok,
false,
);
assertEquals(
(await getRoute({
pathname: "/portrait/*",
search: "theme=*",
})(
serveOgImage,
)(ctx)).response.ok,
true,
);
await assertRejects(
async () => {
await getRoute({
pathname: "/portrait/*",
search: "theme=*",
})(
serveOgImage,
)(
new Context(
new Request(
"https://example.com/portrait/Hello World.INVALID?theme=Light&font-size=100px",
),
connInfo,
),
);
},
HttpError,
"The resource has an invalid file extension.",
);
});