@@ -17,9 +17,21 @@ let event = {
1717 }
1818}
1919
20+ api . use ( function ( req , res , next ) {
21+ console . log ( 'HELLO FROM MIDDLEWARE' )
22+ req . testMiddleware = "123" ;
23+ next ( ) ;
24+ } ) ;
25+
2026/******************************************************************************/
2127/*** DEFINE TEST ROUTES ***/
2228/******************************************************************************/
29+ api . get ( "/" , function ( req , res ) {
30+ res . status ( 200 ) . json ( {
31+ testMiddleware : req . testMiddleware ,
32+ } )
33+ } ) ;
34+
2335api . get ( '/test' , function ( req , res ) {
2436 res . status ( 200 ) . json ( { method : 'get' , status : 'ok' } )
2537} )
@@ -40,6 +52,12 @@ api.get('/test/test2/test3', function(req,res) {
4052
4153describe ( 'Base Path Tests:' , function ( ) {
4254
55+ it ( 'should return testMiddleware: 123 when calling the root path' , async function ( ) {
56+ let _event = Object . assign ( { } , event , { path : '/v1' } )
57+ let result = await new Promise ( r => api . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
58+ expect ( result ) . toEqual ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 200 , body : '{"method":"get","status":"ok"}' , isBase64Encoded : false } )
59+ } )
60+
4361 it ( 'Simple path with base: /v1/test' , async function ( ) {
4462 let _event = Object . assign ( { } , event , { path : '/v1/test' } )
4563 let result = await new Promise ( r => api . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
0 commit comments