@@ -84,7 +84,7 @@ describe('v1', () => {
84
84
} ) ;
85
85
} ) ;
86
86
87
- test ( 'with body input' , async ( ) => {
87
+ test ( 'with JSON body input' , async ( ) => {
88
88
const {
89
89
statusCode,
90
90
headers,
@@ -115,6 +115,35 @@ describe('v1', () => {
115
115
} ) ;
116
116
} ) ;
117
117
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
+
118
147
test ( 'with context' , async ( ) => {
119
148
const {
120
149
statusCode,
@@ -275,7 +304,7 @@ describe('v2', () => {
275
304
} ) ;
276
305
} ) ;
277
306
278
- test ( 'with body input' , async ( ) => {
307
+ test ( 'with JSON body input' , async ( ) => {
279
308
const {
280
309
statusCode,
281
310
headers,
@@ -306,6 +335,35 @@ describe('v2', () => {
306
335
} ) ;
307
336
} ) ;
308
337
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
+
309
367
test ( 'with context' , async ( ) => {
310
368
const {
311
369
statusCode,
0 commit comments