@@ -41,6 +41,17 @@ export const createTestEvent = (
4141 resource : '' ,
4242} ) ;
4343
44+ const createAlbBody = ( httpMethod : string , body : JSONValue ) : string | null => {
45+ // ALB events represent GET and PATCH request bodies as empty strings
46+ if ( httpMethod === HttpVerbs . GET || httpMethod === HttpVerbs . PATCH ) {
47+ return '' ;
48+ }
49+ if ( body === null ) {
50+ return null ;
51+ }
52+ return JSON . stringify ( body ) ;
53+ } ;
54+
4455export const createTestEventV2 = (
4556 rawPath : string ,
4657 method : string ,
@@ -76,36 +87,23 @@ export const createTestALBEvent = (
7687 path : string ,
7788 httpMethod : string ,
7889 headers : Record < string , string > = { } ,
79- body : string | JSONValue = null
80- ) : ALBEvent => {
81- const stringBody =
82- typeof body === 'string'
83- ? body
84- : body !== null
85- ? JSON . stringify ( body )
86- : null ;
87-
88- return {
89- path,
90- httpMethod,
91- headers,
92- // ALB events represent GET and PATCH request bodies as empty strings
93- body :
94- httpMethod === HttpVerbs . GET || httpMethod === HttpVerbs . PATCH
95- ? ''
96- : stringBody ,
97- multiValueHeaders : { } ,
98- isBase64Encoded : false ,
99- queryStringParameters : undefined ,
100- multiValueQueryStringParameters : undefined ,
101- requestContext : {
102- elb : {
103- targetGroupArn :
104- 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test/50dc6c495c0c9188' ,
105- } ,
90+ body : JSONValue = null
91+ ) : ALBEvent => ( {
92+ path,
93+ httpMethod,
94+ headers,
95+ body : createAlbBody ( httpMethod , body ) ,
96+ multiValueHeaders : { } ,
97+ isBase64Encoded : false ,
98+ queryStringParameters : undefined ,
99+ multiValueQueryStringParameters : undefined ,
100+ requestContext : {
101+ elb : {
102+ targetGroupArn :
103+ 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test/50dc6c495c0c9188' ,
106104 } ,
107- } ;
108- } ;
105+ } ,
106+ } ) ;
109107
110108export const createTrackingMiddleware = (
111109 name : string ,
0 commit comments