-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmethod.test.ts
44 lines (37 loc) · 1.5 KB
/
method.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
// Copyright 2020 Liam Tan. All rights reserved. MIT license.
import { assertEquals } from "./deps.ts";
import { defineRouteDecorator } from "./method.ts";
import { HttpMethod, ControllerMetadata, RouteDefinition } from "./types.ts";
import { getControllerOwnMeta } from "./metadata.ts";
const prefix: string = "/";
const testMethod: HttpMethod = HttpMethod.GET;
const TestDecorator = (prefix: string): MethodDecorator => defineRouteDecorator(prefix, testMethod);
Deno.test({
name: "Method decorator should assign default metadata to Newable non-controller class",
fn(): void {
class TestClass {
@TestDecorator(prefix)
public testAction(): void {}
}
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: "Method decorator should assign route metadata to controller class",
fn(): void {
const actionName: string = "testAction";
class TestClass {
@TestDecorator(prefix)
public [actionName](): void {}
}
const meta: ControllerMetadata | undefined = getControllerOwnMeta(TestClass);
const route: RouteDefinition | undefined = meta?.routes.get(actionName);
assertEquals(route?.methodName, actionName);
assertEquals(route?.path, prefix);
assertEquals(route?.requestMethod, testMethod);
},
});