@@ -36,7 +36,7 @@ describe('Converters', () => {
36
36
body : null ,
37
37
} ;
38
38
39
- it ( 'should convert basic GET request' , ( ) => {
39
+ it ( 'converts basic GET request' , ( ) => {
40
40
const request = proxyEventToWebRequest ( baseEvent ) ;
41
41
42
42
expect ( request ) . toBeInstanceOf ( Request ) ;
@@ -45,7 +45,7 @@ describe('Converters', () => {
45
45
expect ( request . body ) . toBe ( null ) ;
46
46
} ) ;
47
47
48
- it ( 'should use Host header over domainName' , ( ) => {
48
+ it ( 'uses Host header over domainName' , ( ) => {
49
49
const event = {
50
50
...baseEvent ,
51
51
headers : { Host : 'custom.example.com' } ,
@@ -56,7 +56,7 @@ describe('Converters', () => {
56
56
expect ( request . url ) . toBe ( 'https://custom.example.com/test' ) ;
57
57
} ) ;
58
58
59
- it ( 'should use X-Forwarded-Proto header for protocol' , ( ) => {
59
+ it ( 'uses X-Forwarded-Proto header for protocol' , ( ) => {
60
60
const event = {
61
61
...baseEvent ,
62
62
headers : { 'X-Forwarded-Proto' : 'https' } ,
@@ -67,7 +67,7 @@ describe('Converters', () => {
67
67
expect ( request . url ) . toBe ( 'https://api.example.com/test' ) ;
68
68
} ) ;
69
69
70
- it ( 'should handle null values in multiValueHeaders arrays' , ( ) => {
70
+ it ( 'handles null values in multiValueHeaders arrays' , ( ) => {
71
71
const event = {
72
72
...baseEvent ,
73
73
multiValueHeaders : {
@@ -82,7 +82,7 @@ describe('Converters', () => {
82
82
expect ( request . headers . get ( 'Custom-Header' ) ) . toBe ( 'value1' ) ;
83
83
} ) ;
84
84
85
- it ( 'should handle null values in multiValueQueryStringParameters arrays' , ( ) => {
85
+ it ( 'handles null values in multiValueQueryStringParameters arrays' , ( ) => {
86
86
const event = {
87
87
...baseEvent ,
88
88
multiValueQueryStringParameters : {
@@ -98,14 +98,10 @@ describe('Converters', () => {
98
98
expect ( url . searchParams . get ( 'sort' ) ) . toBe ( 'desc' ) ;
99
99
} ) ;
100
100
101
- it ( 'should handle POST request with string body' , async ( ) => {
101
+ it ( 'handles POST request with string body' , async ( ) => {
102
102
const event = {
103
103
...baseEvent ,
104
104
httpMethod : 'POST' ,
105
- requestContext : {
106
- ...baseEvent . requestContext ,
107
- httpMethod : 'POST' ,
108
- } ,
109
105
body : '{"key":"value"}' ,
110
106
headers : { 'Content-Type' : 'application/json' } ,
111
107
} ;
@@ -117,17 +113,13 @@ describe('Converters', () => {
117
113
expect ( request . headers . get ( 'Content-Type' ) ) . toBe ( 'application/json' ) ;
118
114
} ) ;
119
115
120
- it ( 'should decode base64 encoded body' , async ( ) => {
116
+ it ( 'decodes base64 encoded body' , async ( ) => {
121
117
const originalText = 'Hello World' ;
122
118
const base64Text = Buffer . from ( originalText ) . toString ( 'base64' ) ;
123
119
124
120
const event = {
125
121
...baseEvent ,
126
122
httpMethod : 'POST' ,
127
- requestContext : {
128
- ...baseEvent . requestContext ,
129
- httpMethod : 'POST' ,
130
- } ,
131
123
body : base64Text ,
132
124
isBase64Encoded : true ,
133
125
} ;
@@ -137,7 +129,7 @@ describe('Converters', () => {
137
129
expect ( await request . text ( ) ) . toBe ( originalText ) ;
138
130
} ) ;
139
131
140
- it ( 'should handle single-value headers' , ( ) => {
132
+ it ( 'handles single-value headers' , ( ) => {
141
133
const event = {
142
134
...baseEvent ,
143
135
headers : {
@@ -152,7 +144,7 @@ describe('Converters', () => {
152
144
expect ( request . headers . get ( 'User-Agent' ) ) . toBe ( 'test-agent' ) ;
153
145
} ) ;
154
146
155
- it ( 'should handle multiValueHeaders' , ( ) => {
147
+ it ( 'handles multiValueHeaders' , ( ) => {
156
148
const event = {
157
149
...baseEvent ,
158
150
multiValueHeaders : {
@@ -167,7 +159,7 @@ describe('Converters', () => {
167
159
expect ( request . headers . get ( 'Custom-Header' ) ) . toBe ( 'value1, value2' ) ;
168
160
} ) ;
169
161
170
- it ( 'should handle both single and multi-value headers' , ( ) => {
162
+ it ( 'handles both single and multi-value headers' , ( ) => {
171
163
const event = {
172
164
...baseEvent ,
173
165
headers : {
@@ -184,7 +176,44 @@ describe('Converters', () => {
184
176
expect ( request . headers . get ( 'Accept' ) ) . toBe ( 'application/json, text/html' ) ;
185
177
} ) ;
186
178
187
- it ( 'should handle queryStringParameters' , ( ) => {
179
+ it ( 'deduplicates headers when same header exists in both headers and multiValueHeaders' , ( ) => {
180
+ const event = {
181
+ ...baseEvent ,
182
+ headers : {
183
+ Host : 'abcd1234.execute-api.eu-west-1.amazonaws.com' ,
184
+ 'X-Forwarded-Proto' : 'https' ,
185
+ } ,
186
+ multiValueHeaders : {
187
+ Host : [ 'abcd1234.execute-api.eu-west-1.amazonaws.com' ] ,
188
+ 'X-Forwarded-Proto' : [ 'https' ] ,
189
+ } ,
190
+ } ;
191
+
192
+ const request = proxyEventToWebRequest ( event ) ;
193
+ expect ( request ) . toBeInstanceOf ( Request ) ;
194
+ expect ( request . headers . get ( 'Host' ) ) . toBe (
195
+ 'abcd1234.execute-api.eu-west-1.amazonaws.com'
196
+ ) ;
197
+ expect ( request . headers . get ( 'X-Forwarded-Proto' ) ) . toBe ( 'https' ) ;
198
+ } ) ;
199
+
200
+ it ( 'appends unique values from multiValueHeaders when header already exists' , ( ) => {
201
+ const event = {
202
+ ...baseEvent ,
203
+ headers : {
204
+ Accept : 'application/json' ,
205
+ } ,
206
+ multiValueHeaders : {
207
+ Accept : [ 'application/json' , 'text/html' ] ,
208
+ } ,
209
+ } ;
210
+
211
+ const request = proxyEventToWebRequest ( event ) ;
212
+ expect ( request ) . toBeInstanceOf ( Request ) ;
213
+ expect ( request . headers . get ( 'Accept' ) ) . toBe ( 'application/json, text/html' ) ;
214
+ } ) ;
215
+
216
+ it ( 'handles queryStringParameters' , ( ) => {
188
217
const event = {
189
218
...baseEvent ,
190
219
queryStringParameters : {
@@ -200,7 +229,7 @@ describe('Converters', () => {
200
229
expect ( url . searchParams . get ( 'age' ) ) . toBe ( '25' ) ;
201
230
} ) ;
202
231
203
- it ( 'should handle multiValueQueryStringParameters' , ( ) => {
232
+ it ( 'handles multiValueQueryStringParameters' , ( ) => {
204
233
const event = {
205
234
...baseEvent ,
206
235
multiValueQueryStringParameters : {
@@ -216,7 +245,7 @@ describe('Converters', () => {
216
245
expect ( url . searchParams . get ( 'sort' ) ) . toBe ( 'desc' ) ;
217
246
} ) ;
218
247
219
- it ( 'should handle both queryStringParameters and multiValueQueryStringParameters' , ( ) => {
248
+ it ( 'handles both queryStringParameters and multiValueQueryStringParameters' , ( ) => {
220
249
const event = {
221
250
...baseEvent ,
222
251
queryStringParameters : {
@@ -234,7 +263,7 @@ describe('Converters', () => {
234
263
expect ( url . searchParams . getAll ( 'multi' ) ) . toEqual ( [ 'value1' , 'value2' ] ) ;
235
264
} ) ;
236
265
237
- it ( 'should skip null queryStringParameter values' , ( ) => {
266
+ it ( 'skips null queryStringParameter values' , ( ) => {
238
267
const event = {
239
268
...baseEvent ,
240
269
queryStringParameters : {
@@ -250,7 +279,7 @@ describe('Converters', () => {
250
279
expect ( url . searchParams . has ( 'null' ) ) . toBe ( false ) ;
251
280
} ) ;
252
281
253
- it ( 'should skip null header values' , ( ) => {
282
+ it ( 'skips null header values' , ( ) => {
254
283
const event = {
255
284
...baseEvent ,
256
285
headers : {
@@ -265,7 +294,7 @@ describe('Converters', () => {
265
294
expect ( request . headers . get ( 'Null-Header' ) ) . toBe ( null ) ;
266
295
} ) ;
267
296
268
- it ( 'should handle null/undefined collections' , ( ) => {
297
+ it ( 'handles null/undefined collections' , ( ) => {
269
298
const event = {
270
299
...baseEvent ,
271
300
headers : null as any ,
@@ -282,7 +311,7 @@ describe('Converters', () => {
282
311
} ) ;
283
312
284
313
describe ( 'responseToProxyResult' , ( ) => {
285
- it ( 'should convert basic Response to API Gateway result' , async ( ) => {
314
+ it ( 'converts basic Response to API Gateway result' , async ( ) => {
286
315
const response = new Response ( 'Hello World' , {
287
316
status : 200 ,
288
317
headers : {
@@ -299,7 +328,7 @@ describe('Converters', () => {
299
328
expect ( result . multiValueHeaders ) . toEqual ( { } ) ;
300
329
} ) ;
301
330
302
- it ( 'should handle single-value headers' , async ( ) => {
331
+ it ( 'handles single-value headers' , async ( ) => {
303
332
const response = new Response ( 'Hello' , {
304
333
status : 201 ,
305
334
headers : { 'content-type' : 'text/plain' , 'x-custom' : 'value' } ,
@@ -315,7 +344,7 @@ describe('Converters', () => {
315
344
expect ( result . multiValueHeaders ) . toEqual ( { } ) ;
316
345
} ) ;
317
346
318
- it ( 'should handle multi-value headers' , async ( ) => {
347
+ it ( 'handles multi-value headers' , async ( ) => {
319
348
const response = new Response ( 'Hello' , {
320
349
status : 200 ,
321
350
headers : {
@@ -332,7 +361,7 @@ describe('Converters', () => {
332
361
} ) ;
333
362
} ) ;
334
363
335
- it ( 'should handle mixed single and multi-value headers' , async ( ) => {
364
+ it ( 'handles mixed single and multi-value headers' , async ( ) => {
336
365
const response = new Response ( 'Hello' , {
337
366
status : 200 ,
338
367
headers : {
@@ -351,7 +380,7 @@ describe('Converters', () => {
351
380
} ) ;
352
381
} ) ;
353
382
354
- it ( 'should handle different status codes' , async ( ) => {
383
+ it ( 'handles different status codes' , async ( ) => {
355
384
const response = new Response ( 'Not Found' , { status : 404 } ) ;
356
385
357
386
const result = await responseToProxyResult ( response ) ;
@@ -360,7 +389,7 @@ describe('Converters', () => {
360
389
expect ( result . body ) . toBe ( 'Not Found' ) ;
361
390
} ) ;
362
391
363
- it ( 'should handle empty response body' , async ( ) => {
392
+ it ( 'handles empty response body' , async ( ) => {
364
393
const response = new Response ( null , { status : 204 } ) ;
365
394
366
395
const result = await responseToProxyResult ( response ) ;
@@ -371,7 +400,7 @@ describe('Converters', () => {
371
400
} ) ;
372
401
373
402
describe ( 'handlerResultToProxyResult' , ( ) => {
374
- it ( 'should return APIGatewayProxyResult as-is' , async ( ) => {
403
+ it ( 'returns APIGatewayProxyResult as-is' , async ( ) => {
375
404
const proxyResult = {
376
405
statusCode : 200 ,
377
406
body : 'test' ,
@@ -384,7 +413,7 @@ describe('Converters', () => {
384
413
expect ( result ) . toBe ( proxyResult ) ;
385
414
} ) ;
386
415
387
- it ( 'should convert Response object' , async ( ) => {
416
+ it ( 'converts Response object' , async ( ) => {
388
417
const response = new Response ( 'Hello' , { status : 201 } ) ;
389
418
390
419
const result = await handlerResultToProxyResult ( response ) ;
@@ -394,7 +423,7 @@ describe('Converters', () => {
394
423
expect ( result . isBase64Encoded ) . toBe ( false ) ;
395
424
} ) ;
396
425
397
- it ( 'should convert plain object to JSON' , async ( ) => {
426
+ it ( 'converts plain object to JSON' , async ( ) => {
398
427
const obj = { message : 'success' , data : [ 1 , 2 , 3 ] } ;
399
428
400
429
const result = await handlerResultToProxyResult ( obj ) ;
0 commit comments