forked from nestjs/nest
/
builder.spec.ts
80 lines (74 loc) 路 2.24 KB
/
builder.spec.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
79
80
import { expect } from 'chai';
import { Controller, Get, RequestMethod, Version } from '../../../common';
import { NestContainer } from '../../injector/container';
import { MiddlewareBuilder } from '../../middleware/builder';
import { RoutesMapper } from '../../middleware/routes-mapper';
import { NoopHttpAdapter } from './../utils/noop-adapter.spec';
describe('MiddlewareBuilder', () => {
let builder: MiddlewareBuilder;
beforeEach(() => {
const container = new NestContainer();
builder = new MiddlewareBuilder(
new RoutesMapper(container),
new NoopHttpAdapter({}),
);
});
describe('apply', () => {
let configProxy;
beforeEach(() => {
configProxy = builder.apply([]);
});
it('should return configuration proxy', () => {
const metatype = (MiddlewareBuilder as any).ConfigProxy;
expect(configProxy instanceof metatype).to.be.true;
});
describe('configuration proxy', () => {
describe('when "forRoutes()" called', () => {
@Controller('path')
class Test {
@Get('route')
public getAll() {}
@Version('1')
@Get('versioned')
public getAllVersioned() {}
}
const route = { path: '/test', method: RequestMethod.GET };
it('should store configuration passed as argument', () => {
configProxy.forRoutes(route, Test);
expect(builder.build()).to.deep.equal([
{
middleware: [],
forRoutes: [
{
method: RequestMethod.GET,
path: route.path,
},
{
method: RequestMethod.GET,
path: '/path/route',
},
{
method: RequestMethod.GET,
path: '/path/versioned',
version: '1',
},
],
},
]);
});
});
});
});
describe('exclude', () => {
it('should map string to RouteInfo', () => {
const path = '/test';
const proxy: any = builder.apply().exclude(path);
expect(proxy.getExcludedRoutes()).to.be.eql([
{
path,
method: -1,
},
]);
});
});
});