@@ -144,6 +144,17 @@ api9.use(middleware3);
144144/*** DEFINE TEST ROUTES ***/
145145/******************************************************************************/
146146
147+ api . get ( '/' , function ( req , res ) {
148+ res . status ( 200 ) . json ( {
149+ testMiddleware : req . testMiddleware ,
150+ } )
151+ } ) ;
152+ api . post ( '/' , function ( req , res ) {
153+ res . status ( 200 ) . json ( {
154+ testMiddleware2 : req . testMiddleware2 ,
155+ } )
156+ } ) ;
157+
147158api . get ( "/test" , function ( req , res ) {
148159 res . status ( 200 ) . json ( {
149160 method : "get" ,
@@ -327,6 +338,36 @@ api9.get("/data/test", (req, res) => {
327338describe ( "Middleware Tests:" , function ( ) {
328339 // this.slow(300);
329340
341+ it ( 'should return testMiddleware: 123 when calling the root route with GET' , async function ( ) {
342+ let _event = Object . assign ( { } , event , { path : "/" } ) ;
343+ let result = await new Promise ( ( r ) =>
344+ api . run ( _event , { } , ( e , res ) => {
345+ r ( res ) ;
346+ } )
347+ ) ;
348+ expect ( result ) . toEqual ( {
349+ multiValueHeaders : { "content-type" : [ "application/json" ] } ,
350+ statusCode : 200 ,
351+ body : '{"testMiddleware":"123"}' ,
352+ isBase64Encoded : false ,
353+ } ) ;
354+ } )
355+
356+ it ( 'should return testMiddleware2: 456 when calling the root route with POST' , async function ( ) {
357+ let _event = Object . assign ( { } , event , { path : "/" , httpMethod : "POST" } ) ;
358+ let result = await new Promise ( ( r ) =>
359+ api . run ( _event , { } , ( e , res ) => {
360+ r ( res ) ;
361+ } )
362+ ) ;
363+ expect ( result ) . toEqual ( {
364+ multiValueHeaders : { "content-type" : [ "application/json" ] } ,
365+ statusCode : 200 ,
366+ body : '{"testMiddleware2":"456"}' ,
367+ isBase64Encoded : false ,
368+ } ) ;
369+ } )
370+
330371 it ( "Set Values in res object" , async function ( ) {
331372 let _event = Object . assign ( { } , event , { } ) ;
332373 let result = await new Promise ( ( r ) =>
0 commit comments