@@ -13,8 +13,14 @@ function clone (json) {
13
13
14
14
function makeEvent ( eventOverrides ) {
15
15
const baseEvent = clone ( apiGatewayEvent )
16
- const multiValueHeaders = Object . assign ( { } , baseEvent . multiValueHeaders , eventOverrides . multiValueHeaders )
17
- const root = Object . assign ( { } , baseEvent , eventOverrides )
16
+ const multiValueHeaders = {
17
+ ...baseEvent . multiValueHeaders ,
18
+ ...eventOverrides . multiValueHeaders
19
+ }
20
+ const root = {
21
+ ...baseEvent ,
22
+ ...eventOverrides
23
+ }
18
24
root . multiValueHeaders = multiValueHeaders
19
25
root . pathParameters . proxy = eventOverrides . path && eventOverrides . path . replace ( / ^ \/ / , '' )
20
26
return root
@@ -23,9 +29,9 @@ function makeEvent (eventOverrides) {
23
29
function expectedRootResponse ( ) {
24
30
return makeResponse ( {
25
31
'multiValueHeaders' : {
26
- 'content-length' : '3747' ,
27
- 'content-type' : 'text/html; charset=utf-8' ,
28
- 'etag' : 'W/"ea3-WawLnWdlaCO/ODv9DBVcX0ZTchw"'
32
+ 'content-length' : [ '3748' ] ,
33
+ 'content-type' : [ 'text/html; charset=utf-8' ] ,
34
+ 'etag' : [ 'W/"ea4-ct1r5H/kBAj6dO7y//hr9wiNLls"' ]
29
35
}
30
36
} )
31
37
}
@@ -37,13 +43,19 @@ function makeResponse (response) {
37
43
'statusCode' : 200
38
44
}
39
45
const baseHeaders = {
40
- 'access-control-allow-origin' : '*' ,
41
- 'connection' : 'close' ,
42
- 'content-type' : 'application/json; charset=utf-8' ,
43
- 'x-powered-by' : 'Express'
46
+ 'access-control-allow-origin' : [ '*' ] ,
47
+ 'connection' : [ 'close' ] ,
48
+ 'content-type' : [ 'application/json; charset=utf-8' ] ,
49
+ 'x-powered-by' : [ 'Express' ]
50
+ }
51
+ const multiValueHeaders = {
52
+ ...baseHeaders ,
53
+ ...response . multiValueHeaders
54
+ }
55
+ const finalResponse = {
56
+ ...baseResponse ,
57
+ ...response
44
58
}
45
- const multiValueHeaders = Object . assign ( { } , baseHeaders , response . multiValueHeaders )
46
- const finalResponse = Object . assign ( { } , baseResponse , response )
47
59
finalResponse . multiValueHeaders = multiValueHeaders
48
60
return finalResponse
49
61
}
@@ -60,7 +72,7 @@ describe('integration tests', () => {
60
72
} ) , {
61
73
succeed
62
74
} )
63
- expect ( response . promise . then ) . toBeTruthy ( )
75
+ expect ( response . then ) . toBeTruthy ( )
64
76
} )
65
77
66
78
test ( 'GET HTML (initial request)' , ( done ) => {
@@ -102,8 +114,8 @@ describe('integration tests', () => {
102
114
expect ( response ) . toEqual ( makeResponse ( {
103
115
'body' : '[{"id":1,"name":"Joe"},{"id":2,"name":"Jane"}]' ,
104
116
'multiValueHeaders' : {
105
- 'content-length' : '46' ,
106
- 'etag' : 'W/"2e-Lu6qxFOQSPFulDAGUFiiK6QgREo"'
117
+ 'content-length' : [ '46' ] ,
118
+ 'etag' : [ 'W/"2e-Lu6qxFOQSPFulDAGUFiiK6QgREo"' ]
107
119
}
108
120
} ) )
109
121
done ( )
@@ -122,10 +134,10 @@ describe('integration tests', () => {
122
134
expect ( response . body . startsWith ( '<!DOCTYPE html>' ) ) . toBe ( true )
123
135
const expectedResponse = makeResponse ( {
124
136
'multiValueHeaders' : {
125
- 'content-length' : '151' ,
126
- 'content-security-policy' : "default-src 'self'" ,
127
- 'content-type' : 'text/html; charset=utf-8' ,
128
- 'x-content-type-options' : 'nosniff'
137
+ 'content-length' : [ '151' ] ,
138
+ 'content-security-policy' : [ "default-src 'self'" ] ,
139
+ 'content-type' : [ 'text/html; charset=utf-8' ] ,
140
+ 'x-content-type-options' : [ 'nosniff' ]
129
141
} ,
130
142
statusCode : 404
131
143
} )
@@ -148,8 +160,8 @@ describe('integration tests', () => {
148
160
expect ( response ) . toEqual ( makeResponse ( {
149
161
'body' : '{"id":1,"name":"Joe"}' ,
150
162
'multiValueHeaders' : {
151
- 'content-length' : '21' ,
152
- 'etag' : 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"'
163
+ 'content-length' : [ '21' ] ,
164
+ 'etag' : [ 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"' ]
153
165
}
154
166
} ) )
155
167
done ( )
@@ -168,8 +180,8 @@ describe('integration tests', () => {
168
180
expect ( response ) . toEqual ( makeResponse ( {
169
181
'body' : '{"id":1,"name":"Joe"}' ,
170
182
'multiValueHeaders' : {
171
- 'content-length' : '21' ,
172
- 'etag' : 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"'
183
+ 'content-length' : [ '21' ] ,
184
+ 'etag' : [ 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"' ]
173
185
}
174
186
} ) )
175
187
done ( )
@@ -190,8 +202,8 @@ describe('integration tests', () => {
190
202
expect ( response ) . toEqual ( makeResponse ( {
191
203
'body' : '{"id":1,"name":"Joe"}' ,
192
204
'multiValueHeaders' : {
193
- 'content-length' : '21' ,
194
- 'etag' : 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"'
205
+ 'content-length' : [ '21' ] ,
206
+ 'etag' : [ 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"' ]
195
207
}
196
208
} ) )
197
209
done ( )
@@ -203,7 +215,7 @@ describe('integration tests', () => {
203
215
} ) ,
204
216
resolutionMode : 'PROMISE'
205
217
} )
206
- . promise . then ( succeed )
218
+ . then ( succeed )
207
219
} )
208
220
209
221
test ( 'GET JSON single (resolutionMode = PROMISE; new server)' , ( done ) => {
@@ -212,8 +224,8 @@ describe('integration tests', () => {
212
224
expect ( response ) . toEqual ( makeResponse ( {
213
225
'body' : '{"id":1,"name":"Joe"}' ,
214
226
'multiValueHeaders' : {
215
- 'content-length' : '21' ,
216
- 'etag' : 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"'
227
+ 'content-length' : [ '21' ] ,
228
+ 'etag' : [ 'W/"15-rRboW+j/yFKqYqV6yklp53+fANQ"' ]
217
229
}
218
230
} ) )
219
231
newServererlessExpress . server . close ( )
@@ -224,7 +236,7 @@ describe('integration tests', () => {
224
236
path : '/users/1' ,
225
237
httpMethod : 'GET'
226
238
} )
227
- newServererlessExpress . handler ( event ) . promise . then ( succeed )
239
+ newServererlessExpress . handler ( event ) . then ( succeed )
228
240
} )
229
241
230
242
test ( 'GET JSON single 404' , ( done ) => {
@@ -233,8 +245,8 @@ describe('integration tests', () => {
233
245
expect ( response ) . toEqual ( makeResponse ( {
234
246
'body' : '{}' ,
235
247
'multiValueHeaders' : {
236
- 'content-length' : '2' ,
237
- 'etag' : 'W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"'
248
+ 'content-length' : [ '2' ] ,
249
+ 'etag' : [ 'W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"' ]
238
250
} ,
239
251
statusCode : 404
240
252
} ) )
@@ -261,10 +273,10 @@ describe('integration tests', () => {
261
273
expect ( response ) . toEqual ( makeResponse ( {
262
274
'body' : samLogoBase64 ,
263
275
'multiValueHeaders' : {
264
- 'accept-ranges' : 'bytes' ,
265
- 'cache-control' : 'public, max-age=0' ,
266
- 'content-length' : '15933' ,
267
- 'content-type' : 'image/png'
276
+ 'accept-ranges' : [ 'bytes' ] ,
277
+ 'cache-control' : [ 'public, max-age=0' ] ,
278
+ 'content-length' : [ '15933' ] ,
279
+ 'content-type' : [ 'image/png' ]
268
280
} ,
269
281
'isBase64Encoded' : true
270
282
} ) )
@@ -295,18 +307,19 @@ describe('integration tests', () => {
295
307
expect ( response ) . toEqual ( makeResponse ( {
296
308
'body' : `{"id":3,"name":"${ newName } "}` ,
297
309
'multiValueHeaders' : {
298
- 'content-length' : '43' ,
299
- 'etag' : 'W/"2b-ksYHypm1DmDdjEzhtyiv73Bluqk"'
310
+ 'content-length' : [ '43' ] ,
311
+ 'etag' : [ 'W/"2b-ksYHypm1DmDdjEzhtyiv73Bluqk"' ]
300
312
} ,
301
313
statusCode : 201
302
314
} ) )
303
315
done ( )
304
316
}
305
- serverlessExpress . handler ( makeEvent ( {
317
+ const event = makeEvent ( {
306
318
path : '/users' ,
307
319
httpMethod : 'POST' ,
308
320
body : `{"name": "${ newName } "}`
309
- } ) , {
321
+ } )
322
+ serverlessExpress . handler ( event , {
310
323
succeed
311
324
} )
312
325
} )
@@ -317,8 +330,8 @@ describe('integration tests', () => {
317
330
expect ( response ) . toEqual ( makeResponse ( {
318
331
'body' : `{"id":3,"name":"${ newName } "}` ,
319
332
'multiValueHeaders' : {
320
- 'content-length' : '43' ,
321
- 'etag' : 'W/"2b-ksYHypm1DmDdjEzhtyiv73Bluqk"'
333
+ 'content-length' : [ '43' ] ,
334
+ 'etag' : [ 'W/"2b-ksYHypm1DmDdjEzhtyiv73Bluqk"' ]
322
335
} ,
323
336
statusCode : 200
324
337
} ) )
@@ -338,8 +351,8 @@ describe('integration tests', () => {
338
351
expect ( response ) . toEqual ( makeResponse ( {
339
352
'body' : `[{"id":2,"name":"Jane"},{"id":3,"name":"${ newName } "}]` ,
340
353
'multiValueHeaders' : {
341
- 'content-length' : '68' ,
342
- 'etag' : 'W/"44-AtuxlvrIBL8NXP4gvEQTI77suNg"'
354
+ 'content-length' : [ '68' ] ,
355
+ 'etag' : [ 'W/"44-AtuxlvrIBL8NXP4gvEQTI77suNg"' ]
343
356
} ,
344
357
statusCode : 200
345
358
} ) )
@@ -359,8 +372,8 @@ describe('integration tests', () => {
359
372
expect ( response ) . toEqual ( makeResponse ( {
360
373
'body' : '{"id":2,"name":"Samuel"}' ,
361
374
'multiValueHeaders' : {
362
- 'content-length' : '24' ,
363
- 'etag' : 'W/"18-uGyzhJdtXqacOe9WRxtXSNjIk5Q"'
375
+ 'content-length' : [ '24' ] ,
376
+ 'etag' : [ 'W/"18-uGyzhJdtXqacOe9WRxtXSNjIk5Q"' ]
364
377
} ,
365
378
statusCode : 200
366
379
} ) )
@@ -381,8 +394,24 @@ describe('integration tests', () => {
381
394
expect ( response ) . toEqual ( makeResponse ( {
382
395
'body' : '{"id":2,"name":"Samuel"}' ,
383
396
'multiValueHeaders' : {
384
- 'content-length' : '24' ,
385
- 'etag' : 'W/"18-uGyzhJdtXqacOe9WRxtXSNjIk5Q"'
397
+ 'access-control-allow-origin' : [
398
+ '*'
399
+ ] ,
400
+ 'connection' : [
401
+ 'close'
402
+ ] ,
403
+ 'content-length' : [
404
+ '24'
405
+ ] ,
406
+ 'content-type' : [
407
+ 'application/json; charset=utf-8'
408
+ ] ,
409
+ 'etag' : [
410
+ 'W/"18-uGyzhJdtXqacOe9WRxtXSNjIk5Q"'
411
+ ] ,
412
+ 'x-powered-by' : [
413
+ 'Express'
414
+ ]
386
415
} ,
387
416
statusCode : 200
388
417
} ) )
@@ -416,7 +445,7 @@ describe('integration tests', () => {
416
445
httpMethod : 'GET' ,
417
446
body : '{"name": "Sam502"}' ,
418
447
multiValueHeaders : {
419
- 'Content-Length' : '-1'
448
+ 'Content-Length' : [ '-1' ]
420
449
}
421
450
} ) , {
422
451
succeed
@@ -476,7 +505,27 @@ describe('integration tests', () => {
476
505
} )
477
506
} )
478
507
479
- test . todo ( 'set-cookie' )
508
+ test ( 'Multiple headers of the same name (set-cookie)' , ( done ) => {
509
+ const succeed = response => {
510
+ delete response . multiValueHeaders . date
511
+ expect ( response ) . toEqual ( makeResponse ( {
512
+ body : '{}' ,
513
+ 'multiValueHeaders' : {
514
+ 'set-cookie' : [ 'Foo=bar; Path=/,Fizz=buzz; Path=/' ] ,
515
+ 'content-length' : [ '2' ] ,
516
+ 'etag' : [ 'W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"' ]
517
+ } ,
518
+ statusCode : 200
519
+ } ) )
520
+ done ( )
521
+ }
522
+ serverlessExpress . handler ( makeEvent ( {
523
+ path : '/cookie' ,
524
+ httpMethod : 'GET'
525
+ } ) , {
526
+ succeed
527
+ } )
528
+ } )
480
529
481
530
test ( 'server.onClose' , ( done ) => {
482
531
// NOTE: this must remain as the final test as it closes `server`
0 commit comments