@@ -11,6 +11,7 @@ const {
1111 baseUrl,
1212 decodeEventBody,
1313 decodeToken,
14+ ensureCharacterEncoding,
1415 isFromReadingRoom,
1516 maybeUseProxiedIp,
1617 normalizeHeaders,
@@ -403,4 +404,35 @@ describe("helpers", () => {
403404 expect ( result . queryStringParameters ) . to . eql ( { } ) ;
404405 } ) ;
405406 } ) ;
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+ } ) ;
406438} ) ;
0 commit comments