-
Notifications
You must be signed in to change notification settings - Fork 3
/
status_test.ts
78 lines (65 loc) · 2.05 KB
/
status_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2020 Filippo Rossi. All rights reserved. MIT license.
import {
assert,
assertStrictEquals as assertStrictEq,
assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
import { MOVED_PERMANENTLY, status } from "./mod.ts";
Deno.test({
name: "status:arguments:number",
fn(): void {
assertStrictEq(status(200), "OK");
assertStrictEq(status(404), "NOT_FOUND");
assertStrictEq(status(500), "INTERNAL_SERVER_ERROR");
assertThrows(status.bind(null, 0), undefined, "invalid status code");
assertThrows(status.bind(null, 1000), undefined, "invalid status code");
assertThrows(status.bind(null, 299), undefined, "invalid status code");
assertThrows(status.bind(null, 310), undefined, "invalid status code");
assertThrows(status.bind(null, 306), undefined, "invalid status code");
},
});
Deno.test({
name: "status:arguments:string",
fn(): void {
assertStrictEq(status("200"), "OK");
assertStrictEq(status("404"), "NOT_FOUND");
assertStrictEq(status("500"), "INTERNAL_SERVER_ERROR");
assert(status("OK"));
assert(status("internal server error"));
assert(status("NoT FoUnd"));
assertThrows(
status.bind(null, "too many bugs"),
undefined,
"invalid status message",
);
assertThrows(status.bind(null, "299"), undefined, "invalid status code");
},
});
Deno.test({
name: "status:pretty",
fn(): void {
assertStrictEq(status.pretty("200"), "Ok");
assertStrictEq(status.pretty("404"), "Not Found");
assertStrictEq(status.pretty("500"), "Internal Server Error");
assert(status.pretty("OK"));
assert(status.pretty("internal server error"));
assert(status.pretty("NoT FoUnd"));
assertThrows(
status.pretty.bind(null, "too many bugs"),
undefined,
"invalid status message",
);
assertThrows(
status.pretty.bind(null, "299"),
undefined,
"invalid status code",
);
assertStrictEq(status(status.pretty("500")), 500);
},
});
Deno.test({
name: "status:globals",
fn(): void {
MOVED_PERMANENTLY;
},
});