Skip to content

Commit

Permalink
Additional options on getByEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpatrick committed Jan 21, 2021
1 parent 050a4b8 commit 3cf81a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/management/UsersManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var ArgumentError = require('rest-facade').ArgumentError;
var Auth0RestClient = require('../Auth0RestClient');
var RetryRestClient = require('../RetryRestClient');
var sanitizeArguments = require('../utils').sanitizeArguments;

/**
* Simple facade for consuming a REST API endpoint.
Expand Down Expand Up @@ -238,13 +239,18 @@ UsersManager.prototype.getAll = function(params) {
* console.log(users);
* });
*
* @param {String} [email] Email address of user(s) to find
* @param {Function} [cb] Callback function.
* @param {String} [email] Email address of user(s) to find
* @param {Object} [options] Additional options to pass to the endpoint
* @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result
* @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
UsersManager.prototype.getByEmail = function(email, callback) {
return this.usersByEmail.getAll({ email }, callback);
UsersManager.prototype.getByEmail = function(email, options, cb) {
var { options, cb } = sanitizeArguments(options, cb);

return this.usersByEmail.getAll({ email, ...options }, cb);
};

/**
Expand Down
7 changes: 5 additions & 2 deletions src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,11 @@ utils.wrapPropertyMethod(ManagementClient, 'getUsers', 'users.getAll');
* console.log(users);
* });
*
* @param {String} [email] Email Address of users to locate
* @param {Function} [cb] Callback function.
* @param {String} [email] Email address of user(s) to find
* @param {Object} [options] Additional options to pass to the endpoint
* @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result
* @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
Expand Down
24 changes: 24 additions & 0 deletions test/management/users.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,30 @@ describe('UsersManager', function() {
done();
});
});

it('should pass additional options into the query string', function(done) {
nock.cleanAll();

var additionalOptions = {
fields: 'user_id, email, email_verified',
include_fields: true
};
var params = {
email: '[email protected]',
...additionalOptions
};

var request = nock(API_URL)
.get('/users-by-email')
.query(params)
.reply(200);

this.users.getByEmail(params.email, additionalOptions).then(function() {
expect(request.isDone()).to.be.true;

done();
});
});
});

describe('#get', function() {
Expand Down

0 comments on commit 3cf81a4

Please sign in to comment.