@@ -144,6 +144,17 @@ api9.use(middleware3);
144
144
/*** DEFINE TEST ROUTES ***/
145
145
/******************************************************************************/
146
146
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
+
147
158
api . get ( "/test" , function ( req , res ) {
148
159
res . status ( 200 ) . json ( {
149
160
method : "get" ,
@@ -327,6 +338,36 @@ api9.get("/data/test", (req, res) => {
327
338
describe ( "Middleware Tests:" , function ( ) {
328
339
// this.slow(300);
329
340
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
+
330
371
it ( "Set Values in res object" , async function ( ) {
331
372
let _event = Object . assign ( { } , event , { } ) ;
332
373
let result = await new Promise ( ( r ) =>
0 commit comments