Repository: auth0/node-auth0 (ts)

Issue:
Support the check connection status endpoint
### Describe the problem you'd like to have solved

The auth0 docs describe a "check connection status" endpoint for verifying whether a connection is live (see https://auth0.com/docs/api/management/v2#!/Connections/get_status). It looks this route is not supported as part of the connections section of the management client.

### Describe the ideal solution

Ideally, you'd be able to do something like `client.connections.checkStatus({ id })` or possibly (depends on rest-facade) `client.connections.status.get({ id })`.

## Alternatives and current work-arounds

I thought about trying to hack around this using some of the underlying rest client features, but rest-facade doesn't (as far as I can tell) support additional pathing (which this would require). That aside, I think I have to write my own function using fetch and handling authentication manually.

### Additional information, if any

None


Pull request description:
Add support for checking connection status
### Changes

Adds support for the missing endpoint to check a connection's status: https://auth0.com/docs/api/management/v2#!/Connections/get_status.

Can be used:

```javascript
auth0.connections.checkStatus({ id })
  .then(() => /* ONLINE */)
  .catch(() => /* OFFLINE */);
```
or
```javascript
auth0.connections.checkStatus({ id }, function(err, result) => {
  if (err) {
    /* OFFLINE */
  } else {
    /* ONLINE */
  }
});
```

### References

Closes #655

### Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors. 

- [x] This change adds unit test coverage
- [ ] This change adds integration test coverage

### Checklist

- [x] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [x] All existing and new tests complete without errors


Patch:
diff --git a/src/management/ConnectionsManager.js b/src/management/ConnectionsManager.js
index 87ebd6e5a..f10f291c0 100644
--- a/src/management/ConnectionsManager.js
+++ b/src/management/ConnectionsManager.js
@@ -51,6 +51,13 @@ var ConnectionsManager = function(options) {
   );
   this.resource = new RetryRestClient(auth0RestClient, options.retry);
 
+  var statusClient = new Auth0RestClient(
+    options.baseUrl + '/connections/:id/status',
+    clientOptions,
+    options.tokenProvider
+  );
+  this.status = new RetryRestClient(statusClient, options.retry);
+
   /**
    * Provides an abstraction layer for consuming the
    * {@link https://auth0.com/docs/api/management/v2#!/Connections/delete_users_by_email
@@ -192,6 +199,34 @@ utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
  */
 utils.wrapPropertyMethod(ConnectionsManager, 'delete', 'resource.delete');
 
+/**
+ * Checks the status of an ad/ldap connection referenced by its ID.
+ *
+ * @method    checkStatus
+ * @memberOf  module:management.OrganizationsManager.prototype
+ *
+ * @example
+ * var params = {id : 'CONNECTION_ID'}
+ * @example <caption>
+ *   This methods takes the connection ID and returns the status when online, or an error when offline.
+ * </caption>
+ *
+ * management.connections.checkStatus( {id : 'CONNECTION_ID'}, function (err, status) {
+ *   if (err) {
+ *     console.log('OFFLINE', err);
+ *   } else {
+ *     console.log('ONLINE', status);
+ *   }
+ * });
+ *
+ * @param   {Object}    params              Connection parameters
+ * @param   {String}    params.id           ID of the Connection.
+ * @param   {Function}  [cb]                Callback function.
+ *
+ * @return  {Promise|undefined}
+ */
+utils.wrapPropertyMethod(ConnectionsManager, 'checkStatus', 'status.get');
+
 /**
  * Delete a connection user by email.
  *


Test patch:
diff --git a/test/management/connections.tests.js b/test/management/connections.tests.js
index 828356252..6c983fdf8 100644
--- a/test/management/connections.tests.js
+++ b/test/management/connections.tests.js
@@ -455,6 +455,60 @@ describe('ConnectionsManager', function() {
     });
   });
 
+  describe('#checkStatus', function() {
+    var params = { id: 5 };
+    var data = {
+      id: params.id,
+      name: 'Test connection'
+    };
+
+    beforeEach(function() {
+      this.request = nock(API_URL)
+        .get('/connections/' + data.id + '/status')
+        .reply(200);
+    });
+
+    it('should accept a callback', function(done) {
+      this.connections.checkStatus(params, function() {
+        done();
+      });
+    });
+
+    it('should return a promise if no callback is given', function(done) {
+      this.connections
+        .checkStatus(params)
+        .then(done.bind(null, null))
+        .catch(done.bind(null, null));
+    });
+
+    it('should report success', function(done) {
+      nock.cleanAll();
+
+      var request = nock(API_URL)
+        .get('/connections/' + params.id + '/status')
+        .reply(200);
+
+      this.connections.checkStatus(params).then(function(response) {
+        expect(response).to.exist;
+        done();
+      });
+    });
+
+    it('should report failure', function(done) {
+      nock.cleanAll();
+
+      var request = nock(API_URL)
+        .get('/connections/' + params.id + '/status')
+        .reply(500);
+
+      this.connections.checkStatus(params).catch(function(err) {
+        expect(err).to.exist;
+
+        done();
+      });
+    });
+  });
+
   describe('#delete user', function() {
     var id = 5;
     var email = 'user@domain.com';