@@ -22,6 +22,7 @@ describe('RouterExecutionContext', () => {
2222 let bindSpy : sinon . SinonSpy ;
2323 let factory : RouteParamsFactory ;
2424 let consumer : PipesConsumer ;
25+ let guardsConsumer : GuardsConsumer ;
2526
2627 beforeEach ( ( ) => {
2728 callback = {
@@ -33,10 +34,11 @@ describe('RouterExecutionContext', () => {
3334
3435 factory = new RouteParamsFactory ( ) ;
3536 consumer = new PipesConsumer ( ) ;
37+ guardsConsumer = new GuardsConsumer ( ) ;
3638
3739 contextCreator = new RouterExecutionContext (
3840 factory , new PipesContextCreator ( new ApplicationConfig ( ) ) , consumer ,
39- new GuardsContextCreator ( new NestContainer ( ) ) , new GuardsConsumer ( ) ,
41+ new GuardsContextCreator ( new NestContainer ( ) ) , guardsConsumer ,
4042 new InterceptorsContextCreator ( new NestContainer ( ) ) , new InterceptorsConsumer ( ) ,
4143 ) ;
4244 } ) ;
@@ -101,6 +103,12 @@ describe('RouterExecutionContext', () => {
101103 done ( ) ;
102104 } ) ;
103105 } ) ;
106+ it ( 'should throw exception when "tryActivate" returns false' , ( ) => {
107+ sinon . stub ( guardsConsumer , 'tryActivate' , ( ) => false ) ;
108+ expect (
109+ proxyContext ( request , response , next ) ,
110+ ) . to . eventually . throw ( ) ;
111+ } ) ;
104112 } ) ;
105113 } ) ;
106114 } ) ;
@@ -186,6 +194,30 @@ describe('RouterExecutionContext', () => {
186194 expect ( values [ 1 ] ) . to . deep . include ( expectedValues [ 1 ] ) ;
187195 } ) ;
188196 } ) ;
197+ describe ( 'getCustomFactory' , ( ) => {
198+ describe ( 'when factory is function' , ( ) => {
199+ it ( 'should return curried factory' , ( ) => {
200+ const data = 3 ;
201+ const result = 10 ;
202+ const customFactory = ( _ , req ) => result ;
203+
204+ expect ( contextCreator . getCustomFactory ( customFactory , data ) ( ) ) . to . be . eql ( result ) ;
205+ } ) ;
206+ } ) ;
207+ describe ( 'when factory is undefined / is not a function' , ( ) => {
208+ it ( 'should return curried null identity' , ( ) => {
209+ const result = 10 ;
210+ const customFactory = undefined ;
211+ expect ( contextCreator . getCustomFactory ( customFactory , undefined ) ( ) ) . to . be . eql ( null ) ;
212+ } ) ;
213+ } ) ;
214+ } ) ;
215+ describe ( 'mergeParamsMetatypes' , ( ) => {
216+ it ( 'should return "paramsProperties" when paramtypes array doesnt exists' , ( ) => {
217+ const paramsProperties = [ '1' ] ;
218+ expect ( contextCreator . mergeParamsMetatypes ( paramsProperties as any , null ) ) . to . be . eql ( paramsProperties ) ;
219+ } ) ;
220+ } ) ;
189221 describe ( 'getParamValue' , ( ) => {
190222 let consumerApplySpy : sinon . SinonSpy ;
191223 const value = 3 , metatype = null , transforms = [ ] ;
0 commit comments