@@ -32,6 +32,21 @@ describe('RouterExplorer', () => {
3232 public getTestUsingArray ( ) { }
3333 }
3434
35+ @Controller ( [ 'global' , 'global-alias' ] )
36+ class TestRouteAlias {
37+ @Get ( 'test' )
38+ public getTest ( ) { }
39+
40+ @Post ( 'test' )
41+ public postTest ( ) { }
42+
43+ @All ( 'another-test' )
44+ public anotherTest ( ) { }
45+
46+ @Get ( [ 'foo' , 'bar' ] )
47+ public getTestUsingArray ( ) { }
48+ }
49+
3550 let routerBuilder : RouterExplorer ;
3651 let injector : Injector ;
3752 let exceptionsFilter : RouterExceptionFilters ;
@@ -70,6 +85,22 @@ describe('RouterExplorer', () => {
7085 expect ( paths [ 2 ] . requestMethod ) . to . eql ( RequestMethod . ALL ) ;
7186 expect ( paths [ 3 ] . requestMethod ) . to . eql ( RequestMethod . GET ) ;
7287 } ) ;
88+
89+ it ( 'should method return expected list of route paths alias' , ( ) => {
90+ const paths = routerBuilder . scanForPaths ( new TestRouteAlias ( ) ) ;
91+
92+ expect ( paths ) . to . have . length ( 4 ) ;
93+
94+ expect ( paths [ 0 ] . path ) . to . eql ( [ '/test' ] ) ;
95+ expect ( paths [ 1 ] . path ) . to . eql ( [ '/test' ] ) ;
96+ expect ( paths [ 2 ] . path ) . to . eql ( [ '/another-test' ] ) ;
97+ expect ( paths [ 3 ] . path ) . to . eql ( [ '/foo' , '/bar' ] ) ;
98+
99+ expect ( paths [ 0 ] . requestMethod ) . to . eql ( RequestMethod . GET ) ;
100+ expect ( paths [ 1 ] . requestMethod ) . to . eql ( RequestMethod . POST ) ;
101+ expect ( paths [ 2 ] . requestMethod ) . to . eql ( RequestMethod . ALL ) ;
102+ expect ( paths [ 3 ] . requestMethod ) . to . eql ( RequestMethod . GET ) ;
103+ } ) ;
73104 } ) ;
74105
75106 describe ( 'exploreMethodMetadata' , ( ) => {
@@ -87,6 +118,20 @@ describe('RouterExplorer', () => {
87118 expect ( route . requestMethod ) . to . eql ( RequestMethod . GET ) ;
88119 } ) ;
89120
121+ it ( 'should method return expected object which represent single route with alias' , ( ) => {
122+ const instance = new TestRouteAlias ( ) ;
123+ const instanceProto = Object . getPrototypeOf ( instance ) ;
124+
125+ const route = routerBuilder . exploreMethodMetadata (
126+ new TestRouteAlias ( ) ,
127+ instanceProto ,
128+ 'getTest' ,
129+ ) ;
130+
131+ expect ( route . path ) . to . eql ( [ '/test' ] ) ;
132+ expect ( route . requestMethod ) . to . eql ( RequestMethod . GET ) ;
133+ } ) ;
134+
90135 it ( 'should method return expected object which represent multiple routes' , ( ) => {
91136 const instance = new TestRoute ( ) ;
92137 const instanceProto = Object . getPrototypeOf ( instance ) ;
@@ -100,6 +145,20 @@ describe('RouterExplorer', () => {
100145 expect ( route . path ) . to . eql ( [ '/foo' , '/bar' ] ) ;
101146 expect ( route . requestMethod ) . to . eql ( RequestMethod . GET ) ;
102147 } ) ;
148+
149+ it ( 'should method return expected object which represent multiple routes with alias' , ( ) => {
150+ const instance = new TestRouteAlias ( ) ;
151+ const instanceProto = Object . getPrototypeOf ( instance ) ;
152+
153+ const route = routerBuilder . exploreMethodMetadata (
154+ new TestRouteAlias ( ) ,
155+ instanceProto ,
156+ 'getTestUsingArray' ,
157+ ) ;
158+
159+ expect ( route . path ) . to . eql ( [ '/foo' , '/bar' ] ) ;
160+ expect ( route . requestMethod ) . to . eql ( RequestMethod . GET ) ;
161+ } ) ;
103162 } ) ;
104163
105164 describe ( 'applyPathsToRouterProxy' , ( ) => {
@@ -130,14 +189,20 @@ describe('RouterExplorer', () => {
130189
131190 describe ( 'extractRouterPath' , ( ) => {
132191 it ( 'should return expected path' , ( ) => {
133- expect ( routerBuilder . extractRouterPath ( TestRoute ) ) . to . be . eql ( '/global' ) ;
134- expect ( routerBuilder . extractRouterPath ( TestRoute , '/module' ) ) . to . be . eql (
192+ expect ( routerBuilder . extractRouterPath ( TestRoute ) ) . to . be . eql ( [ '/global' ] ) ;
193+ expect ( routerBuilder . extractRouterPath ( TestRoute , '/module' ) ) . to . be . eql ( [
135194 '/module/global' ,
136- ) ;
195+ ] ) ;
137196 } ) ;
138197
139- it ( 'should throw it a there is a bad path expected path' , ( ) => {
140- expect ( ( ) => routerBuilder . validateRoutePath ( undefined ) ) . to . throw ( ) ;
198+ it ( 'should return expected path with alias' , ( ) => {
199+ expect ( routerBuilder . extractRouterPath ( TestRouteAlias ) ) . to . be . eql ( [
200+ '/global' ,
201+ '/global-alias' ,
202+ ] ) ;
203+ expect (
204+ routerBuilder . extractRouterPath ( TestRouteAlias , '/module' ) ,
205+ ) . to . be . eql ( [ '/module/global' , '/module/global-alias' ] ) ;
141206 } ) ;
142207 } ) ;
143208
0 commit comments