@@ -84,7 +84,7 @@ describe('v1', () => {
8484 } ) ;
8585 } ) ;
8686
87- test ( 'with body input' , async ( ) => {
87+ test ( 'with JSON body input' , async ( ) => {
8888 const {
8989 statusCode,
9090 headers,
@@ -115,6 +115,35 @@ describe('v1', () => {
115115 } ) ;
116116 } ) ;
117117
118+ test ( 'with url encoded body input' , async ( ) => {
119+ const {
120+ statusCode,
121+ headers,
122+ body : rawBody ,
123+ } = await handler (
124+ mockAPIGatewayProxyEventV1 ( {
125+ body : 'name=Aphex' ,
126+ headers : {
127+ 'content-type' : 'application/x-www-form-urlencoded' ,
128+ } ,
129+ method : 'POST' ,
130+ path : 'hello' ,
131+ queryStringParameters : { } ,
132+ resource : '/hello' ,
133+ } ) ,
134+ ctx ,
135+ ) ;
136+ const body = JSON . parse ( rawBody ) ;
137+
138+ expect ( statusCode ) . toBe ( 200 ) ;
139+ expect ( headers ) . toEqual ( {
140+ 'content-type' : 'application/json' ,
141+ } ) ;
142+ expect ( body ) . toEqual ( {
143+ greeting : 'Hello Aphex' ,
144+ } ) ;
145+ } ) ;
146+
118147 test ( 'with context' , async ( ) => {
119148 const {
120149 statusCode,
@@ -275,7 +304,7 @@ describe('v2', () => {
275304 } ) ;
276305 } ) ;
277306
278- test ( 'with body input' , async ( ) => {
307+ test ( 'with JSON body input' , async ( ) => {
279308 const {
280309 statusCode,
281310 headers,
@@ -306,6 +335,35 @@ describe('v2', () => {
306335 } ) ;
307336 } ) ;
308337
338+ test ( 'with url encoded body input' , async ( ) => {
339+ const {
340+ statusCode,
341+ headers,
342+ body : rawBody ,
343+ } = await handler (
344+ mockAPIGatewayProxyEventV2 ( {
345+ body : 'name=Aphex' ,
346+ headers : {
347+ 'content-type' : 'application/x-www-form-urlencoded' ,
348+ } ,
349+ method : 'POST' ,
350+ path : 'hello' ,
351+ queryStringParameters : { } ,
352+ routeKey : '$default' ,
353+ } ) ,
354+ ctx ,
355+ ) ;
356+ const body = JSON . parse ( rawBody ) ;
357+
358+ expect ( statusCode ) . toBe ( 200 ) ;
359+ expect ( headers ) . toEqual ( {
360+ 'content-type' : 'application/json' ,
361+ } ) ;
362+ expect ( body ) . toEqual ( {
363+ greeting : 'Hello Aphex' ,
364+ } ) ;
365+ } ) ;
366+
309367 test ( 'with context' , async ( ) => {
310368 const {
311369 statusCode,
0 commit comments