-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhttp_status.test.ts
40 lines (33 loc) · 1.23 KB
/
http_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
// Copyright 2020 Liam Tan. All rights reserved. MIT license.
import { assertEquals } from "./deps.ts";
import { HttpStatus } from "./http_status.ts";
import { ControllerMetadata } from "./types.ts";
import { getControllerOwnMeta } from "./metadata.ts";
Deno.test({
name: "HttpStatus decorator should apply default metadata to Newable non-controller class",
fn(): void {
class TestClass {
@HttpStatus(200)
public testAction() {}
}
const meta: ControllerMetadata | undefined = getControllerOwnMeta(TestClass);
assertEquals(meta?.prefix, null);
assertEquals(meta?.defaultResponseCodes instanceof Map, true);
assertEquals(meta?.routes instanceof Map, true);
assertEquals(meta?.args instanceof Array, true);
},
});
Deno.test({
name: "HttpStatus decorator should apply defaultResponseCode metadata to class",
fn(): void {
const actionName: string = "testAction";
const code: number = 200;
class TestClass {
@HttpStatus(code)
public [actionName]() {}
}
const meta: ControllerMetadata | undefined = getControllerOwnMeta(TestClass);
const responseCodeMeta: number | undefined = meta?.defaultResponseCodes.get(actionName);
assertEquals(responseCodeMeta, code);
},
});