From e1ae872d695a8c2b827e57e1c802fca7b2f2cc00 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Fri, 10 Feb 2017 18:31:45 -0500 Subject: [PATCH] Add .envelope() method to WPRequest --- lib/constructors/wp-request.js | 11 ++++++++++ tests/unit/lib/constructors/wp-request.js | 25 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/constructors/wp-request.js b/lib/constructors/wp-request.js index b5cf8327..5fd54bd2 100644 --- a/lib/constructors/wp-request.js +++ b/lib/constructors/wp-request.js @@ -442,6 +442,17 @@ WPRequest.prototype.embed = function() { return this.param( '_embed', true ); }; +/** + * Return response body and headers together within an envelope object. + * + * @method envelope + * @chainable + * @return {WPRequest} The WPRequest instance (for chaining) + */ +WPRequest.prototype.envelope = function() { + return this.param( '_envelope', true ); +}; + // Parameters supported by all/nearly all default collections // ========================================================== diff --git a/tests/unit/lib/constructors/wp-request.js b/tests/unit/lib/constructors/wp-request.js index 272dcc75..2a83e290 100644 --- a/tests/unit/lib/constructors/wp-request.js +++ b/tests/unit/lib/constructors/wp-request.js @@ -269,8 +269,8 @@ describe( 'WPRequest', function() { }); it( 'should set the "_embed" parameter', function() { - request.embed(); - expect( request._params._embed ).to.equal( true ); + var path = request.embed().toString(); + expect( path ).to.equal( '/?_embed=true' ); }); it( 'should be chainable', function() { @@ -279,6 +279,27 @@ describe( 'WPRequest', function() { }); + describe( '.envelope()', function() { + + it( 'is defined', function() { + expect( request ).to.have.property( 'envelope' ); + }); + + it( 'is a function', function() { + expect( request.envelope ).to.be.a( 'function' ); + }); + + it( 'should set the "_envelope" parameter', function() { + var path = request.envelope().toString(); + expect( path ).to.equal( '/?_envelope=true' ); + }); + + it( 'should be chainable', function() { + expect( request.envelope() ).to.equal( request ); + }); + + }); + describe( '.page()', function() { it( 'is defined', function() {