Repository: cloudant/nodejs-cloudant (js)

Issue:
Return values when using Promises plugin not correct
Please include the following information in your ticket.

- Cloudant (nodejs-cloudant) version(s) that are affected by this issue: Tested on 2.1.0 and 2.2.0
- Node version : v6.11.0
- A small code sample that demonstrates the issue.

This may be user error, but I'm struggling with the promises plugin.  Return values from a simple get seem to include a statusCode field in the body:

~~~~
const Cloudant = require('@cloudant/cloudant');
const cloudant = new Cloudant({ url: CDB_URL, plugins: [ 'promises', { retry: { retryDelayMultiplier: 4 } } ] });
    let db = cloudant.use("someDb");
    db.get("someId")
        .then((res) => {
            console.log(res)
       });
~~~~

The output would be something like:


{ endpoints: [],
  agentc:
   { switch:
      { certs: [Object],
        url: 'blah' } },
  statusCode: 200 }

which includes a statusCode.

The effects are worse when using attachments as db.attachment.get does not return a Byte stream, but an Object which includes a statusCode.

If I use regular callbacks, all works as expected.  Hopefully this is simple error on my part, but if someone could help me out that would be great.

Pull request description:
Removed addition of statusCode to response objects
Thanks for your hard work, please ensure all items are complete before opening.

- [x] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://github.com/cloudant/nodejs-cloudant/blob/master/DCO1.1.txt)
- [x] You have added tests for any code changes
- [x] You have updated the [CHANGES.md](https://github.com/cloudant/nodejs-cloudant/blob/master/CHANGES.md)
- [x] You have completed the PR template below:

## What
Removed addition of `statusCode` to response objects.

## Testing
Update existing unit test to assert object key length.

## Issues
Fixes #308.

Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 1c5ed2c..791edbb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,4 +1,5 @@
 # UNRELEASED
+- [FIXED] Removed addition of `statusCode` to response objects returned by promises.
 - [IMPROVED] Added support for IAM API key when initializing client with VCAP_SERVICES environment variable.
 
 # 2.2.0 (2018-04-30)
diff --git a/lib/client.js b/lib/client.js
index 9e0be59..67b34fd 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -205,7 +205,6 @@ class CloudantClient {
           if (data) {
             try {
               data = JSON.parse(data);
-              data.statusCode = response.statusCode;
             } catch (err) {}
           } else {
             data = { statusCode: response.statusCode };


Test patch:
diff --git a/test/client.js b/test/client.js
index d5063b8..ce52e46 100644
--- a/test/client.js
+++ b/test/client.js
@@ -1327,20 +1327,21 @@ describe('CloudantClient', function() {
     describe('with no other plugins', function() {
       it('performs request and returns response with promise client', function(done) {
         var mocks = nock(SERVER)
-            .get(DBNAME)
-            .reply(200, {doc_count: 1});
+            .get(`${DBNAME}/${DOCID}`)
+            .reply(200, { _id: DOCID, _rev: '1-xxxxxx', foo: 'bar' });
 
         var cloudantClient = new Client({ plugins: 'promises' });
         assert.equal(cloudantClient._plugins.length, 0);
         assert.ok(cloudantClient._cfg.usePromises);
 
         var options = {
-          url: SERVER + DBNAME,
+          url: SERVER + DBNAME + '/' + DOCID,
           auth: { username: ME, password: PASSWORD },
           method: 'GET'
         };
         var p = cloudantClient.request(options).then(function(data) {
-          assert.equal(data.doc_count, 1);
+          assert.equal(Object.keys(data).length, 3);
+          assert.equal(data.foo, 'bar');
           mocks.done();
           done();
         }).catch(function(err) {