1- import { stringify } from ' querystring' ;
2- import { apiGatewayEvent } from ' serverless-plugin-test-helper' ;
3- import { Request , Body } from ' ./parser' ;
1+ import { stringify } from " querystring" ;
2+ import { apiGatewayEvent } from " serverless-plugin-test-helper" ;
3+ import { Request , Body } from " ./parser" ;
44
5- describe ( ' Body parsing' , ( ) => {
6- it ( ' Parses json body' , ( ) => {
7- const json = { hello : ' world' } ;
8- const headers = { ' content-type' : ' application/json' } ;
5+ describe ( " Body parsing" , ( ) => {
6+ it ( " Parses json body" , ( ) => {
7+ const json = { hello : " world" } ;
8+ const headers = { " content-type" : " application/json" } ;
99 const body = new Body ( JSON . stringify ( json ) , headers ) . getParsedBody ( ) ;
1010 expect ( body ) . toEqual ( json ) ;
1111 } ) ;
1212
13- it ( ' Parses json body when charset is also defined in the content-type' , ( ) => {
14- const json = { hello : ' world' } ;
15- const headers = { ' content-type' : ' application/json;charset=UTF-8' } ;
13+ it ( " Parses json body when charset is also defined in the content-type" , ( ) => {
14+ const json = { hello : " world" } ;
15+ const headers = { " content-type" : " application/json;charset=UTF-8" } ;
1616 const body = new Body ( JSON . stringify ( json ) , headers ) . getParsedBody ( ) ;
1717 expect ( body ) . toEqual ( json ) ;
1818 } ) ;
1919
20- it ( ' Parses form url encoded body' , ( ) => {
21- const form = { hello : ' world' } ;
22- const headers = { ' content-type' : ' application/x-www-form-urlencoded' } ;
20+ it ( " Parses form url encoded body" , ( ) => {
21+ const form = { hello : " world" } ;
22+ const headers = { " content-type" : " application/x-www-form-urlencoded" } ;
2323 const body = new Body ( stringify ( form ) , headers ) . getParsedBody ( ) ;
2424 expect ( body ) . toEqual ( form ) ;
2525 } ) ;
2626
27- it ( ' Parses form url encoded body when charset is also defined in the content-type' , ( ) => {
28- const form = { hello : ' world' } ;
29- const headers = { ' content-type' : ' application/x-www-form-urlencoded;charset=UTF-8' } ;
27+ it ( " Parses form url encoded body when charset is also defined in the content-type" , ( ) => {
28+ const form = { hello : " world" } ;
29+ const headers = { " content-type" : " application/x-www-form-urlencoded;charset=UTF-8" } ;
3030 const body = new Body ( stringify ( form ) , headers ) . getParsedBody ( ) ;
3131 expect ( body ) . toEqual ( form ) ;
3232 } ) ;
3333
3434 it ( "Tries to parse body as JSON when content type isn't specified" , ( ) => {
35- const json = { hello : ' world' } ;
35+ const json = { hello : " world" } ;
3636 const headers = undefined ;
3737 const body = new Body ( JSON . stringify ( json ) , headers ) . getParsedBody ( ) ;
3838 expect ( body ) . toEqual ( json ) ;
3939 } ) ;
4040
4141 it ( "Errors when encoding and content-type don't match" , ( ) => {
4242 const invalid = '2["test" : 123]4}{' ;
43- const headers = { ' content-type' : ' application/json' } ;
43+ const headers = { " content-type" : " application/json" } ;
4444 const body = new Body ( invalid , headers ) . getParsedBody ( ) ;
4545 expect ( body ) . toEqual ( invalid ) ;
4646 } ) ;
4747
48- it ( ' Returns empty body when none given' , ( ) => {
48+ it ( " Returns empty body when none given" , ( ) => {
4949 let empty ;
50- const headers = { ' content-type' : ' application/x-www-form-urlencoded' } ;
50+ const headers = { " content-type" : " application/x-www-form-urlencoded" } ;
5151 const body = new Body ( empty , headers ) . getParsedBody ( ) ;
5252 expect ( body ) . toEqual ( empty ) ;
5353 } ) ;
5454} ) ;
5555
56- describe ( ' Request parsing' , ( ) => {
57- it ( ' Gets all fields with optional parameters' , ( ) => {
56+ describe ( " Request parsing" , ( ) => {
57+ it ( " Gets all fields with optional parameters" , ( ) => {
5858 const event = apiGatewayEvent ( {
59- body : JSON . stringify ( { hello : ' world' } ) ,
60- pathParameters : { proxy : ' not today' } ,
61- queryStringParameters : { name : ' a test' } ,
62- headers : { ' content-type' : ' application/json' , 'Test-Request' : ' true' } ,
59+ body : JSON . stringify ( { hello : " world" } ) ,
60+ pathParameters : { proxy : " not today" } ,
61+ queryStringParameters : { name : " a test" } ,
62+ headers : { " content-type" : " application/json" , "test-request" : " true" } ,
6363 } ) ;
6464 const { body, path, query, auth, headers, testRequest } = new Request ( event ) . getProperties ( ) ;
6565
66- expect ( body ) . toEqual ( { hello : ' world' } ) ;
67- expect ( path ) . toEqual ( { proxy : ' not today' } ) ;
68- expect ( query ) . toEqual ( { name : ' a test' } ) ;
69- expect ( headers [ ' content-type' ] ) . toEqual ( ' application/json' ) ;
66+ expect ( body ) . toEqual ( { hello : " world" } ) ;
67+ expect ( path ) . toEqual ( { proxy : " not today" } ) ;
68+ expect ( query ) . toEqual ( { name : " a test" } ) ;
69+ expect ( headers [ " content-type" ] ) . toEqual ( " application/json" ) ;
7070 expect ( testRequest ) . toEqual ( true ) ;
7171 expect ( auth ) . toBeTruthy ( ) ;
7272 } ) ;
@@ -87,7 +87,7 @@ describe('Request parsing', () => {
8787 expect ( testRequest ) . toBeFalsy ( ) ;
8888 } ) ;
8989
90- it ( ' Supports default values in method signature' , ( ) => {
90+ it ( " Supports default values in method signature" , ( ) => {
9191 const event = apiGatewayEvent ( ) ;
9292 delete event . body ;
9393 delete event . headers ;
0 commit comments