Repository: auth0/node-auth0
Pull request #252 (2018-03-28 14:18:10)

Fixing some docs issues
fix https://github.com/auth0/node-auth0/issues/251


Patch:
diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js
index 36f334f1a..48bdb6895 100644
--- a/src/management/UsersManager.js
+++ b/src/management/UsersManager.js
@@ -38,7 +38,7 @@ var UsersManager = function (options){
     headers: options.headers,
     query: { repeatParams: false }
   };
-  
+
   var usersAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id', clientOptions, options.tokenProvider);
   this.users = new RetryRestClient(usersAuth0RestClient, options.retry);
 
@@ -417,13 +417,13 @@ UsersManager.prototype.deleteMultifactorProvider = function (params, cb) {
  * @memberOf  module:management.UsersManager.prototype
  *
  * @example
- * var params = { id: USER_ID };
- * var data = {
- * 	user_id: 'OTHER_USER_ID',
- * 	connection_id: 'CONNECTION_ID'
+ * var userId = 'USER_ID';
+ * var params = {
+ *   user_id: 'OTHER_USER_ID',
+ *   connection_id: 'CONNECTION_ID'
  * };
  *
- * management.users.link(params, data, function (err, user) {
+ * management.users.link(userId, params, function (err, user) {
  *   if (err) {
  *     // Handle error.
  *   }
@@ -444,9 +444,12 @@ UsersManager.prototype.link = function (userId, params, cb) {
   params = params || {};
 
   // Require a user ID.
-  if (!userId || typeof userId !== 'string') {
+  if (!userId) {
     throw new ArgumentError('The userId cannot be null or undefined');
   }
+  if (typeof userId !== 'string') {
+    throw new ArgumentError('The userId has to be a string');
+  }
 
   if (cb && cb instanceof Function) {
     return this.identities.create(query, params, cb);
diff --git a/src/management/index.js b/src/management/index.js
index ddb024606..5b4878ee2 100644
--- a/src/management/index.js
+++ b/src/management/index.js
@@ -123,9 +123,9 @@ var ManagementClient = function (options) {
     var telemetry = jsonToBase64(options.clientInfo || this.getClientInfo());
     managerOptions.headers['Auth0-Client'] = telemetry;
   }
-  
+
   managerOptions.retry = options.retry;
-  
+
   /**
    * Simple abstraction for performing CRUD operations on the
    * clients endpoint.
@@ -1078,13 +1078,13 @@ utils.wrapPropertyMethod(ManagementClient, 'unlinkUsers', 'users.unlink');
  * @memberOf  module:management.ManagementClient.prototype
  *
  * @example
- * var params = { id: USER_ID };
- * var data = {
+ * var userId = 'USER_ID';
+ * var params = {
  *   user_id: 'OTHER_USER_ID',
  *   connection_id: 'CONNECTION_ID'
  * };
  *
- * management.linkUsers(params, data, function (err, user) {
+ * management.linkUsers(userId, params, function (err, user) {
  *   if (err) {
  *     // Handle error.
  *   }


Test patch:
diff --git a/test/management/users.tests.js b/test/management/users.tests.js
index 75905e49d..1147f319a 100644
--- a/test/management/users.tests.js
+++ b/test/management/users.tests.js
@@ -698,8 +698,21 @@ describe('UsersManager', function () {
       this.request = nock(API_URL)
         .post('/users/' + userId + '/identities')
         .reply(200);
-    })
+    });
 
+    it('should validate empty userId', function () {
+      var _this = this;
+      expect(function() {
+        _this.users.link(null, data, function () {});
+      }).to.throw('The userId cannot be null or undefined');
+    });
+
+    it('should validate non-string userId', function () {
+      var _this = this;
+      expect(function() {
+        _this.users.link(123, data, function () {});
+      }).to.throw('The userId has to be a string');
+    });
 
     it('should accept a callback', function (done) {
       this