-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
cors-builder.test.ts
40 lines (37 loc) · 1.14 KB
/
cors-builder.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
import { assert } from "../deps_test.ts";
import { CorsBuilder } from "./cors-builder.ts";
import { HttpContext } from "../models/http-context.ts";
const { test } = Deno;
test({
name: "testCorsBuilder",
fn() {
const builder = new CorsBuilder();
const context = new HttpContext({
request: new Request("http://localhost:8000"),
respondWith: () => Promise.resolve(),
});
builder
.WithOrigins("http://localhost:8000")
.WithMethods("PUT, OPTIONS")
.WithHeaders("X-Custom-Header, Upgrade-Insecure-Requests")
.AllowCredentials();
builder.onPostRequest(context).then(() => {
assert(
context.response.headers.get("Access-Control-Allow-Origin") ===
"http://localhost:8000",
);
assert(
context.response.headers.get("Access-Control-Allow-Methods") ===
"PUT, OPTIONS",
);
assert(
context.response.headers.get("Access-Control-Allow-Headers") ===
"X-Custom-Header, Upgrade-Insecure-Requests",
);
assert(
context.response.headers.get("Access-Control-Allow-Credentials") ===
"true",
);
});
},
});