HttpDataApi: Only serialize JSON on POST
* src/dapi/http/HttpDataApi.js (_encodeKeys): JSON.stringify on POST. * test/dapi/http/HttpDataApiTest.js: Update tests accordingly. Add POST test.master
parent
ae9c293518
commit
020ca01458
|
@ -206,6 +206,11 @@ module.exports = Class( 'HttpDataApi' )
|
|||
{
|
||||
var uri = '';
|
||||
|
||||
if ( this._method === 'POST' )
|
||||
{
|
||||
return JSON.stringify( obj );
|
||||
}
|
||||
|
||||
// ES3 support
|
||||
for ( var key in obj )
|
||||
{
|
||||
|
|
|
@ -105,7 +105,7 @@ describe( 'HttpDataApi', function()
|
|||
*/
|
||||
it( 'delegates to provided HTTP implementation', function()
|
||||
{
|
||||
var method = 'POST',
|
||||
var method = 'GET',
|
||||
data = "ribbit",
|
||||
c = function() {};
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe( 'HttpDataApi', function()
|
|||
{
|
||||
it( 'converts data into encoded string', function()
|
||||
{
|
||||
var method = 'POST',
|
||||
var method = 'GET',
|
||||
data = { foo: "bar=baz", '&bar': "moo%cow" },
|
||||
c = function() {};
|
||||
|
||||
|
@ -143,7 +143,7 @@ describe( 'HttpDataApi', function()
|
|||
|
||||
it( 'with no keys, results in empty string', function()
|
||||
{
|
||||
var method = 'POST',
|
||||
var method = 'GET',
|
||||
data = {},
|
||||
c = function() {};
|
||||
|
||||
|
@ -151,6 +151,20 @@ describe( 'HttpDataApi', function()
|
|||
|
||||
expect( impl.provided[ 2 ] ).to.equal( "" );
|
||||
} );
|
||||
|
||||
|
||||
it( 'encodes JSON on POST', () =>
|
||||
{
|
||||
var method = 'POST',
|
||||
data = { foo: 'bar' },
|
||||
c = () => {};
|
||||
|
||||
Sut( dummy_url, method, impl ).request( data, c );
|
||||
|
||||
expect( impl.provided[ 2 ] ).to.equal(
|
||||
JSON.stringify( data )
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue