Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2015-05-28 12:16:02 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2015-05-28 15:15:41 -0400
commit881e740bb9de26e9d62b9806560c833efddf397a (patch)
tree1282f968228513e17b6985860fb44bc1e4a7dada /test
parentca68d12370e6505cd6faaccac817d06d5f095275 (diff)
downloadliza-881e740bb9de26e9d62b9806560c833efddf397a.tar.gz
liza-881e740bb9de26e9d62b9806560c833efddf397a.tar.bz2
liza-881e740bb9de26e9d62b9806560c833efddf397a.zip
JsonResponse returns parse error or combined request/parse on failure
Diffstat (limited to 'test')
-rw-r--r--test/dapi/format/JsonResponseTest.js57
1 files changed, 46 insertions, 11 deletions
diff --git a/test/dapi/format/JsonResponseTest.js b/test/dapi/format/JsonResponseTest.js
index 633a93f..f74ea50 100644
--- a/test/dapi/format/JsonResponseTest.js
+++ b/test/dapi/format/JsonResponseTest.js
@@ -83,19 +83,54 @@ describe( 'dapi.format.JsonRepsonse trait', function()
} );
- it( 'proxy error from encapsulated DataApi', function( done )
+ describe( 'on request error from supertype', function()
{
- var e = Error( 'foo' ),
- chk = {};
+ it( 'attempts to format output as JSON', function( done )
+ {
+ var chk = '{"foo": "bar"}';
- _createStubbedDapi( e, chk )
- .request( '', function( err, data )
- {
- // data should also be cleared out
- expect( err ).to.equal( e );
- expect( data ).to.equal( chk );
- done();
- } );
+ _createStubbedDapi( null, chk )
+ .request( '', function( _, data )
+ {
+ expect( data ).to.be.a( 'object' );
+ expect( data.foo ).to.equal( "bar" );
+ done();
+ } );
+ } );
+
+
+ it( 'proxies error when JSON output valid', function( done )
+ {
+ var e = Error( 'foo' );
+
+ _createStubbedDapi( e, '{}' )
+ .request( '', function( err, _ )
+ {
+ expect( err ).to.equal( e );
+ done();
+ } );
+ } );
+
+
+ it( 'produces both errors on bad JSON output', function( done )
+ {
+ var e = Error( 'foo' );
+
+ _createStubbedDapi( e, 'BAD JSON' )
+ .request( '', function( err, _ )
+ {
+ // the main error should indicate both
+ expect( err ).to.be.instanceOf( Error );
+
+ // and we should provide references to both
+ expect( err.list[ 0 ] ).to.equal( e );
+ expect( err.list[ 1 ] ).to.be.instanceOf(
+ SyntaxError
+ );
+
+ done();
+ } );
+ } );
} );
} );
} );