1- import { lambdaWrapper } from 'serverless-jest- plugin'
1+ import { context } from 'serverless-plugin-test-helper '
22import { StatusCodes } from 'http-status-codes'
33import type { APIGatewayProxyEvent } from 'aws-lambda'
44
@@ -11,18 +11,22 @@ const proxyEventFactory = (body: unknown): APIGatewayProxyEvent<{ body: Foo }> =
1111}
1212
1313describe ( 'POST /foo' , ( ) => {
14- const endpoint = lambdaWrapper . wrap ( { foo } , { handler : 'foo' } )
15-
1614 test ( 'returns 400 HTTP' , async ( ) => {
17- const response = await endpoint . run ( proxyEventFactory ( { invalid : 'invalid' } ) )
15+ const event = proxyEventFactory ( { invalid : 'invalid' } )
16+ const handler = foo ( event , context , jest . fn ( ) )
1817
19- expect ( response . statusCode ) . toEqual ( StatusCodes . BAD_REQUEST )
20- expect ( response . body ) . toEqual ( 'Event object failed validation' )
18+ await expect ( handler ) . resolves . toMatchObject ( {
19+ body : 'Event object failed validation' ,
20+ statusCode : StatusCodes . BAD_REQUEST ,
21+ } )
2122 } )
2223
2324 test ( 'returns 200 HTTP' , async ( ) => {
24- const response = await endpoint . run ( proxyEventFactory ( { bar : 'aaaa' , foo : 'aaaaaaaaaaaaa' } ) )
25+ const event = proxyEventFactory ( { bar : 'aaaa' , foo : 'aaaaaaaaaaaaa' } )
26+ const handler = foo ( event , context , jest . fn ( ) )
2527
26- expect ( response . statusCode ) . toEqual ( StatusCodes . OK )
28+ await expect ( handler ) . resolves . toMatchObject ( {
29+ statusCode : StatusCodes . OK ,
30+ } )
2731 } )
2832} )
0 commit comments