diff --git a/lib/run_action.js b/lib/run_action.js index e99fa0a..c65de14 100644 --- a/lib/run_action.js +++ b/lib/run_action.js @@ -66,8 +66,15 @@ function runAction(base, method, path, queryParams, bodyData, callback, numAttem resp.json() .then(function(body) { var error = base._checkStatusForError(resp.status, body); - resp.statusCode = resp.status; - callback(error, resp, body); + // Ensure Response interface matches interface from + // `request` Response object + var r = {}; + Object.keys(resp).forEach(function(property) { + r[property] = resp[property]; + }); + r.body = body; + r.statusCode = resp.status; + callback(error, r, body); }) .catch(function() { callback(base._checkStatusForError(resp.status)); diff --git a/test/base.test.js b/test/base.test.js index 4a594b1..33d5533 100644 --- a/test/base.test.js +++ b/test/base.test.js @@ -539,6 +539,21 @@ describe('Base', function() { }); }); + it('exposes the body of the request directly on the response', function(done) { + testExpressApp.set('handler override', function(req, res) { + res.json({ + fizz: 'buzz', + }); + }); + + fakeBase.runAction('get', '/', {}, null, function(err, res, body) { + expect(err).toBeNull(); + expect(res.body.fizz).toBe('buzz'); + expect(body.fizz).toBe('buzz'); + done(); + }); + }); + it('makes requests GET requests with empty bodies', function(done) { expect(version).toEqual(expect.stringMatching(/^\d+\.\d+\.\d+$/));