Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for checking connection status #662

Merged
merged 4 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 'user@domain.com';
Expand Down