@@ -11,6 +11,7 @@ const {
11
11
baseUrl,
12
12
decodeEventBody,
13
13
decodeToken,
14
+ ensureCharacterEncoding,
14
15
isFromReadingRoom,
15
16
maybeUseProxiedIp,
16
17
normalizeHeaders,
@@ -403,4 +404,35 @@ describe("helpers", () => {
403
404
expect ( result . queryStringParameters ) . to . eql ( { } ) ;
404
405
} ) ;
405
406
} ) ;
407
+
408
+ describe ( "ensureCharacterEncoding" , ( ) => {
409
+ const response = { statusCode : 200 , body : "Hello, World!" } ;
410
+
411
+ it ( "passes through an existing character set" , ( ) => {
412
+ const result = ensureCharacterEncoding ( {
413
+ ...response ,
414
+ headers : { "Content-Type" : "text/plain; charset=ISO-8859-1" } ,
415
+ } ) ;
416
+ expect ( result . headers [ "Content-Type" ] ) . to . eql (
417
+ "text/plain; charset=ISO-8859-1"
418
+ ) ;
419
+ } ) ;
420
+
421
+ it ( "adds character set if it's missing" , ( ) => {
422
+ const result = ensureCharacterEncoding ( {
423
+ ...response ,
424
+ headers : { "Content-Type" : "text/plain" } ,
425
+ } ) ;
426
+ expect ( result . headers [ "Content-Type" ] ) . to . eql (
427
+ "text/plain; charset=UTF-8"
428
+ ) ;
429
+ } ) ;
430
+
431
+ it ( "adds content type if it's missing" , ( ) => {
432
+ const result = ensureCharacterEncoding ( { ...response , headers : { } } ) ;
433
+ expect ( result . headers [ "Content-Type" ] ) . to . eql (
434
+ "application/json; charset=UTF-8"
435
+ ) ;
436
+ } ) ;
437
+ } ) ;
406
438
} ) ;
0 commit comments