@@ -154,31 +154,50 @@ describe("httpRequest", () => {
154154 done ( ) ;
155155 } )
156156 } ) ;
157- it ( "should encode a JSON body" , ( done ) => {
157+ it ( "should encode a JSON body by default" , ( done ) => {
158+
159+ let options = {
160+ body : { "foo" : "bar" } ,
161+ }
158162
159- var result = httpRequest . encodeBody ( { "foo" : "bar" } , { 'Content-Type' : 'application/json' } ) ;
160- expect ( result ) . toEqual ( '{"foo":"bar"}' ) ;
163+ var result = httpRequest . encodeBody ( options ) ;
164+ expect ( result . body ) . toEqual ( '{"foo":"bar"}' ) ;
165+ expect ( result . headers [ 'Content-Type' ] ) . toEqual ( 'application/json' ) ;
161166 done ( ) ;
162167
163168 } )
164- it ( "should encode a www-form body" , ( done ) => {
169+
170+ it ( "should encode a JSON body" , ( done ) => {
171+
172+ let options = {
173+ body : { "foo" : "bar" } ,
174+ headers : { 'Content-Type' : 'application/json' }
175+ }
165176
166- var result = httpRequest . encodeBody ( { "foo" : "bar" , "bar" : "baz" } , { 'cOntent-tYpe' : 'application/x-www-form-urlencoded' } ) ;
167- expect ( result ) . toEqual ( "foo= bar&bar=baz" ) ;
177+ var result = httpRequest . encodeBody ( options ) ;
178+ expect ( result . body ) . toEqual ( '{ "foo":" bar"}' ) ;
168179 done ( ) ;
169- } ) ;
170- it ( "should not encode a wrong content type" , ( done ) => {
171180
172- var result = httpRequest . encodeBody ( { "foo" : "bar" , "bar" : "baz" } , { 'cOntent-tYpe' : 'mime/jpeg' } ) ;
173- expect ( result ) . toEqual ( { "foo" : "bar" , "bar" : "baz" } ) ;
181+ } )
182+ it ( "should encode a www-form body" , ( done ) => {
183+ let options = {
184+ body : { "foo" : "bar" , "bar" : "baz" } ,
185+ headers : { 'cOntent-tYpe' : 'application/x-www-form-urlencoded' }
186+ }
187+ var result = httpRequest . encodeBody ( options ) ;
188+ expect ( result . body ) . toEqual ( "foo=bar&bar=baz" ) ;
174189 done ( ) ;
175190 } ) ;
176- it ( "should not encode when missing content type" , ( done ) => {
177- var result = httpRequest . encodeBody ( { "foo" : "bar" , "bar" : "baz" } , { 'X-Custom-Header' : 'my-header' } ) ;
178- expect ( result ) . toEqual ( { "foo" : "bar" , "bar" : "baz" } ) ;
191+ it ( "should not encode a wrong content type" , ( done ) => {
192+ let options = {
193+ body :{ "foo" : "bar" , "bar" : "baz" } ,
194+ headers : { 'cOntent-tYpe' : 'mime/jpeg' }
195+ }
196+ var result = httpRequest . encodeBody ( options ) ;
197+ expect ( result . body ) . toEqual ( { "foo" : "bar" , "bar" : "baz" } ) ;
179198 done ( ) ;
180199 } ) ;
181-
200+
182201 it ( "should fail gracefully" , ( done ) => {
183202 httpRequest ( {
184203 url : "http://not a good url" ,
0 commit comments