Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-04-14 12:06:43 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-04-14 12:08:00 -0400
commita6115018d24387796b59f7f31885589008872589 (patch)
tree1b17c429455c31903a01c2d1d1e7f2d5ed3bebbf /test
parent413df53f4ff3e473240b7ecb2c727855d1b3036f (diff)
downloadliza-a6115018d24387796b59f7f31885589008872589.tar.gz
liza-a6115018d24387796b59f7f31885589008872589.tar.bz2
liza-a6115018d24387796b59f7f31885589008872589.zip
Add x-www-form-urlencoded header for XhrHttpImpl
It might be the case that we may want to post raw data in the future; in fact, I can guarantee it. We'll cross that bridge when we come to it. * src/dapi/http/XhrHttpImpl.js (openRequest): Set ContentType header on POST * test/dapi/http/XhrHttpImplTest.js: Modified accordingly
Diffstat (limited to 'test')
-rw-r--r--test/dapi/http/XhrHttpImplTest.js54
1 files changed, 50 insertions, 4 deletions
diff --git a/test/dapi/http/XhrHttpImplTest.js b/test/dapi/http/XhrHttpImplTest.js
index ffa5ca2..93df02e 100644
--- a/test/dapi/http/XhrHttpImplTest.js
+++ b/test/dapi/http/XhrHttpImplTest.js
@@ -170,34 +170,79 @@ describe( 'XhrHttpImpl', function()
.requestData( url, 'GET', "", done );
} );
+
+ it( 'does not set Content-Type', function( done )
+ {
+ var url = 'http://bar',
+ StubXhr = createStubXhr();
+
+ StubXhr.prototype.readyState = 4; // done
+ StubXhr.prototype.status = 200; // OK
+
+ StubXhr.prototype.setRequestHeader = function()
+ {
+ // warning: this is fragile, if additional headers are
+ // ever set
+ throw Error( 'Headers should not be set on GET' );
+ };
+
+ Sut( StubXhr )
+ .requestData( url, 'GET', "", done );
+ } );
} );
describe( 'HTTP method is not GET', function()
{
- it( 'sends data verbatim', function( done )
+ it( 'sends data verbatim as x-www-form-urlencoded', function( done )
{
var url = 'http://bar',
src = "moocow",
- StubXhr = createStubXhr();
+ StubXhr = createStubXhr(),
+
+ open_called = false,
+ send_called = false,
+ header_called = false;
StubXhr.prototype.readyState = 4; // done
StubXhr.prototype.status = 200; // OK
StubXhr.prototype.open = function( _, given_url )
{
+ open_called = true;
+
// URL should be unchanged
expect( given_url ).to.equal( url );
};
StubXhr.prototype.send = function( data )
{
+ send_called = true;
+
expect( data ).is.equal( src );
StubXhr.inst.onreadystatechange();
};
+ StubXhr.prototype.setRequestHeader = function( name, val )
+ {
+ header_called = true;
+
+ // warning: this is fragile, if additional headers are
+ // ever set
+ expect( name ).to.equal( 'Content-Type' );
+ expect( val ).to.equal(
+ 'application/x-www-form-urlencoded'
+ );
+ };
+
Sut( StubXhr )
- .requestData( url, 'POST', src, done );
+ .requestData( url, 'POST', src, function()
+ {
+ console.log( open_called, send_called, header_called );
+ expect( open_called && send_called && header_called )
+ .to.be.true;
+ done();
+ } );
} );
} );
@@ -346,7 +391,8 @@ function createStubXhr()
send: function( data )
{
this.onreadystatechange();
- }
+ },
+ setRequestHeader: function() {},
};
return StubXhr;