@@ -10,6 +10,7 @@ const {
1010 makeResponse,
1111 EACH_MATRIX
1212} = require ( '../jest-helpers' )
13+ const { getEventSource } = require ( '../src/event-sources' )
1314const jestHelpersPath = path . join ( __dirname , '..' , 'jest-helpers' )
1415
1516let app , router , serverlessExpressInstance
@@ -115,7 +116,7 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
115116 res . json ( { xHeaders } )
116117 } )
117118 const event = makeEvent ( {
118- eventSourceName : 'apiGatewayV1 ' ,
119+ eventSourceName : 'AWS_API_GATEWAY_V1 ' ,
119120 path : '/foo' ,
120121 httpMethod : 'GET' ,
121122 multiValueHeaders : undefined ,
@@ -126,7 +127,7 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
126127 } )
127128 const response = await serverlessExpressInstance ( event )
128129 const expectedResponse = makeResponse ( {
129- eventSourceName : 'apiGatewayV1 ' ,
130+ eventSourceName : 'AWS_API_GATEWAY_V1 ' ,
130131 body : JSON . stringify ( {
131132 xHeaders : {
132133 'x-header-one' : 'Value1' ,
@@ -265,31 +266,31 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
265266 const etagRegex = / ^ W \/ .* $ /
266267 const lastModifiedRegex = / ^ .* G M T $ /
267268 switch ( eventSourceName ) {
268- case 'alb ' :
269- case 'apiGatewayV1 ' :
269+ case 'AWS_ALB ' :
270+ case 'AWS_API_GATEWAY_V1 ' :
270271 expect ( response . multiValueHeaders . etag . length ) . toEqual ( 1 )
271272 expect ( response . multiValueHeaders . etag [ 0 ] ) . toMatch ( etagRegex )
272273 expect ( response . multiValueHeaders [ 'last-modified' ] . length ) . toEqual ( 1 )
273274 expect ( response . multiValueHeaders [ 'last-modified' ] [ 0 ] ) . toMatch ( lastModifiedRegex )
274275 delete response . multiValueHeaders . etag
275276 delete response . multiValueHeaders [ 'last-modified' ]
276277 break
277- case 'azureHttpFunctionV4 ' :
278- case 'azureHttpFunctionV3 ' :
278+ case 'AZURE_HTTP_FUNCTION_V4 ' :
279+ case 'AZURE_HTTP_FUNCTION_V3 ' :
279280 expectedResponse . body = Buffer . from ( samLogoBase64 , 'base64' )
280281 expectedResponse . isBase64Encoded = false
281282 expect ( response . headers . etag ) . toMatch ( etagRegex )
282283 expect ( response . headers [ 'last-modified' ] ) . toMatch ( lastModifiedRegex )
283284 delete response . headers . etag
284285 delete response . headers [ 'last-modified' ]
285286 break
286- case 'apiGatewayV2 ' :
287+ case 'AWS_API_GATEWAY_V2 ' :
287288 expect ( response . headers . etag ) . toMatch ( etagRegex )
288289 expect ( response . headers [ 'last-modified' ] ) . toMatch ( lastModifiedRegex )
289290 delete response . headers . etag
290291 delete response . headers [ 'last-modified' ]
291292 break
292- case 'lambdaEdge ' :
293+ case 'AWS_LAMBDA_EDGE ' :
293294 expect ( response . headers . etag . length ) . toEqual ( 1 )
294295 expect ( response . headers . etag [ 0 ] . key ) . toMatch ( 'etag' )
295296 expect ( response . headers . etag [ 0 ] . value ) . toMatch ( etagRegex )
@@ -420,12 +421,56 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
420421 expect ( response ) . toEqual ( expectedResponse )
421422 } )
422423
423- test . skip ( 'respondToEventSourceWithError' , async ( ) => {
424- const response = await serverlessExpressInstance ( null )
425- expect ( response ) . toEqual ( {
426- statusCode : 500 ,
427- body : '' ,
428- multiValueHeaders : { }
424+ describe ( 'respondToEventSourceWithError' , ( ) => {
425+ let event
426+ let eventSource
427+ let getRequestSpy
428+
429+ beforeEach ( ( ) => {
430+ event = makeEvent ( {
431+ eventSourceName,
432+ path : '/users' ,
433+ httpMethod : 'GET'
434+ } )
435+ eventSource = getEventSource ( { eventSourceName } )
436+ getRequestSpy = jest . spyOn ( eventSource , 'getRequest' ) . mockImplementation ( ( ) => {
437+ throw new URIError ( 'URI malformed' )
438+ } )
439+ } )
440+
441+ afterEach ( ( ) => {
442+ getRequestSpy . mockRestore ( )
443+ } )
444+
445+ test ( 'respondWithErrors: true' , async ( ) => {
446+ serverlessExpressInstance = serverlessExpress ( {
447+ app,
448+ eventSource,
449+ respondWithErrors : true
450+ } )
451+
452+ const response = await serverlessExpressInstance ( event )
453+ const statusCode = response . statusCode || response . status
454+
455+ expect ( statusCode ) . toBe ( 500 )
456+ expect ( response . body ) . toContain ( 'URIError' )
457+ expect ( response . body ) . toContain ( 'URI malformed' )
458+ expect ( getRequestSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( { event } ) )
459+ } )
460+
461+ test ( 'respondWithErrors: false' , async ( ) => {
462+ serverlessExpressInstance = serverlessExpress ( {
463+ app,
464+ eventSource,
465+ respondWithErrors : false
466+ } )
467+
468+ const response = await serverlessExpressInstance ( event )
469+ const statusCode = response . statusCode || response . status
470+
471+ expect ( statusCode ) . toBe ( 500 )
472+ expect ( response . body ) . toEqual ( '' )
473+ expect ( getRequestSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( { event } ) )
429474 } )
430475 } )
431476
@@ -471,8 +516,8 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
471516 jest . useRealTimers ( )
472517
473518 switch ( eventSourceName ) {
474- case 'azureHttpFunctionV4 ' :
475- case 'azureHttpFunctionV3 ' :
519+ case 'AZURE_HTTP_FUNCTION_V4 ' :
520+ case 'AZURE_HTTP_FUNCTION_V3 ' :
476521 expectedResponse . cookies = [
477522 {
478523 domain : 'mafoo.com' ,
0 commit comments