@@ -154,31 +154,50 @@ describe("httpRequest", () => {
154
154
done ( ) ;
155
155
} )
156
156
} ) ;
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
+ }
158
162
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' ) ;
161
166
done ( ) ;
162
167
163
168
} )
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
+ }
165
176
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"}' ) ;
168
179
done ( ) ;
169
- } ) ;
170
- it ( "should not encode a wrong content type" , ( done ) => {
171
180
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" ) ;
174
189
done ( ) ;
175
190
} ) ;
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" } ) ;
179
198
done ( ) ;
180
199
} ) ;
181
-
200
+
182
201
it ( "should fail gracefully" , ( done ) => {
183
202
httpRequest ( {
184
203
url : "http://not a good url" ,
0 commit comments