Skip to content

Commit

Permalink
Add support for checking connection status (#662)
Browse files Browse the repository at this point in the history
* Add support for checking connection status

* update example

* Update example

* Remove unused import
  • Loading branch information
frederikprijck authored Oct 4, 2021
1 parent 9b44014 commit 0d83e5d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/management/ConnectionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
54 changes: 54 additions & 0 deletions test/management/connections.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
Expand Down

0 comments on commit 0d83e5d

Please sign in to comment.