@@ -346,6 +346,34 @@ describe('handler', function() {
346346 } ) ;
347347 } ) ;
348348
349+ it ( 'next() called with no more middleware, return undefined' , function ( ) {
350+ const result = { foo : 'foo' } ;
351+
352+ const fixture = lambdaHandler ( )
353+ . use ( ( event , context , next ) => next ( null , context , result ) ) ;
354+
355+ return fixture ( testEvent , testContext )
356+ . then ( nextResult => {
357+ expect ( nextResult ) . to . be . undefined ;
358+ } ) ;
359+ } ) ;
360+
361+ it ( 'next() called with no more middleware, return last returned result' , function ( ) {
362+ const result = { foo : 'foo' } ;
363+
364+ const fixture = lambdaHandler ( )
365+ . use ( async ( event , context , next ) => {
366+ await next ( ) ;
367+ return result ;
368+ } )
369+ . use ( ( event , context , next ) => next ( ) ) ;
370+
371+ return fixture ( testEvent , testContext )
372+ . then ( nextResult => {
373+ expect ( nextResult ) . to . equal ( result ) ;
374+ } ) ;
375+ } ) ;
376+
349377 it ( 'next() call is resolved with result value when it is overridden after calling chained next' , function ( ) {
350378 const result1 = { foo : 'foo' } ;
351379 const result2 = { bar : 'bar' } ;
@@ -367,6 +395,30 @@ describe('handler', function() {
367395 } ) ;
368396 } ) ;
369397
398+ it ( 'next() can be called multiple times and result is handled' , function ( ) {
399+ const multiEvent = [ 'f' , 'b' ] ;
400+ const resultMap = {
401+ f : { foo : 'foo' } ,
402+ b : { bar : 'bar' }
403+ } ;
404+
405+ const fixture = lambdaHandler ( )
406+ . use ( async ( events , context , next ) => {
407+ return Promise . all ( events . map ( event => next ( null , context , event ) ) ) ;
408+ } )
409+ . use ( async ( event , context , next ) => {
410+ await next ( ) ;
411+ } )
412+ . use ( async event => {
413+ return resultMap [ event ] ;
414+ } ) ;
415+
416+ return fixture ( multiEvent , testContext )
417+ . then ( result => {
418+ expect ( result ) . to . deep . equal ( [ resultMap . f , resultMap . b ] ) ;
419+ } ) ;
420+ } ) ;
421+
370422 it ( 'has expected execution order' , function ( ) {
371423 const order = [ ] ;
372424 const fixture = lambdaHandler ( )
0 commit comments