11import * as sinon from 'sinon' ;
22import { expect } from 'chai' ;
33import { RouteParamtypes } from '../../../common/enums/route-paramtypes.enum' ;
4+ import { CUSTOM_ROUTE_AGRS_METADATA } from '../../../common/constants' ;
5+ import { createRouteParamDecorator } from '../../../common/utils/decorators/create-route-param-metadata.decorator' ;
46import { RouterExecutionContext } from '../../router/router-execution-context' ;
57import { RouteParamsMetadata , Request , Body } from '../../../index' ;
68import { RouteParamsFactory } from '../../router/route-params-factory' ;
@@ -104,12 +106,15 @@ describe('RouterExecutionContext', () => {
104106 } ) ;
105107 } ) ;
106108 describe ( 'reflectCallbackMetadata' , ( ) => {
109+ const CustomDecorator = createRouteParamDecorator ( ( ) => { } ) ;
107110 class TestController {
108- public callback ( @Request ( ) req , @Body ( ) body ) { }
111+ public callback ( @Request ( ) req , @Body ( ) body , @ CustomDecorator ( ) custom ) { }
109112 }
110113 it ( 'should returns ROUTE_ARGS_METADATA callback metadata' , ( ) => {
111114 const instance = new TestController ( ) ;
112115 const metadata = contextCreator . reflectCallbackMetadata ( instance , 'callback' ) ;
116+ console . log ( metadata ) ;
117+
113118 const expectedMetadata = {
114119 [ `${ RouteParamtypes . REQUEST } :0` ] : {
115120 index : 0 ,
@@ -121,8 +126,22 @@ describe('RouterExecutionContext', () => {
121126 data : undefined ,
122127 pipes : [ ] ,
123128 } ,
129+ [ `custom${ CUSTOM_ROUTE_AGRS_METADATA } :2` ] : {
130+ index : 2 ,
131+ factory : ( ) => { } ,
132+ data : undefined ,
133+ } ,
124134 } ;
125- expect ( metadata ) . to . deep . equal ( expectedMetadata ) ;
135+ expect ( metadata [ `${ RouteParamtypes . REQUEST } :0` ] ) . to . deep . equal ( expectedMetadata [ `${ RouteParamtypes . REQUEST } :0` ] ) ;
136+ expect ( metadata [ `${ RouteParamtypes . REQUEST } :1` ] ) . to . deep . equal ( expectedMetadata [ `${ RouteParamtypes . REQUEST } :1` ] ) ;
137+
138+ const keys = Object . keys ( metadata ) ;
139+ const custom = keys . find ( ( key ) => key . includes ( CUSTOM_ROUTE_AGRS_METADATA ) ) ;
140+
141+ expect ( metadata [ custom ] ) . to . be . an ( 'object' ) ;
142+ expect ( metadata [ custom ] . index ) . to . be . eq ( 2 ) ;
143+ expect ( metadata [ custom ] . data ) . to . be . eq ( undefined ) ;
144+ expect ( metadata [ custom ] . factory ) . to . be . a ( 'function' ) ;
126145 } ) ;
127146 } ) ;
128147 describe ( 'getArgumentsLength' , ( ) => {
@@ -153,17 +172,15 @@ describe('RouterExecutionContext', () => {
153172 it ( 'should exchange arguments keys for appropriate values' , ( ) => {
154173 const metadata = {
155174 [ RouteParamtypes . REQUEST ] : { index : 0 , data : 'test' , pipes : [ ] } ,
156- [ RouteParamtypes . BODY ] : {
157- index : 2 ,
158- data : 'test' ,
159- pipes : [ ] ,
160- } ,
175+ [ RouteParamtypes . BODY ] : { index : 2 , data : 'test' , pipes : [ ] } ,
176+ [ `key${ CUSTOM_ROUTE_AGRS_METADATA } ` ] : { index : 3 , data : 'custom' , pipes : [ ] } ,
161177 } ;
162178 const keys = Object . keys ( metadata ) ;
163179 const values = contextCreator . exchangeKeysForValues ( keys , metadata ) ;
164180 const expectedValues = [
165181 { index : 0 , type : RouteParamtypes . REQUEST , data : 'test' } ,
166182 { index : 2 , type : RouteParamtypes . BODY , data : 'test' } ,
183+ { index : 3 , type : `key${ CUSTOM_ROUTE_AGRS_METADATA } ` , data : 'custom' } ,
167184 ] ;
168185 expect ( values [ 0 ] ) . to . deep . include ( expectedValues [ 0 ] ) ;
169186 expect ( values [ 1 ] ) . to . deep . include ( expectedValues [ 1 ] ) ;
0 commit comments