import { Context as LambdaContext } from 'aws-lambda' ; import { adaptFaasKitHandlerForLambda , adaptLambdaHandlerForFaasKit , Context , } from './adapters' ; describe ( 'adaptFaasKitHandlerForLambda' , ( ) => { test ( 'nests lambda-provided context' , async ( ) => { const mockEvent = { testKey : 'testValue' } ; const mockContext = { callbackWaitsForEmptyEventLoop : false , functionName : 'testFunction' , functionVersion : 'LATEST' , invokedFunctionArn : 'arn:testFunction' , memoryLimitInMB : '128' , awsRequestId : '1' , logGroupName : 'testFunctionLogGroupName' , logStreamName : 'testFunctionLogGroupName1' , getRemainingTimeInMillis : ( ) => { return 1 ; } , done : ( _error , _result ) => { } , fail : ( _error ) => { } , succeed : ( _result ) => { } , } ; const mockResult = 'test result' ; const mockHandler = jest . fn ( ) . mockResolvedValue ( mockResult ) ; const mockWrappedHandler = adaptFaasKitHandlerForLambda ( mockHandler ) ; const mockCallback = jest . fn ( ) ; const result = await mockWrappedHandler ( mockEvent , mockContext , mockCallback ) ; expect ( mockHandler ) . toBeCalledWith ( mockEvent , { AWSLambda : mockContext } ) ; expect ( result ) . toEqual ( mockResult ) ; } ) ; } ) ; describe ( 'adaptLambdaHandlerForFaasKit' , ( ) => { test ( '' , async ( ) => { const mockEvent = { testKey : 'testValue' } ; const expectedContext = { callbackWaitsForEmptyEventLoop : false , functionName : 'testFunction' , functionVersion : 'LATEST' , invokedFunctionArn : 'arn:testFunction' , memoryLimitInMB : '128' , awsRequestId : '1' , logGroupName : 'testFunctionLogGroupName' , logStreamName : 'testFunctionLogGroupName1' , getRemainingTimeInMillis : ( ) => { return 1 ; } , done : ( _error , _result ) => { } , fail : ( _error ) => { } , succeed : ( _result ) => { } , } ; const mockContext = { AWSLambda : expectedContext , } ; const mockResult = 'test result' ; const mockHandler = jest . fn ( ) . mockResolvedValue ( mockResult ) ; const mockWrappedHandler = adaptLambdaHandlerForFaasKit ( mockHandler ) ; const result = await mockWrappedHandler ( mockEvent , mockContext ) ; expect ( mockHandler . mock . calls [ 0 ] [ 0 ] ) . toBe ( mockEvent ) ; expect ( mockHandler . mock . calls [ 0 ] [ 1 ] ) . toEqual ( expectedContext ) ; expect ( result ) . toEqual ( mockResult ) ; } ) ; } ) ;