-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexecution_container.test.ts
49 lines (42 loc) · 1.44 KB
/
execution_container.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 { assertEquals, Context, RouterContext } from "./deps.ts";
import { ExecutionContainer } from "./execution_container.ts";
import {
ControllerMetadata,
EInjectionScope,
RouteDefinition,
RouteArgument,
HttpMethod,
ExecutionResult,
} from "./types.ts";
import { Controller } from "./controller.ts";
import { getControllerOwnMeta } from "./metadata.ts";
import { Get } from "./method.ts";
import { createMockContext } from "./utils.ts";
import DIContainer from "./dependency_container.ts";
Deno.test({
name: "expect execution container result to match the body of the called action",
async fn() {
const responseBody = { key: "value" };
@Controller("/test", EInjectionScope.SINGLETON)
class TestController {
@Get("/")
testAction() {
return responseBody;
}
}
DIContainer.register(TestController, EInjectionScope.SINGLETON, TestController.name);
const meta: ControllerMetadata | undefined = getControllerOwnMeta(TestController);
const container: ExecutionContainer = new ExecutionContainer(
<ControllerMetadata>meta,
TestController.name
);
const route: RouteDefinition = {
requestMethod: HttpMethod.GET,
path: "/",
methodName: "testAction",
};
const context: Context = createMockContext({ path: "/test" });
const { body }: ExecutionResult = await container.execute(route, <RouterContext>context);
assertEquals(body, responseBody);
},
});