@@ -433,7 +433,7 @@ describe('HttpServerModule', () => {
433
433
methodReflection
434
434
} )
435
435
} ) ;
436
- const reqMock = { } ;
436
+ const reqMock = { body : 'invalidType' } ;
437
437
const resMock = { } ;
438
438
const result = await requestHandler ( reqMock , resMock ) ;
439
439
@@ -459,6 +459,49 @@ describe('HttpServerModule', () => {
459
459
expect ( methodInterceptorPost . called ) . to . be . false ;
460
460
} ) ;
461
461
462
+ it ( 'should create a request handler that process preValidation interceptors' , async ( ) => {
463
+ const ctrlInterceptorPre = sinon . stub ( ) . callsFake ( next => next ( ) ) ;
464
+ const ctrlInterceptorPost = sinon . stub ( ) . callsFake ( next => next ( ) ) ;
465
+
466
+ const methodInterceptorPre = sinon . stub ( ) . callsFake ( next => next ( ) ) ;
467
+ const methodInterceptorPost = sinon . stub ( ) . callsFake ( next => next ( ) ) ;
468
+
469
+ @interceptor < HttpServerInterceptor > ( ctrlInterceptorPre , { stage : 'preValidation' } )
470
+ @interceptor < HttpServerInterceptor > ( ctrlInterceptorPost , { stage : 'postValidation' } )
471
+ @route . controller ( { basePath : '/api/customers' } )
472
+ class CustomerController {
473
+ @interceptor < HttpServerInterceptor > ( methodInterceptorPre , { stage : 'preValidation' } )
474
+ @interceptor < HttpServerInterceptor > ( methodInterceptorPost , { stage : 'postValidation' } )
475
+ @route . post ( { path : '/all' } )
476
+ find ( @route . body ( { required : true } ) body ) {
477
+ return { body } ;
478
+ }
479
+ }
480
+ const dummyHttpServer = new DummyHttpServer ( ) ;
481
+ const controllerReflection = reflect ( CustomerController ) ;
482
+ const methodReflection = controllerReflection . methods [ 0 ] ;
483
+ const requestHandler = await dummyHttpServer . createRequestHandler ( new CustomerController ( ) , 'find' , {
484
+ path : '/all' ,
485
+ verb : 'get' ,
486
+ controllerReflection,
487
+ methodReflection,
488
+ parametersConfig : dummyHttpServer . createParametersConfigurations ( {
489
+ controllerReflection,
490
+ methodReflection
491
+ } )
492
+ } ) ;
493
+ const reqMock = { } ;
494
+ const resMock = { } ;
495
+ const result = await requestHandler ( reqMock , resMock ) ;
496
+
497
+ expect ( result [ 1 ] ) . to . containSubset ( { body : undefined } ) ;
498
+ expect ( ctrlInterceptorPre . called ) . to . be . true ;
499
+ expect ( ctrlInterceptorPost . called ) . to . be . true ;
500
+
501
+ expect ( methodInterceptorPre . called ) . to . be . true ;
502
+ expect ( methodInterceptorPost . called ) . to . be . true ;
503
+ } ) ;
504
+
462
505
it ( 'should create a request handler tha process interceptors in the correct order' , async ( ) => {
463
506
const callsOrder = [ ] ;
464
507
const createHandler = name => next => {
0 commit comments