@@ -2,34 +2,37 @@ const { Request } = require('./request');
22
33describe ( 'Request object' , ( ) => {
44 const requestObject = { a :1 } ;
5- const event = {
6- body : JSON . stringify ( requestObject ) ,
7- headers : {
8- 'Content-Type' : 'application/json' ,
9- 'Content-Length' : JSON . stringify ( requestObject ) . length ,
10- 'X-Header' : 'value2'
11- } ,
12- multiValueHeaders : {
13- 'Content-Type' : [ 'application/json' ] ,
14- 'Content-Length' : [ JSON . stringify ( requestObject ) . length ] ,
15- 'X-Header' : [ 'value1' , 'value2' ]
16- } ,
17- httpMethod : 'POST' ,
18- isBase64Encoded : false ,
19- path : '/path' ,
20- pathParameters : { } ,
21- queryStringParameters : {
22- a : '1' ,
23- b : '2'
24- } ,
25- multiValueQueryStringParameters : {
26- a : [ '1' ] ,
27- b : [ '1' , '2' ]
28- } ,
29- stageVariables : { } ,
30- requestContext : { } ,
31- resource : ''
32- } ;
5+ let event ;
6+ beforeEach ( ( ) => {
7+ event = {
8+ body : JSON . stringify ( requestObject ) ,
9+ headers : {
10+ 'Content-Type' : 'application/json' ,
11+ 'Content-Length' : JSON . stringify ( requestObject ) . length ,
12+ 'X-Header' : 'value2'
13+ } ,
14+ multiValueHeaders : {
15+ 'Content-Type' : [ 'application/json' ] ,
16+ 'Content-Length' : [ JSON . stringify ( requestObject ) . length ] ,
17+ 'X-Header' : [ 'value1' , 'value2' ]
18+ } ,
19+ httpMethod : 'POST' ,
20+ isBase64Encoded : false ,
21+ path : '/path' ,
22+ pathParameters : { } ,
23+ queryStringParameters : {
24+ a : '1' ,
25+ b : '2'
26+ } ,
27+ multiValueQueryStringParameters : {
28+ a : [ '1' ] ,
29+ b : [ '1' , '2' ]
30+ } ,
31+ stageVariables : { } ,
32+ requestContext : { } ,
33+ resource : ''
34+ } ;
35+ } ) ;
3336
3437 it ( 'should read query parameter' , ( ) => {
3538 const request = new Request ( event ) ;
@@ -57,6 +60,20 @@ describe('Request object', () => {
5760 expect ( request . get ( 'X-Header' ) ) . toEqual ( [ 'value1' , 'value2' ] ) ;
5861 } ) ;
5962
63+ it ( 'should read query as empty object if there is no queryparamters' , ( ) => {
64+ delete event . multiValueQueryStringParameters ;
65+ const request = new Request ( event ) ;
66+
67+ expect ( request . query ) . toEqual ( { } ) ;
68+ } ) ;
69+
70+ it ( 'should read headers as empty object if there is no headers' , ( ) => {
71+ delete event . multiValueHeaders ;
72+ const request = new Request ( event ) ;
73+
74+ expect ( request . headers ) . toEqual ( { } ) ;
75+ } ) ;
76+
6077 it ( 'should handle weird header asks' , ( ) => {
6178 const request = new Request ( event ) ;
6279
0 commit comments