diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 000000000..5ac85e271
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,4 @@
+{
+ "printWidth": 100,
+ "singleQuote": true
+}
diff --git a/package.json b/package.json
index 1a55d5382..5f48c73ef 100644
--- a/package.json
+++ b/package.json
@@ -5,23 +5,22 @@
"main": "src/index.js",
"scripts": {
"test": "mocha -R spec $(find ./test -name *.tests.js)",
- "test:ci": "istanbul cover _mocha --report lcovonly -R $(find ./test -name *.tests.js) -- -R mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
+ "test:ci":
+ "istanbul cover _mocha --report lcovonly -R $(find ./test -name *.tests.js) -- -R mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
"test:coverage": "codecov",
"test:watch": "NODE_ENV=test mocha --timeout 5000 $(find ./test -name *.tests.js) --watch",
"jsdoc:generate": "jsdoc --configure .jsdoc.json --verbose",
"release:clean": "node scripts/cleanup.js",
"preversion": "node scripts/prepare.js",
"version": "node scripts/changelog.js && node scripts/jsdocs.js",
- "postversion": "npm run release:clean"
+ "postversion": "npm run release:clean",
+ "precommit": "pretty-quick --staged"
},
"repository": {
"type": "git",
"url": "https://github.com/auth0/node-auth0"
},
- "keywords": [
- "auth0",
- "api"
- ],
+ "keywords": ["auth0", "api"],
"author": "Auth0",
"license": "MIT",
"bugs": {
@@ -39,6 +38,7 @@
"devDependencies": {
"chai": "^2.2.0",
"codecov": "^2.2.0",
+ "husky": "^0.14.3",
"istanbul": "^0.4.0",
"jsdoc": "^3.4.0",
"json-loader": "^0.5.4",
@@ -48,6 +48,8 @@
"mocha-multi": "^0.11.0",
"moment": "^2.18.1",
"nock": "^3.1.1",
+ "prettier": "^1.12.0",
+ "pretty-quick": "^1.4.1",
"sinon": "^1.17.1",
"string-replace-webpack-plugin": "0.0.3",
"webpack": "^1.12.14"
diff --git a/src/Auth0RestClient.js b/src/Auth0RestClient.js
index 0b29e8e06..fb44de7e5 100644
--- a/src/Auth0RestClient.js
+++ b/src/Auth0RestClient.js
@@ -2,7 +2,7 @@ var RestClient = require('rest-facade').Client;
var Promise = require('bluebird');
var ArgumentError = require('rest-facade').ArgumentError;
-var Auth0RestClient = function (resourceUrl, options, provider) {
+var Auth0RestClient = function(resourceUrl, options, provider) {
if (resourceUrl === null || resourceUrl === undefined) {
throw new ArgumentError('Must provide a Resource Url');
}
@@ -19,53 +19,54 @@ var Auth0RestClient = function (resourceUrl, options, provider) {
this.provider = provider;
this.restClient = new RestClient(resourceUrl, options);
- this.wrappedProvider = function (method, args) {
+ this.wrappedProvider = function(method, args) {
if (!this.provider) {
return this.restClient[method].apply(this.restClient, args);
}
var callback;
- if(args && args[args.length -1] instanceof Function){
- callback = args[args.length -1];
+ if (args && args[args.length - 1] instanceof Function) {
+ callback = args[args.length - 1];
}
var self = this;
- return this.provider.getAccessToken()
- .then(function (access_token) {
+ return this.provider
+ .getAccessToken()
+ .then(function(access_token) {
self.options.headers['Authorization'] = 'Bearer ' + access_token;
return self.restClient[method].apply(self.restClient, args);
- }).catch(function(err){
- if(callback){
+ })
+ .catch(function(err) {
+ if (callback) {
return callback(err);
}
return Promise.reject(err);
});
- }
+ };
};
-Auth0RestClient.prototype.getAll = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.getAll = function(/* [params], [callback] */) {
return this.wrappedProvider('getAll', arguments);
};
-
-Auth0RestClient.prototype.get = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.get = function(/* [params], [callback] */) {
return this.wrappedProvider('get', arguments);
-}
+};
-Auth0RestClient.prototype.create = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.create = function(/* [params], [callback] */) {
return this.wrappedProvider('create', arguments);
-}
+};
-Auth0RestClient.prototype.patch = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.patch = function(/* [params], [callback] */) {
return this.wrappedProvider('patch', arguments);
-}
+};
-Auth0RestClient.prototype.update = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.update = function(/* [params], [callback] */) {
return this.wrappedProvider('update', arguments);
-}
+};
-Auth0RestClient.prototype.delete = function ( /* [params], [callback] */ ) {
+Auth0RestClient.prototype.delete = function(/* [params], [callback] */) {
return this.wrappedProvider('delete', arguments);
-}
+};
module.exports = Auth0RestClient;
diff --git a/src/RetryRestClient.js b/src/RetryRestClient.js
index 78b7cd097..28ea9cf43 100644
--- a/src/RetryRestClient.js
+++ b/src/RetryRestClient.js
@@ -1,4 +1,3 @@
-
var Promise = require('bluebird');
var retry = require('retry');
var ArgumentError = require('rest-facade').ArgumentError;
@@ -13,10 +12,10 @@ var DEFAULT_OPTIONS = { maxRetries: 10, enabled: true };
* @memberOf module:management
* @param {Object} restClient RestClient.
* @param {Object} [options] Options for the RetryRestClient.
- * @param {Object} [options.enabled:true] Enabled or Disable Retry Policy functionality.
- * @param {Number} [options.maxRetries=10] The maximum amount of times to retry the operation. Default is 10.
+ * @param {Object} [options.enabled:true] Enabled or Disable Retry Policy functionality.
+ * @param {Number} [options.maxRetries=10] The maximum amount of times to retry the operation. Default is 10.
*/
-var RetryRestClient = function(restClient, options){
+var RetryRestClient = function(restClient, options) {
if (restClient === null || typeof restClient !== 'object') {
throw new ArgumentError('Must provide RestClient');
}
@@ -34,54 +33,52 @@ var RetryRestClient = function(restClient, options){
this.restClient = restClient;
this.maxRetries = params.maxRetries;
this.enabled = params.enabled;
-}
+};
-RetryRestClient.prototype.getAll = function ( /* [params], [callback] */ ) {
- return this.invoke('getAll', arguments);
+RetryRestClient.prototype.getAll = function(/* [params], [callback] */) {
+ return this.invoke('getAll', arguments);
};
-RetryRestClient.prototype.get = function ( /* [params], [callback] */ ) {
- return this.invoke('get', arguments);
-}
+RetryRestClient.prototype.get = function(/* [params], [callback] */) {
+ return this.invoke('get', arguments);
+};
-RetryRestClient.prototype.create = function ( /* [params], [callback] */ ) {
- return this.invoke('create', arguments);
-}
+RetryRestClient.prototype.create = function(/* [params], [callback] */) {
+ return this.invoke('create', arguments);
+};
-RetryRestClient.prototype.patch = function ( /* [params], [callback] */ ) {
- return this.invoke('patch', arguments);
-}
+RetryRestClient.prototype.patch = function(/* [params], [callback] */) {
+ return this.invoke('patch', arguments);
+};
-RetryRestClient.prototype.update = function ( /* [params], [callback] */ ) {
- return this.invoke('update', arguments);
-}
+RetryRestClient.prototype.update = function(/* [params], [callback] */) {
+ return this.invoke('update', arguments);
+};
-RetryRestClient.prototype.delete = function ( /* [params], [callback] */ ) {
- return this.invoke('delete', arguments);
-}
+RetryRestClient.prototype.delete = function(/* [params], [callback] */) {
+ return this.invoke('delete', arguments);
+};
-RetryRestClient.prototype.invoke = function(method, args){
+RetryRestClient.prototype.invoke = function(method, args) {
var cb;
args = Array.prototype.slice.call(args); // convert array-like object to array.
- if(args && args[args.length -1] instanceof Function){
- cb = args[args.length -1];
+ if (args && args[args.length - 1] instanceof Function) {
+ cb = args[args.length - 1];
args.pop(); // Remove the callback
}
var promise = this.handleRetry(method, args);
if (cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
return promise;
-}
+};
-RetryRestClient.prototype.handleRetry = function(method, args){
- if(!this.enabled){
+RetryRestClient.prototype.handleRetry = function(method, args) {
+ if (!this.enabled) {
return this.restClient[method].apply(this.restClient, args);
}
@@ -93,12 +90,13 @@ RetryRestClient.prototype.handleRetry = function(method, args){
};
var self = this;
- var promise = new Promise(function (resolve, reject) {
+ var promise = new Promise(function(resolve, reject) {
var operation = retry.operation(retryOptions);
- operation.attempt(function(){
- self.restClient[method].apply(self.restClient, args)
- .then(function(body) {
+ operation.attempt(function() {
+ self.restClient[method]
+ .apply(self.restClient, args)
+ .then(function(body) {
resolve(body);
})
.catch(function(err) {
@@ -110,51 +108,49 @@ RetryRestClient.prototype.handleRetry = function(method, args){
return promise;
};
-RetryRestClient.prototype.invokeRetry = function(err, operation , reject){
+RetryRestClient.prototype.invokeRetry = function(err, operation, reject) {
var ratelimits = this.extractRatelimits(err);
- if(ratelimits){
+ if (ratelimits) {
var delay = ratelimits.reset * 1000 - new Date().getTime();
- if(delay > 0){
+ if (delay > 0) {
this.retryWithDelay(delay, operation, err, reject);
- }else{
+ } else {
this.retryWithImmediate(operation, err, reject);
- }
- }else{
+ }
+ } else {
reject(err);
- }
-}
+ }
+};
-RetryRestClient.prototype.extractRatelimits = function(err){
- if(err && err.statusCode === 429 && err.originalError && err.originalError.response){
+RetryRestClient.prototype.extractRatelimits = function(err) {
+ if (err && err.statusCode === 429 && err.originalError && err.originalError.response) {
var headers = err.originalError.response.header;
- if(headers && headers['x-ratelimit-limit']){
+ if (headers && headers['x-ratelimit-limit']) {
return {
limit: headers['x-ratelimit-limit'],
remaining: headers['x-ratelimit-remaining'],
reset: headers['x-ratelimit-reset']
- }
+ };
}
}
return;
-}
+};
-RetryRestClient.prototype.retryWithImmediate = function(operation, err, reject){
- if(operation.retry(err)){
+RetryRestClient.prototype.retryWithImmediate = function(operation, err, reject) {
+ if (operation.retry(err)) {
return;
- }
+ }
reject(err);
-}
+};
-RetryRestClient.prototype.retryWithDelay = function(delay, operation, err, reject){
+RetryRestClient.prototype.retryWithDelay = function(delay, operation, err, reject) {
setTimeout(() => {
- if(operation.retry(err)){
+ if (operation.retry(err)) {
return;
}
reject(err);
}, delay);
-}
-
-
+};
module.exports = RetryRestClient;
diff --git a/src/auth/DatabaseAuthenticator.js b/src/auth/DatabaseAuthenticator.js
index 86afff830..96a9e18ee 100644
--- a/src/auth/DatabaseAuthenticator.js
+++ b/src/auth/DatabaseAuthenticator.js
@@ -3,7 +3,6 @@ var extend = require('util')._extend;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;
-
/**
* @class
* Abstracts the sign-in, sign-up and change-password processes for Database &
@@ -16,7 +15,7 @@ var RestClient = require('rest-facade').Client;
* @param {String} [options.clientId] Default client ID.
* @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
*/
-var DatabaseAuthenticator = function (options, oauth) {
+var DatabaseAuthenticator = function(options, oauth) {
if (!options) {
throw new ArgumentError('Missing authenticator options');
}
@@ -39,7 +38,6 @@ var DatabaseAuthenticator = function (options, oauth) {
this.clientId = options.clientId;
};
-
/**
* Sign in using a database or active directory service.
* @method signIn
@@ -75,7 +73,7 @@ var DatabaseAuthenticator = function (options, oauth) {
*
* @return {Promise|undefined}
*/
-DatabaseAuthenticator.prototype.signIn = function (userData, cb) {
+DatabaseAuthenticator.prototype.signIn = function(userData, cb) {
var defaultFields = {
connection: 'Username-Password-Authentication'
};
@@ -85,20 +83,17 @@ DatabaseAuthenticator.prototype.signIn = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.username !== 'string'
- || data.username.trim().length === 0) {
+ if (typeof data.username !== 'string' || data.username.trim().length === 0) {
throw new ArgumentError('username field is required');
}
- if (typeof data.password !== 'string'
- || data.password.trim().length === 0) {
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
throw new ArgumentError('password field is required');
}
return this.oauth.signIn(data, cb);
};
-
/**
* Sign up using a database or active directory service.
* @method signUp
@@ -133,7 +128,7 @@ DatabaseAuthenticator.prototype.signIn = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-DatabaseAuthenticator.prototype.signUp = function (userData, cb) {
+DatabaseAuthenticator.prototype.signUp = function(userData, cb) {
var params = {
type: 'signup'
};
@@ -146,18 +141,15 @@ DatabaseAuthenticator.prototype.signUp = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.email !== 'string'
- || data.email.trim().length === 0) {
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
throw new ArgumentError('email field is required');
}
- if (typeof data.password !== 'string'
- || data.password.trim().length === 0) {
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
throw new ArgumentError('password field is required');
}
- if (typeof data.connection !== 'string'
- || data.connection.trim().length === 0) {
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
throw new ArgumentError('connection field is required');
}
@@ -168,7 +160,6 @@ DatabaseAuthenticator.prototype.signUp = function (userData, cb) {
return this.dbConnections.create(params, data);
};
-
/**
* Change password using a database or active directory service.
*
@@ -206,7 +197,7 @@ DatabaseAuthenticator.prototype.signUp = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-DatabaseAuthenticator.prototype.changePassword = function (userData, cb) {
+DatabaseAuthenticator.prototype.changePassword = function(userData, cb) {
var params = {
type: 'change_password'
};
@@ -219,18 +210,15 @@ DatabaseAuthenticator.prototype.changePassword = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.email !== 'string'
- || data.email.trim().length === 0) {
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
throw new ArgumentError('email field is required');
}
- if (typeof data.password !== 'string'
- || data.password.trim().length === 0) {
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
throw new ArgumentError('password field is required');
}
- if (typeof data.connection !== 'string'
- || data.connection.trim().length === 0) {
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
throw new ArgumentError('connection field is required');
}
@@ -241,7 +229,6 @@ DatabaseAuthenticator.prototype.changePassword = function (userData, cb) {
return this.dbConnections.create(params, data);
};
-
/**
* Request a change password email using a database or active directory service.
*
@@ -276,7 +263,7 @@ DatabaseAuthenticator.prototype.changePassword = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-DatabaseAuthenticator.prototype.requestChangePasswordEmail = function (userData, cb) {
+DatabaseAuthenticator.prototype.requestChangePasswordEmail = function(userData, cb) {
var params = {
type: 'change_password'
};
@@ -289,13 +276,11 @@ DatabaseAuthenticator.prototype.requestChangePasswordEmail = function (userData,
throw new ArgumentError('Missing user data object');
}
- if (typeof data.email !== 'string'
- || data.email.trim().length === 0) {
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
throw new ArgumentError('email field is required');
}
- if (typeof data.connection !== 'string'
- || data.connection.trim().length === 0) {
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
throw new ArgumentError('connection field is required');
}
@@ -306,5 +291,4 @@ DatabaseAuthenticator.prototype.requestChangePasswordEmail = function (userData,
return this.dbConnections.create(params, data);
};
-
module.exports = DatabaseAuthenticator;
diff --git a/src/auth/OAuthAuthenticator.js b/src/auth/OAuthAuthenticator.js
index 902d7eebb..125b8878e 100644
--- a/src/auth/OAuthAuthenticator.js
+++ b/src/auth/OAuthAuthenticator.js
@@ -3,7 +3,6 @@ var extend = require('util')._extend;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;
-
/**
* @class
* Abstracts the sign-in, sign-up and change-password processes for Database &
@@ -16,7 +15,7 @@ var RestClient = require('rest-facade').Client;
* @param {String} [options.clientId] Default client ID.
* @param {String} [options.clientSecret] Default client Secret.
*/
-var OAuthAuthenticator = function (options) {
+var OAuthAuthenticator = function(options) {
if (!options) {
throw new ArgumentError('Missing authenticator options');
}
@@ -39,7 +38,6 @@ var OAuthAuthenticator = function (options) {
this.clientSecret = options.clientSecret;
};
-
/**
* Sign in using a username and password.
*
@@ -78,7 +76,7 @@ var OAuthAuthenticator = function (options) {
*
* @return {Promise|undefined}
*/
-OAuthAuthenticator.prototype.signIn = function (userData, cb) {
+OAuthAuthenticator.prototype.signIn = function(userData, cb) {
var params = {
type: 'ro'
};
@@ -93,9 +91,7 @@ OAuthAuthenticator.prototype.signIn = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.connection !== 'string'
- || data.connection.split().length === 0)
- {
+ if (typeof data.connection !== 'string' || data.connection.split().length === 0) {
throw new ArgumentError('connection field is required');
}
@@ -145,7 +141,7 @@ OAuthAuthenticator.prototype.signIn = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-OAuthAuthenticator.prototype.passwordGrant = function (userData, cb) {
+OAuthAuthenticator.prototype.passwordGrant = function(userData, cb) {
var params = {
type: 'token'
};
@@ -160,18 +156,15 @@ OAuthAuthenticator.prototype.passwordGrant = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.username !== 'string'
- || data.username.split().length === 0) {
+ if (typeof data.username !== 'string' || data.username.split().length === 0) {
throw new ArgumentError('username field is required');
}
- if (typeof data.password !== 'string'
- || data.password.split().length === 0) {
+ if (typeof data.password !== 'string' || data.password.split().length === 0) {
throw new ArgumentError('password field is required');
}
- if (typeof data.realm === 'string'
- && data.realm.split().length !== 0) {
+ if (typeof data.realm === 'string' && data.realm.split().length !== 0) {
data.grant_type = 'http://auth0.com/oauth/grant-type/password-realm';
}
@@ -194,7 +187,7 @@ OAuthAuthenticator.prototype.passwordGrant = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-OAuthAuthenticator.prototype.socialSignIn = function (data, cb) {
+OAuthAuthenticator.prototype.socialSignIn = function(data, cb) {
var params = {
type: 'access_token'
};
@@ -203,13 +196,11 @@ OAuthAuthenticator.prototype.socialSignIn = function (data, cb) {
throw new ArgumentError('Missing user credential objects');
}
- if (typeof data.access_token !== 'string'
- || data.access_token.trim().length === 0) {
+ if (typeof data.access_token !== 'string' || data.access_token.trim().length === 0) {
throw new ArgumentError('access_token field is required');
}
- if (typeof data.connection !== 'string'
- || data.connection.trim().length === 0) {
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
throw new ArgumentError('connection field is required');
}
@@ -221,15 +212,14 @@ OAuthAuthenticator.prototype.socialSignIn = function (data, cb) {
};
OAuthAuthenticator.prototype.clientCredentialsGrant = function(options, cb) {
-
var params = {
type: 'token'
};
var defaultFields = {
- grant_type: "client_credentials",
- client_id: this.clientId,
- client_secret: this.clientSecret
+ grant_type: 'client_credentials',
+ client_id: this.clientId,
+ client_secret: this.clientSecret
};
var data = extend(defaultFields, options);
diff --git a/src/auth/PasswordlessAuthenticator.js b/src/auth/PasswordlessAuthenticator.js
index 5759b7685..99c124275 100644
--- a/src/auth/PasswordlessAuthenticator.js
+++ b/src/auth/PasswordlessAuthenticator.js
@@ -3,7 +3,6 @@ var extend = require('util')._extend;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;
-
/**
* @class
* Handles authenticator with passwordless flows, e.g. SMS, Touch ID, etc.
@@ -15,7 +14,7 @@ var RestClient = require('rest-facade').Client;
* @param {String} [options.clientId] Default client ID.
* @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
*/
-var PasswordlessAuthenticator = function (options, oauth) {
+var PasswordlessAuthenticator = function(options, oauth) {
if (!options) {
throw new ArgumentError('Missing authenticator options');
}
@@ -38,7 +37,6 @@ var PasswordlessAuthenticator = function (options, oauth) {
this.clientId = options.clientId;
};
-
/**
* Sign in with the given user credentials.
*
@@ -80,34 +78,33 @@ var PasswordlessAuthenticator = function (options, oauth) {
*
* @return {Promise|undefined}
*/
-PasswordlessAuthenticator.prototype.signIn = function (userData, cb) {
+PasswordlessAuthenticator.prototype.signIn = function(userData, cb) {
var defaultFields = {
client_id: this.clientId
};
var data = extend(defaultFields, userData);
// Don't let the user override the connection nor the grant type.
- if (!data.connection || (data.connection !== 'email' && data.connection !== 'sms')) { data.connection = 'sms'; }
+ if (!data.connection || (data.connection !== 'email' && data.connection !== 'sms')) {
+ data.connection = 'sms';
+ }
data.grant_type = 'password';
if (!userData || typeof userData !== 'object') {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.username !== 'string'
- || data.username.trim().length === 0) {
+ if (typeof data.username !== 'string' || data.username.trim().length === 0) {
throw new ArgumentError('username field (phone number) is required');
}
- if (typeof data.password !== 'string'
- || data.password.trim().length === 0) {
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
throw new ArgumentError('password field (verification code) is required');
}
return this.oauth.signIn(data, cb);
};
-
/**
* Start passwordless flow sending an email.
*
@@ -153,7 +150,7 @@ PasswordlessAuthenticator.prototype.signIn = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-PasswordlessAuthenticator.prototype.sendEmail = function (userData, cb) {
+PasswordlessAuthenticator.prototype.sendEmail = function(userData, cb) {
var defaultFields = {
client_id: this.clientId
};
@@ -166,13 +163,11 @@ PasswordlessAuthenticator.prototype.sendEmail = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.email !== 'string'
- || data.email.trim().length === 0) {
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
throw new ArgumentError('email field is required');
}
- if (typeof data.send !== 'string'
- || data.send.trim().length === 0) {
+ if (typeof data.send !== 'string' || data.send.trim().length === 0) {
throw new ArgumentError('send field is required');
}
@@ -183,7 +178,6 @@ PasswordlessAuthenticator.prototype.sendEmail = function (userData, cb) {
return this.passwordless.create(data);
};
-
/**
* Start passwordless flow sending an SMS.
*
@@ -214,7 +208,7 @@ PasswordlessAuthenticator.prototype.sendEmail = function (userData, cb) {
*
* @return {Promise|undefined}
*/
-PasswordlessAuthenticator.prototype.sendSMS = function (userData, cb) {
+PasswordlessAuthenticator.prototype.sendSMS = function(userData, cb) {
var defaultFields = {
client_id: this.clientId
};
@@ -227,8 +221,7 @@ PasswordlessAuthenticator.prototype.sendSMS = function (userData, cb) {
throw new ArgumentError('Missing user data object');
}
- if (typeof data.phone_number !== 'string'
- || data.phone_number.trim().length === 0) {
+ if (typeof data.phone_number !== 'string' || data.phone_number.trim().length === 0) {
throw new ArgumentError('phone_number field is required');
}
@@ -239,5 +232,4 @@ PasswordlessAuthenticator.prototype.sendSMS = function (userData, cb) {
return this.passwordless.create(data);
};
-
module.exports = PasswordlessAuthenticator;
diff --git a/src/auth/TokensManager.js b/src/auth/TokensManager.js
index 5b6afb4e2..b8c5af22a 100644
--- a/src/auth/TokensManager.js
+++ b/src/auth/TokensManager.js
@@ -3,7 +3,6 @@ var getRequestPromise = require('../utils').getRequestPromise;
var ArgumentError = require('rest-facade').ArgumentError;
-
/**
* @class
* Provides methods for getting token data and exchanging tokens.
@@ -15,7 +14,7 @@ var ArgumentError = require('rest-facade').ArgumentError;
* @param {String} [options.headers] Default request headers.
* @param {String} [options.clientId] Default client ID.
*/
-var TokensManager = function (options) {
+var TokensManager = function(options) {
if (typeof options !== 'object') {
throw new ArgumentError('Missing tokens manager options');
}
@@ -29,7 +28,6 @@ var TokensManager = function (options) {
this.clientId = options.clientId || '';
};
-
/**
* Given an ID token get the user profile linked to it.
*
@@ -56,7 +54,7 @@ var TokensManager = function (options) {
*
* @return {Promise|undefined}
*/
-TokensManager.prototype.getInfo = function (idToken, cb) {
+TokensManager.prototype.getInfo = function(idToken, cb) {
var headers = extend({}, this.headers);
if (idToken === null || idToken === undefined) {
@@ -77,16 +75,13 @@ TokensManager.prototype.getInfo = function (idToken, cb) {
// Use callback if given.
if (cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
return promise;
};
-
/**
* Exchange the token of the logged in user with a token that is valid to call
* the API (signed with the API secret).
@@ -127,19 +122,18 @@ TokensManager.prototype.getInfo = function (idToken, cb) {
*
* @return {Promise|undefined}
*/
-TokensManager.prototype.getDelegationToken = function (data, cb) {
- var body = extend({ client_id : this.clientId }, data);
+TokensManager.prototype.getDelegationToken = function(data, cb) {
+ var body = extend({ client_id: this.clientId }, data);
var headers = this.headers;
if (!data) {
throw new ArgumentError('Missing token data object');
}
- var hasIdToken = typeof data.id_token === 'string'
- && data.id_token.trim().length !== 0;
+ var hasIdToken = typeof data.id_token === 'string' && data.id_token.trim().length !== 0;
- var hasRefreshToken = typeof data.refresh_token === 'string'
- && data.refresh_token.trim().length !== 0;
+ var hasRefreshToken =
+ typeof data.refresh_token === 'string' && data.refresh_token.trim().length !== 0;
if (!hasIdToken && !hasRefreshToken) {
throw new ArgumentError('one of id_token or refresh_token is required');
@@ -149,18 +143,15 @@ TokensManager.prototype.getDelegationToken = function (data, cb) {
throw new ArgumentError('id_token and refresh_token fields cannot be specified simulatenously');
}
- if (typeof data.target !== 'string'
- || data.target.trim().length === 0) {
+ if (typeof data.target !== 'string' || data.target.trim().length === 0) {
throw new ArgumentError('target field is required');
}
- if (typeof data.api_type !== 'string'
- || data.api_type.trim().length === 0) {
+ if (typeof data.api_type !== 'string' || data.api_type.trim().length === 0) {
throw new ArgumentError('api_type field is required');
}
- if (typeof data.grant_type !== 'string'
- || data.grant_type.trim().length === 0) {
+ if (typeof data.grant_type !== 'string' || data.grant_type.trim().length === 0) {
throw new ArgumentError('grant_type field is required');
}
@@ -174,14 +165,11 @@ TokensManager.prototype.getDelegationToken = function (data, cb) {
// Use callback if given.
if (cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
return promise;
};
-
module.exports = TokensManager;
diff --git a/src/auth/UsersManager.js b/src/auth/UsersManager.js
index 874f56f89..94e4606da 100644
--- a/src/auth/UsersManager.js
+++ b/src/auth/UsersManager.js
@@ -3,7 +3,6 @@ var getRequestPromise = require('../utils').getRequestPromise;
var ArgumentError = require('rest-facade').ArgumentError;
-
/**
* @class
* Provides methods for getting user information and impersonating users.
@@ -15,7 +14,7 @@ var ArgumentError = require('rest-facade').ArgumentError;
* @param {String} [options.headers] Default request headers.
* @param {String} [options.clientId] Default client ID.
*/
-var UsersManager = function (options) {
+var UsersManager = function(options) {
if (typeof options !== 'object') {
throw new ArgumentError('Missing users manager options');
}
@@ -29,7 +28,6 @@ var UsersManager = function (options) {
this.clientId = options.clientId;
};
-
/**
* Given an access token get the user profile linked to it.
*
@@ -55,7 +53,7 @@ var UsersManager = function (options) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.getInfo = function (accessToken, cb) {
+UsersManager.prototype.getInfo = function(accessToken, cb) {
var url = this.baseUrl + '/userinfo';
var headers = extend({}, this.headers);
@@ -80,16 +78,13 @@ UsersManager.prototype.getInfo = function (accessToken, cb) {
// Use callback if given.
if (cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
return promise;
};
-
/**
* Impersonate the user with the given user ID.
*
@@ -126,7 +121,7 @@ UsersManager.prototype.getInfo = function (accessToken, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.impersonate = function (userId, settings, cb) {
+UsersManager.prototype.impersonate = function(userId, settings, cb) {
var url = this.baseUrl + '/users/' + userId + '/impersonate';
if (userId === null || userId === undefined) {
@@ -141,23 +136,23 @@ UsersManager.prototype.impersonate = function (userId, settings, cb) {
throw new ArgumentError('Missing impersonation settings object');
}
- if (typeof settings.impersonator_id !== 'string'
- || settings.impersonator_id.trim().length === 0) {
+ if (
+ typeof settings.impersonator_id !== 'string' ||
+ settings.impersonator_id.trim().length === 0
+ ) {
throw new ArgumentError('impersonator_id field is required');
}
- if (typeof settings.protocol !== 'string'
- || settings.protocol.trim().length === 0) {
+ if (typeof settings.protocol !== 'string' || settings.protocol.trim().length === 0) {
throw new ArgumentError('protocol field is required');
}
- if (typeof settings.token !== 'string'
- || settings.token.trim().length === 0) {
+ if (typeof settings.token !== 'string' || settings.token.trim().length === 0) {
throw new ArgumentError('token field is required');
}
var data = extend({ client_id: settings.clientId || this.clientId }, settings);
- var headers = extend({'Authorization': `Bearer ${settings.token}`}, this.headers);
+ var headers = extend({ Authorization: `Bearer ${settings.token}` }, this.headers);
// Perform the request.
var promise = getRequestPromise({
method: 'POST',
@@ -168,14 +163,11 @@ UsersManager.prototype.impersonate = function (userId, settings, cb) {
// Use callback if given.
if (cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
return promise;
};
-
module.exports = UsersManager;
diff --git a/src/auth/index.js b/src/auth/index.js
index a8d2e4227..56df17e83 100644
--- a/src/auth/index.js
+++ b/src/auth/index.js
@@ -18,7 +18,6 @@ var TokensManager = require('./TokensManager');
var BASE_URL_FORMAT = 'https://%s';
-
/**
* @class
* Authentication API SDK.
@@ -46,11 +45,9 @@ var BASE_URL_FORMAT = 'https://%s';
* @param {String} [options.clientId] Default client ID.
* @param {String} [options.clientSecret] Default client Secret.
*/
-var AuthenticationClient = function (options) {
+var AuthenticationClient = function(options) {
if (!options || typeof options !== 'object') {
- throw new ArgumentError(
- 'Authentication Client SDK options must be an object'
- );
+ throw new ArgumentError('Authentication Client SDK options must be an object');
}
if (!options.domain || options.domain.length === 0) {
@@ -109,7 +106,6 @@ var AuthenticationClient = function (options) {
this.tokens = new TokensManager(managerOptions);
};
-
/**
* Return an object with information about the current client,
*
@@ -118,31 +114,30 @@ var AuthenticationClient = function (options) {
*
* @return {Object} Object containing client information.
*/
-AuthenticationClient.prototype.getClientInfo = function () {
+AuthenticationClient.prototype.getClientInfo = function() {
var clientInfo = {
name: 'node-auth0',
version: pkg.version,
dependencies: [],
- environment: [{
- name: 'node.js',
- version: process.version.replace('v', '')
- }]
+ environment: [
+ {
+ name: 'node.js',
+ version: process.version.replace('v', '')
+ }
+ ]
};
// Add the dependencies to the client info object.
- Object
- .keys(pkg.dependencies)
- .forEach(function (name) {
- clientInfo.dependencies.push({
- name: name,
- version: pkg.dependencies[name]
- });
+ Object.keys(pkg.dependencies).forEach(function(name) {
+ clientInfo.dependencies.push({
+ name: name,
+ version: pkg.dependencies[name]
});
+ });
return clientInfo;
};
-
/**
* Start passwordless flow sending an email.
*
@@ -177,13 +172,12 @@ AuthenticationClient.prototype.getClientInfo = function () {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.requestMagicLink = function (data, cb) {
+AuthenticationClient.prototype.requestMagicLink = function(data, cb) {
data.send = 'link';
return this.passwordless.sendEmail(data, cb);
};
-
/**
* Start passwordless flow sending an email.
*
@@ -216,13 +210,12 @@ AuthenticationClient.prototype.requestMagicLink = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.requestEmailCode = function (data, cb) {
+AuthenticationClient.prototype.requestEmailCode = function(data, cb) {
data.send = 'code';
return this.passwordless.sendEmail(data, cb);
};
-
/**
* Start passwordless flow sending an SMS.
*
@@ -252,7 +245,7 @@ AuthenticationClient.prototype.requestEmailCode = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.requestSMSCode = function (data, cb) {
+AuthenticationClient.prototype.requestSMSCode = function(data, cb) {
var translatedData = {
phone_number: data.phoneNumber || data.phone_number
};
@@ -260,7 +253,6 @@ AuthenticationClient.prototype.requestSMSCode = function (data, cb) {
return this.passwordless.sendSMS(translatedData, cb);
};
-
/**
* Sign in with the given user credentials.
*
@@ -302,7 +294,7 @@ AuthenticationClient.prototype.requestSMSCode = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.verifySMSCode = function (data, cb) {
+AuthenticationClient.prototype.verifySMSCode = function(data, cb) {
var translatedData = {
username: data.phoneNumber || data.phone_number || data.username,
password: data.code || data.password
@@ -311,7 +303,6 @@ AuthenticationClient.prototype.verifySMSCode = function (data, cb) {
return this.passwordless.signIn(translatedData, cb);
};
-
/**
* Exchange the token of the logged in user with a token that is valid to call
* the API (signed with the API secret).
@@ -350,7 +341,7 @@ AuthenticationClient.prototype.verifySMSCode = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.getDelegationToken = function (data, cb) {
+AuthenticationClient.prototype.getDelegationToken = function(data, cb) {
var translatedData = {
id_token: data.id_token,
api_type: data.api || data.api_type,
@@ -362,7 +353,6 @@ AuthenticationClient.prototype.getDelegationToken = function (data, cb) {
return this.tokens.getDelegationToken(translatedData, cb);
};
-
/**
* Change password using a database or active directory service.
*
@@ -399,7 +389,7 @@ AuthenticationClient.prototype.getDelegationToken = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.changePassword = function (data, cb) {
+AuthenticationClient.prototype.changePassword = function(data, cb) {
var translatedData = {
connection: data.connection,
email: data.email || data.username,
@@ -409,7 +399,6 @@ AuthenticationClient.prototype.changePassword = function (data, cb) {
return this.database.changePassword(data, cb);
};
-
/**
* Request a change password email using a database or active directory service.
*
@@ -443,7 +432,7 @@ AuthenticationClient.prototype.changePassword = function (data, cb) {
*
* @return {Promise|undefined}
*/
-AuthenticationClient.prototype.requestChangePasswordEmail = function (data, cb) {
+AuthenticationClient.prototype.requestChangePasswordEmail = function(data, cb) {
var translatedData = {
connection: data.connection,
email: data.email || data.username
@@ -452,7 +441,6 @@ AuthenticationClient.prototype.requestChangePasswordEmail = function (data, cb)
return this.database.requestChangePasswordEmail(data, cb);
};
-
/**
* Given an access token get the user profile linked to it.
*
@@ -507,7 +495,11 @@ utils.wrapPropertyMethod(AuthenticationClient, 'getProfile', 'users.getInfo');
*
* @return {Promise|undefined}
*/
-utils.wrapPropertyMethod(AuthenticationClient, 'clientCredentialsGrant', 'oauth.clientCredentialsGrant');
+utils.wrapPropertyMethod(
+ AuthenticationClient,
+ 'clientCredentialsGrant',
+ 'oauth.clientCredentialsGrant'
+);
/**
* Sign in using a username and password
diff --git a/src/management/BlacklistedTokensManager.js b/src/management/BlacklistedTokensManager.js
index 46dc706de..9da308df4 100644
--- a/src/management/BlacklistedTokensManager.js
+++ b/src/management/BlacklistedTokensManager.js
@@ -15,7 +15,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var BlacklistedTokensManager = function (options) {
+var BlacklistedTokensManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -45,11 +45,14 @@ var BlacklistedTokensManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/blacklists/tokens', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/blacklists/tokens',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Blacklist a new token.
*
@@ -79,7 +82,6 @@ var BlacklistedTokensManager = function (options) {
*/
utils.wrapPropertyMethod(BlacklistedTokensManager, 'add', 'resource.create');
-
/**
* Get all blacklisted tokens.
*
@@ -97,5 +99,4 @@ utils.wrapPropertyMethod(BlacklistedTokensManager, 'add', 'resource.create');
*/
utils.wrapPropertyMethod(BlacklistedTokensManager, 'getAll', 'resource.getAll');
-
module.exports = BlacklistedTokensManager;
diff --git a/src/management/ClientGrantsManager.js b/src/management/ClientGrantsManager.js
index 00f589fca..91deafc8e 100644
--- a/src/management/ClientGrantsManager.js
+++ b/src/management/ClientGrantsManager.js
@@ -16,7 +16,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var ClientGrantsManager = function (options) {
+var ClientGrantsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -46,11 +46,14 @@ var ClientGrantsManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/client-grants/:id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/client-grants/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create an Auth0 client grant.
*
@@ -73,7 +76,6 @@ var ClientGrantsManager = function (options) {
*/
utils.wrapPropertyMethod(ClientGrantsManager, 'create', 'resource.create');
-
/**
* Get all Auth0 Client Grants.
*
@@ -91,7 +93,6 @@ utils.wrapPropertyMethod(ClientGrantsManager, 'create', 'resource.create');
*/
utils.wrapPropertyMethod(ClientGrantsManager, 'getAll', 'resource.getAll');
-
/**
* Update an Auth0 client grant.
*
@@ -123,7 +124,6 @@ utils.wrapPropertyMethod(ClientGrantsManager, 'getAll', 'resource.getAll');
*/
utils.wrapPropertyMethod(ClientGrantsManager, 'update', 'resource.patch');
-
/**
* Delete an Auth0 client grant.
*
@@ -147,5 +147,4 @@ utils.wrapPropertyMethod(ClientGrantsManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(ClientGrantsManager, 'delete', 'resource.delete');
-
module.exports = ClientGrantsManager;
diff --git a/src/management/ClientsManager.js b/src/management/ClientsManager.js
index 837c8affc..be255f4ea 100644
--- a/src/management/ClientsManager.js
+++ b/src/management/ClientsManager.js
@@ -20,7 +20,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var ClientsManager = function (options) {
+var ClientsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -50,11 +50,14 @@ var ClientsManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/clients/:client_id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/clients/:client_id',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create an Auth0 client.
*
@@ -77,7 +80,6 @@ var ClientsManager = function (options) {
*/
utils.wrapPropertyMethod(ClientsManager, 'create', 'resource.create');
-
/**
* Get all Auth0 clients.
*
@@ -95,7 +97,6 @@ utils.wrapPropertyMethod(ClientsManager, 'create', 'resource.create');
*/
utils.wrapPropertyMethod(ClientsManager, 'getAll', 'resource.getAll');
-
/**
* Get an Auth0 client.
*
@@ -119,7 +120,6 @@ utils.wrapPropertyMethod(ClientsManager, 'getAll', 'resource.getAll');
*/
utils.wrapPropertyMethod(ClientsManager, 'get', 'resource.get');
-
/**
* Update an Auth0 client.
*
@@ -147,7 +147,6 @@ utils.wrapPropertyMethod(ClientsManager, 'get', 'resource.get');
*/
utils.wrapPropertyMethod(ClientsManager, 'update', 'resource.patch');
-
/**
* Delete an Auth0 client.
*
@@ -171,5 +170,4 @@ utils.wrapPropertyMethod(ClientsManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(ClientsManager, 'delete', 'resource.delete');
-
module.exports = ClientsManager;
diff --git a/src/management/ConnectionsManager.js b/src/management/ConnectionsManager.js
index 012d79311..69c4acc25 100644
--- a/src/management/ConnectionsManager.js
+++ b/src/management/ConnectionsManager.js
@@ -14,7 +14,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var ConnectionsManager = function (options) {
+var ConnectionsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -44,11 +44,14 @@ var ConnectionsManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/connections/:id ', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/connections/:id ',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create a new connection.
*
@@ -71,7 +74,6 @@ var ConnectionsManager = function (options) {
*/
utils.wrapPropertyMethod(ConnectionsManager, 'create', 'resource.create');
-
/**
* Get all connections.
*
@@ -89,7 +91,6 @@ utils.wrapPropertyMethod(ConnectionsManager, 'create', 'resource.create');
*/
utils.wrapPropertyMethod(ConnectionsManager, 'getAll', 'resource.getAll');
-
/**
* Get an Auth0 connection.
*
@@ -113,7 +114,6 @@ utils.wrapPropertyMethod(ConnectionsManager, 'getAll', 'resource.getAll');
*/
utils.wrapPropertyMethod(ConnectionsManager, 'get', 'resource.get');
-
/**
* Update an existing connection.
*
@@ -141,7 +141,6 @@ utils.wrapPropertyMethod(ConnectionsManager, 'get', 'resource.get');
*/
utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
-
/**
* Delete an existing connection.
*
@@ -165,5 +164,4 @@ utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(ConnectionsManager, 'delete', 'resource.delete');
-
module.exports = ConnectionsManager;
diff --git a/src/management/DeviceCredentialsManager.js b/src/management/DeviceCredentialsManager.js
index cce190438..af97301a5 100644
--- a/src/management/DeviceCredentialsManager.js
+++ b/src/management/DeviceCredentialsManager.js
@@ -9,7 +9,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class DeviceCredentialsManager
* Manages Auth0 Device Credentials.
@@ -21,7 +20,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var DeviceCredentialsManager = function (options) {
+var DeviceCredentialsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -52,11 +51,14 @@ var DeviceCredentialsManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/device-credentials/:id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/device-credentials/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create an Auth0 credential.
*
@@ -79,7 +81,6 @@ var DeviceCredentialsManager = function (options) {
*/
utils.wrapPropertyMethod(DeviceCredentialsManager, 'createPublicKey', 'resource.create');
-
/**
* Get all Auth0 credentials.
*
@@ -97,7 +98,6 @@ utils.wrapPropertyMethod(DeviceCredentialsManager, 'createPublicKey', 'resource.
*/
utils.wrapPropertyMethod(DeviceCredentialsManager, 'getAll', 'resource.getAll');
-
/**
* Delete an Auth0 device credential.
*
@@ -123,5 +123,4 @@ utils.wrapPropertyMethod(DeviceCredentialsManager, 'getAll', 'resource.getAll');
*/
utils.wrapPropertyMethod(DeviceCredentialsManager, 'delete', 'resource.delete');
-
module.exports = DeviceCredentialsManager;
diff --git a/src/management/EmailProviderManager.js b/src/management/EmailProviderManager.js
index a6a8571f2..591d9aea5 100644
--- a/src/management/EmailProviderManager.js
+++ b/src/management/EmailProviderManager.js
@@ -9,7 +9,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class EmailProviderManager
* Auth0 Email Provider.
@@ -21,7 +20,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var EmailProviderManager = function (options) {
+var EmailProviderManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -51,11 +50,14 @@ var EmailProviderManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/emails/provider', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/emails/provider',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Configure the email provider.
*
@@ -77,7 +79,6 @@ var EmailProviderManager = function (options) {
*/
utils.wrapPropertyMethod(EmailProviderManager, 'configure', 'resource.create');
-
/**
* Get the email provider.
*
@@ -95,7 +96,6 @@ utils.wrapPropertyMethod(EmailProviderManager, 'configure', 'resource.create');
*/
utils.wrapPropertyMethod(EmailProviderManager, 'get', 'resource.getAll');
-
/**
* Update the email provider.
*
@@ -120,7 +120,6 @@ utils.wrapPropertyMethod(EmailProviderManager, 'get', 'resource.getAll');
*/
utils.wrapPropertyMethod(EmailProviderManager, 'update', 'resource.patch');
-
/**
* Delete email provider.
*
@@ -142,5 +141,4 @@ utils.wrapPropertyMethod(EmailProviderManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(EmailProviderManager, 'delete', 'resource.delete');
-
module.exports = EmailProviderManager;
diff --git a/src/management/JobsManager.js b/src/management/JobsManager.js
index 46ca95e5f..8f91dcd23 100644
--- a/src/management/JobsManager.js
+++ b/src/management/JobsManager.js
@@ -13,7 +13,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class
* Abstract the creation as well as the retrieval of async jobs.
@@ -25,7 +24,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var JobsManager = function (options){
+var JobsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -52,11 +51,14 @@ var JobsManager = function (options){
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/jobs/:id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/jobs/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.jobs = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Get a job by its ID.
*
@@ -83,7 +85,7 @@ var JobsManager = function (options){
*
* @return {Promise|undefined}
*/
-JobsManager.prototype.get = function (params, cb) {
+JobsManager.prototype.get = function(params, cb) {
if (!params.id || typeof params.id !== 'string') {
throw new ArgumentError('The id parameter must be a valid job id');
}
@@ -96,7 +98,6 @@ JobsManager.prototype.get = function (params, cb) {
return this.jobs.get(params);
};
-
/**
* Given a path to a file and a connection id, create a new job that imports the
* users contained in the file and associate them with the given connection.
@@ -123,7 +124,7 @@ JobsManager.prototype.get = function (params, cb) {
*
* @return {Promise|undefined}
*/
-JobsManager.prototype.importUsers = function (data, cb) {
+JobsManager.prototype.importUsers = function(data, cb) {
var options = this.options;
var headers = extend({}, options.headers);
@@ -132,48 +133,47 @@ JobsManager.prototype.importUsers = function (data, cb) {
var url = options.baseUrl + '/jobs/users-imports';
var method = 'POST';
- var promise = new Promise(function (resolve, reject) {
- request({
- url: url,
- method: method,
- headers: headers,
- formData: {
- users: {
- value: fs.createReadStream(data.users),
- options: {
- filename: data.users
- }
- },
- connection_id: data.connection_id
+ var promise = new Promise(function(resolve, reject) {
+ request(
+ {
+ url: url,
+ method: method,
+ headers: headers,
+ formData: {
+ users: {
+ value: fs.createReadStream(data.users),
+ options: {
+ filename: data.users
+ }
+ },
+ connection_id: data.connection_id
+ }
+ },
+ function(err, res) {
+ // `superagent` uses the error parameter in callback on http errors.
+ // the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
+ var type = (res.statusCode / 100) | 0;
+ var isErrorResponse = 4 === type || 5 === type;
+ if (isErrorResponse) {
+ var error = new Error('cannot ' + method + url + ' (' + res.statusCode + ')');
+ error.status = res.statusCode;
+ error.method = method;
+ error.text = res.text;
+ reject(error);
+ }
+
+ if (err) {
+ reject(err);
+ }
+
+ resolve(res);
}
- }, function (err, res) {
-
-
- // `superagent` uses the error parameter in callback on http errors.
- // the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
- var type = res.statusCode / 100 | 0;
- var isErrorResponse = (4 === type || 5 === type);
- if (isErrorResponse) {
- var error = new Error('cannot ' + method + url + ' (' + res.statusCode + ')');
- error.status = res.statusCode;
- error.method = method;
- error.text = res.text;
- reject(error);
- }
-
- if (err) {
- reject(err);
- }
-
- resolve(res);
- });
+ );
});
// Don't return a promise if a callback was given.
if (cb && cb instanceof Function) {
- promise
- .then(cb.bind(null, null))
- .catch(cb);
+ promise.then(cb.bind(null, null)).catch(cb);
return;
}
@@ -181,7 +181,6 @@ JobsManager.prototype.importUsers = function (data, cb) {
return promise;
};
-
/**
* Send a verification email to a user.
*
@@ -205,7 +204,7 @@ JobsManager.prototype.importUsers = function (data, cb) {
*
* @return {Promise|undefined}
*/
-JobsManager.prototype.verifyEmail = function (data, cb) {
+JobsManager.prototype.verifyEmail = function(data, cb) {
if (!data.user_id || typeof data.user_id !== 'string') {
throw new ArgumentError('Must specify a user ID');
}
@@ -218,5 +217,4 @@ JobsManager.prototype.verifyEmail = function (data, cb) {
return this.jobs.create({ id: 'verification-email' }, data);
};
-
module.exports = JobsManager;
diff --git a/src/management/LogsManager.js b/src/management/LogsManager.js
index f635ac286..9f00081a7 100644
--- a/src/management/LogsManager.js
+++ b/src/management/LogsManager.js
@@ -14,7 +14,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var LogsManager = function (options) {
+var LogsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}
@@ -44,7 +44,11 @@ var LogsManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/logs/:id ', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/logs/:id ',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
@@ -65,7 +69,6 @@ var LogsManager = function (options) {
*/
utils.wrapPropertyMethod(LogsManager, 'getAll', 'resource.getAll');
-
/**
* Get an Auth0 log.
*
diff --git a/src/management/ManagementTokenProvider.js b/src/management/ManagementTokenProvider.js
index 9a33c20e5..59996fb2b 100644
--- a/src/management/ManagementTokenProvider.js
+++ b/src/management/ManagementTokenProvider.js
@@ -21,7 +21,7 @@ var DEFAULT_OPTIONS = { enableCache: true };
* @param {Boolean} [options.enableCache=true] Enabled or Disable Cache
* @param {Number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
*/
-var ManagementTokenProvider = function (options) {
+var ManagementTokenProvider = function(options) {
if (!options || typeof options !== 'object') {
throw new ArgumentError('Options must be an object');
}
@@ -44,7 +44,7 @@ var ManagementTokenProvider = function (options) {
throw new ArgumentError('Must provide a audience');
}
- if (typeof params.enableCache !== 'boolean'){
+ if (typeof params.enableCache !== 'boolean') {
throw new ArgumentError('enableCache must be a boolean');
}
@@ -58,7 +58,7 @@ var ManagementTokenProvider = function (options) {
}
}
- if (params.scope && typeof params.scope !== 'string'){
+ if (params.scope && typeof params.scope !== 'string') {
throw new ArgumentError('scope must be a string');
}
@@ -70,7 +70,7 @@ var ManagementTokenProvider = function (options) {
telemetry: this.options.telemetry
};
this.authenticationClient = new AuthenticationClient(authenticationClientOptions);
-}
+};
/**
* Returns the access_token.
@@ -80,43 +80,45 @@ var ManagementTokenProvider = function (options) {
*
* @return {Promise} Promise returning an access_token.
*/
-ManagementTokenProvider.prototype.getAccessToken = function () {
- if(this.options.enableCache){
- return this.getCachedAccessToken(this.options)
- .then(function (data) {
- return data.access_token
- });
- }else{
- return this.clientCredentialsGrant(this.options.domain, this.options.scope, this.options.audience)
- .then(function (data) {
- return data.access_token
- });
+ManagementTokenProvider.prototype.getAccessToken = function() {
+ if (this.options.enableCache) {
+ return this.getCachedAccessToken(this.options).then(function(data) {
+ return data.access_token;
+ });
+ } else {
+ return this.clientCredentialsGrant(
+ this.options.domain,
+ this.options.scope,
+ this.options.audience
+ ).then(function(data) {
+ return data.access_token;
+ });
}
-}
+};
ManagementTokenProvider.prototype.getCachedAccessToken = Promise.promisify(
memoizer({
- load: function (options, callback) {
+ load: function(options, callback) {
this.clientCredentialsGrant(options.domain, options.scope, options.audience)
- .then(function (data) {
+ .then(function(data) {
callback(null, data);
})
- .catch(function (err) {
+ .catch(function(err) {
callback(err);
});
},
- hash: function (options) {
+ hash: function(options) {
return options.domain + '-' + options.clientId + '-' + options.scope;
},
- itemMaxAge: function (options, data) {
- if(options.cacheTTLInSeconds){
+ itemMaxAge: function(options, data) {
+ if (options.cacheTTLInSeconds) {
return options.cacheTTLInSeconds * 1000;
}
// if the expires_in is lower than 10 seconds, do not subtract 10 additional seconds.
- if (data.expires_in && data.expires_in < 10 /* seconds */){
+ if (data.expires_in && data.expires_in < 10 /* seconds */) {
return data.expires_in * 1000;
- }else if(data.expires_in){
+ } else if (data.expires_in) {
// Subtract 10 seconds from expires_in to fetch a new one, before it expires.
return data.expires_in * 1000 - 10000 /* milliseconds */;
}
@@ -126,7 +128,7 @@ ManagementTokenProvider.prototype.getCachedAccessToken = Promise.promisify(
})
);
-ManagementTokenProvider.prototype.clientCredentialsGrant = function (domain, scope, audience) {
+ManagementTokenProvider.prototype.clientCredentialsGrant = function(domain, scope, audience) {
return this.authenticationClient.clientCredentialsGrant({
audience: audience,
scope: scope
diff --git a/src/management/ResourceServersManager.js b/src/management/ResourceServersManager.js
index 6e93a03aa..67a68aa2f 100644
--- a/src/management/ResourceServersManager.js
+++ b/src/management/ResourceServersManager.js
@@ -21,7 +21,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.retry] Retry Policy Config
*/
-var ResourceServersManager = function (options) {
+var ResourceServersManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide resource server options');
}
@@ -50,7 +50,11 @@ var ResourceServersManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/resource-servers/:id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/resource-servers/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
@@ -93,7 +97,6 @@ utils.wrapPropertyMethod(ResourceServersManager, 'create', 'resource.create');
*/
utils.wrapPropertyMethod(ResourceServersManager, 'getAll', 'resource.getAll');
-
/**
* Get a Resource Server.
*
@@ -167,4 +170,4 @@ utils.wrapPropertyMethod(ResourceServersManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(ResourceServersManager, 'delete', 'resource.delete');
-module.exports = ResourceServersManager;
\ No newline at end of file
+module.exports = ResourceServersManager;
diff --git a/src/management/RulesManager.js b/src/management/RulesManager.js
index 30f0d61e0..0d824481e 100644
--- a/src/management/RulesManager.js
+++ b/src/management/RulesManager.js
@@ -9,7 +9,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class RulesManager
* The rule class provides a simple abstraction for performing CRUD operations
@@ -22,7 +21,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var RulesManager = function (options) {
+var RulesManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -51,11 +50,14 @@ var RulesManager = function (options) {
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/rules/:id', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/rules/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create a new rule.
*
@@ -78,7 +80,6 @@ var RulesManager = function (options) {
*/
utils.wrapPropertyMethod(RulesManager, 'create', 'resource.create');
-
/**
* Get all rules.
*
@@ -96,7 +97,6 @@ utils.wrapPropertyMethod(RulesManager, 'create', 'resource.create');
*/
utils.wrapPropertyMethod(RulesManager, 'getAll', 'resource.getAll');
-
/**
* Get an Auth0 rule.
*
@@ -120,7 +120,6 @@ utils.wrapPropertyMethod(RulesManager, 'getAll', 'resource.getAll');
*/
utils.wrapPropertyMethod(RulesManager, 'get', 'resource.get');
-
/**
* Update an existing rule.
*
@@ -158,7 +157,6 @@ utils.wrapPropertyMethod(RulesManager, 'get', 'resource.get');
*/
utils.wrapPropertyMethod(RulesManager, 'update', 'resource.patch');
-
/**
* Delete an existing rule.
*
@@ -182,5 +180,4 @@ utils.wrapPropertyMethod(RulesManager, 'update', 'resource.patch');
*/
utils.wrapPropertyMethod(RulesManager, 'delete', 'resource.delete');
-
module.exports = RulesManager;
diff --git a/src/management/StatsManager.js b/src/management/StatsManager.js
index 3d9f81a6c..9dafe9f94 100644
--- a/src/management/StatsManager.js
+++ b/src/management/StatsManager.js
@@ -8,7 +8,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class
* Abstracts interaction with the stats endpoint.
@@ -20,7 +19,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var StatsManager = function (options){
+var StatsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -45,11 +44,14 @@ var StatsManager = function (options){
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/stats/:type', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/stats/:type',
+ clientOptions,
+ options.tokenProvider
+ );
this.stats = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Get the daily stats.
*
@@ -77,7 +79,7 @@ var StatsManager = function (options){
*
* @return {Promise|undefined}
*/
-StatsManager.prototype.getDaily = function (params, cb) {
+StatsManager.prototype.getDaily = function(params, cb) {
params = params || {};
params.type = 'daily';
@@ -88,7 +90,6 @@ StatsManager.prototype.getDaily = function (params, cb) {
return this.stats.get(params);
};
-
/**
* Get a the active users count.
*
@@ -108,7 +109,7 @@ StatsManager.prototype.getDaily = function (params, cb) {
*
* @return {Promise|undefined}
*/
-StatsManager.prototype.getActiveUsersCount = function (cb) {
+StatsManager.prototype.getActiveUsersCount = function(cb) {
var options = { type: 'active-users' };
if (cb && cb instanceof Function) {
@@ -119,5 +120,4 @@ StatsManager.prototype.getActiveUsersCount = function (cb) {
return this.stats.get(options);
};
-
module.exports = StatsManager;
diff --git a/src/management/TenantManager.js b/src/management/TenantManager.js
index e9afc56db..a4ee9dbae 100644
--- a/src/management/TenantManager.js
+++ b/src/management/TenantManager.js
@@ -8,7 +8,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class
* Abstracts interaction with the tenant endpoint.
@@ -20,7 +19,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var TenantManager = function (options){
+var TenantManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -45,7 +44,11 @@ var TenantManager = function (options){
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/tenants/settings', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/tenants/settings',
+ clientOptions,
+ options.tokenProvider
+ );
this.tenant = new RetryRestClient(auth0RestClient, options.retry);
};
@@ -67,7 +70,7 @@ var TenantManager = function (options){
*
* @return {Promise|undefined}
*/
-TenantManager.prototype.updateSettings = function (data, cb) {
+TenantManager.prototype.updateSettings = function(data, cb) {
if (cb && cb instanceof Function) {
return this.tenant.patch({}, data, cb);
}
@@ -95,7 +98,7 @@ TenantManager.prototype.updateSettings = function (data, cb) {
*
* @return {Promise|undefined}
*/
-TenantManager.prototype.getSettings = function (cb) {
+TenantManager.prototype.getSettings = function(cb) {
if (cb && cb instanceof Function) {
return this.tenant.get({}, cb);
}
@@ -104,5 +107,4 @@ TenantManager.prototype.getSettings = function (cb) {
return this.tenant.get({});
};
-
module.exports = TenantManager;
diff --git a/src/management/TicketsManager.js b/src/management/TicketsManager.js
index d77a76cb6..d6e06c919 100644
--- a/src/management/TicketsManager.js
+++ b/src/management/TicketsManager.js
@@ -7,13 +7,13 @@ var RetryRestClient = require('../RetryRestClient');
* Abstracts interaction with the tickets endpoint.
* @constructor
* @memberOf module:management
- *
+ *
* @param {Object} options The client options.
* @param {String} options.baseUrl The URL of the API.
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var TicketsManager = function (options){
+var TicketsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -38,11 +38,14 @@ var TicketsManager = function (options){
*
* @type {external:RestClient}
*/
- var auth0RestClient = new Auth0RestClient(options.baseUrl + '/tickets/:type', clientOptions, options.tokenProvider);
+ var auth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/tickets/:type',
+ clientOptions,
+ options.tokenProvider
+ );
this.ticket = new RetryRestClient(auth0RestClient, options.retry);
};
-
/**
* Create a new password change ticket.
*
@@ -66,7 +69,7 @@ var TicketsManager = function (options){
* @param {Function} [cb] Callback function.
* @return {Promise}
*/
-TicketsManager.prototype.changePassword = function (data, cb) {
+TicketsManager.prototype.changePassword = function(data, cb) {
var params = { type: 'password-change' };
if (cb && cb instanceof Function) {
@@ -77,7 +80,6 @@ TicketsManager.prototype.changePassword = function (data, cb) {
return this.ticket.create(params, data);
};
-
/**
* Create an email verification ticket.
*
@@ -99,7 +101,7 @@ TicketsManager.prototype.changePassword = function (data, cb) {
* @param {Function} [cb] Callback function.
* @return {Promise}
*/
-TicketsManager.prototype.verifyEmail = function (data, cb) {
+TicketsManager.prototype.verifyEmail = function(data, cb) {
var params = { type: 'email-verification' };
if (cb && cb instanceof Function) {
@@ -110,6 +112,4 @@ TicketsManager.prototype.verifyEmail = function (data, cb) {
return this.ticket.create(params, data);
};
-
module.exports = TicketsManager;
-
diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js
index 48bdb6895..54f4cc235 100644
--- a/src/management/UsersManager.js
+++ b/src/management/UsersManager.js
@@ -8,7 +8,6 @@ var RetryRestClient = require('../RetryRestClient');
* @see https://github.com/ngonzalvez/rest-facade
*/
-
/**
* @class
* Abstracts interaction with the users endpoint.
@@ -20,7 +19,7 @@ var RetryRestClient = require('../RetryRestClient');
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
-var UsersManager = function (options){
+var UsersManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide manager options');
}
@@ -39,7 +38,11 @@ var UsersManager = function (options){
query: { repeatParams: false }
};
- var usersAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id', clientOptions, options.tokenProvider);
+ var usersAuth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/users/:id',
+ clientOptions,
+ options.tokenProvider
+ );
this.users = new RetryRestClient(usersAuth0RestClient, options.retry);
/**
@@ -49,7 +52,11 @@ var UsersManager = function (options){
*
* @type {external:RestClient}
*/
- var multifactorAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id/multifactor/:provider', clientOptions, options.tokenProvider);
+ var multifactorAuth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/users/:id/multifactor/:provider',
+ clientOptions,
+ options.tokenProvider
+ );
this.multifactor = new RetryRestClient(multifactorAuth0RestClient, options.retry);
/**
@@ -57,7 +64,11 @@ var UsersManager = function (options){
*
* @type {external:RestClient}
*/
- var identitiesAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id/identities/:provider/:user_id', clientOptions, options.tokenProvider);
+ var identitiesAuth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/users/:id/identities/:provider/:user_id',
+ clientOptions,
+ options.tokenProvider
+ );
this.identities = new RetryRestClient(identitiesAuth0RestClient, options.retry);
/**
@@ -65,7 +76,11 @@ var UsersManager = function (options){
*
* @type {external:RestClient}
*/
- var userLogsAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id/logs', clientOptions, options.tokenProvider);
+ var userLogsAuth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/users/:id/logs',
+ clientOptions,
+ options.tokenProvider
+ );
this.userLogs = new RetryRestClient(userLogsAuth0RestClient, options.retry);
/**
@@ -73,7 +88,11 @@ var UsersManager = function (options){
*
* @type {external:RestClient}
*/
- var enrollmentsAuth0RestClient = new Auth0RestClient(options.baseUrl + '/users/:id/enrollments', clientOptions, options.tokenProvider);
+ var enrollmentsAuth0RestClient = new Auth0RestClient(
+ options.baseUrl + '/users/:id/enrollments',
+ clientOptions,
+ options.tokenProvider
+ );
this.enrollments = new RetryRestClient(enrollmentsAuth0RestClient, options.retry);
/**
@@ -81,11 +100,14 @@ var UsersManager = function (options){
*
* @type {external:RestClient}
*/
- var usersByEmailClient = new Auth0RestClient(options.baseUrl + '/users-by-email', clientOptions, options.tokenProvider);
+ var usersByEmailClient = new Auth0RestClient(
+ options.baseUrl + '/users-by-email',
+ clientOptions,
+ options.tokenProvider
+ );
this.usersByEmail = new RetryRestClient(usersByEmailClient, options.retry);
};
-
/**
* Create a new user.
*
@@ -106,7 +128,7 @@ var UsersManager = function (options){
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.create = function (data, cb) {
+UsersManager.prototype.create = function(data, cb) {
if (cb && cb instanceof Function) {
return this.users.create(data, cb);
}
@@ -114,7 +136,6 @@ UsersManager.prototype.create = function (data, cb) {
return this.users.create(data);
};
-
/**
* Get all users.
*
@@ -143,7 +164,7 @@ UsersManager.prototype.create = function (data, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.getAll = function (params) {
+UsersManager.prototype.getAll = function(params) {
return this.users.getAll.apply(this.users, arguments);
};
@@ -167,11 +188,10 @@ UsersManager.prototype.getAll = function (params) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.getByEmail = function (email, callback) {
+UsersManager.prototype.getByEmail = function(email, callback) {
return this.usersByEmail.getAll({ email }, callback);
};
-
/**
* Get a user by its id.
*
@@ -189,11 +209,10 @@ UsersManager.prototype.getByEmail = function (email, callback) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.get = function () {
+UsersManager.prototype.get = function() {
return this.users.get.apply(this.users, arguments);
};
-
/**
* Update a user by its id.
*
@@ -219,11 +238,10 @@ UsersManager.prototype.get = function () {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.update = function () {
+UsersManager.prototype.update = function() {
return this.users.patch.apply(this.users, arguments);
};
-
/**
* Update the user metadata.
*
@@ -252,7 +270,7 @@ UsersManager.prototype.update = function () {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.updateUserMetadata = function (params, metadata, cb) {
+UsersManager.prototype.updateUserMetadata = function(params, metadata, cb) {
var data = {
user_metadata: metadata
};
@@ -264,7 +282,6 @@ UsersManager.prototype.updateUserMetadata = function (params, metadata, cb) {
return this.users.patch(params, data);
};
-
/**
* Update the app metadata.
*
@@ -293,7 +310,7 @@ UsersManager.prototype.updateUserMetadata = function (params, metadata, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.updateAppMetadata = function (params, metadata, cb) {
+UsersManager.prototype.updateAppMetadata = function(params, metadata, cb) {
var data = {
app_metadata: metadata
};
@@ -305,7 +322,6 @@ UsersManager.prototype.updateAppMetadata = function (params, metadata, cb) {
return this.users.patch(params, data);
};
-
/**
* Delete a user by its id.
*
@@ -328,7 +344,7 @@ UsersManager.prototype.updateAppMetadata = function (params, metadata, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.delete = function (params) {
+UsersManager.prototype.delete = function(params) {
if (typeof params !== 'object' || typeof params.id !== 'string') {
throw new ArgumentError('You must provide an id for the delete method');
}
@@ -336,7 +352,6 @@ UsersManager.prototype.delete = function (params) {
return this.users.delete.apply(this.users, arguments);
};
-
/**
* Delete all users.
*
@@ -356,7 +371,7 @@ UsersManager.prototype.delete = function (params) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.deleteAll = function (cb) {
+UsersManager.prototype.deleteAll = function(cb) {
if (typeof cb !== 'function') {
var errorMsg = 'The deleteAll method only accepts a callback as argument';
@@ -366,7 +381,6 @@ UsersManager.prototype.deleteAll = function (cb) {
return this.users.delete.apply(this.users, arguments);
};
-
/**
* Delete a multifactor provider.
*
@@ -391,7 +405,7 @@ UsersManager.prototype.deleteAll = function (cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.deleteMultifactorProvider = function (params, cb) {
+UsersManager.prototype.deleteMultifactorProvider = function(params, cb) {
params = params || {};
if (!params.id || typeof params.id !== 'string') {
@@ -409,7 +423,6 @@ UsersManager.prototype.deleteMultifactorProvider = function (params, cb) {
return this.multifactor.delete(params);
};
-
/**
* Link the user with another account.
*
@@ -439,7 +452,7 @@ UsersManager.prototype.deleteMultifactorProvider = function (params, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.link = function (userId, params, cb) {
+UsersManager.prototype.link = function(userId, params, cb) {
var query = { id: userId };
params = params || {};
@@ -458,7 +471,6 @@ UsersManager.prototype.link = function (userId, params, cb) {
return this.identities.create(query, params);
};
-
/**
* Unlink the given accounts.
*
@@ -484,7 +496,7 @@ UsersManager.prototype.link = function (userId, params, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.unlink = function (params, cb) {
+UsersManager.prototype.unlink = function(params, cb) {
params = params || {};
if (!params.id || typeof params.id !== 'string') {
@@ -533,7 +545,7 @@ UsersManager.prototype.unlink = function (params, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.logs = function (params, cb) {
+UsersManager.prototype.logs = function(params, cb) {
params = params || {};
if (!params.id || typeof params.id !== 'string') {
@@ -560,7 +572,7 @@ UsersManager.prototype.logs = function (params, cb) {
*
* @return {Promise|undefined}
*/
-UsersManager.prototype.getGuardianEnrollments = function () {
+UsersManager.prototype.getGuardianEnrollments = function() {
return this.enrollments.get.apply(this.enrollments, arguments);
};
diff --git a/src/management/index.js b/src/management/index.js
index a761d9b52..f1f4bbf9a 100644
--- a/src/management/index.js
+++ b/src/management/index.js
@@ -51,7 +51,7 @@ var MANAGEMENT_API_AUD_FORMAT = 'https://%s/api/v2/';
* });
*
*
- * @example
+ * @example
* Initialize your client class, by using a Non Interactive Client to fetch an access_token
* via the Client Credentials Grant.
*
@@ -84,13 +84,13 @@ var MANAGEMENT_API_AUD_FORMAT = 'https://%s/api/v2/';
* @param {Number} [options.retry.maxRetries=10] Retry failed requests X times.
*
*/
-var ManagementClient = function (options) {
+var ManagementClient = function(options) {
if (!options || typeof options !== 'object') {
throw new ArgumentError('Management API SDK options must be an object');
}
if (!options.domain || options.domain.length === 0) {
- throw new ArgumentError('Must provide a domain');
+ throw new ArgumentError('Must provide a domain');
}
var baseUrl = util.format(BASE_URL_FORMAT, options.domain);
@@ -103,7 +103,10 @@ var ManagementClient = function (options) {
};
if (options.token === undefined) {
- var config = assign({ audience: util.format(MANAGEMENT_API_AUD_FORMAT, options.domain) }, options);
+ var config = assign(
+ { audience: util.format(MANAGEMENT_API_AUD_FORMAT, options.domain) },
+ options
+ );
if (options.tokenProvider) {
config.enableCache = options.tokenProvider.enableCache;
@@ -232,10 +235,8 @@ var ManagementClient = function (options) {
* @type {ResourceServersManager}
*/
this.resourceServers = new ResourceServersManager(managerOptions);
-
};
-
/**
* Return an object with information about the current client,
*
@@ -244,30 +245,29 @@ var ManagementClient = function (options) {
*
* @return {Object} Object containing client information.
*/
-ManagementClient.prototype.getClientInfo = function () {
+ManagementClient.prototype.getClientInfo = function() {
var clientInfo = {
name: 'node-auth0',
version: pkg.version,
dependencies: [],
- environment: [{
- name: 'node.js',
- version: process.version.replace('v', '')
- }]
+ environment: [
+ {
+ name: 'node.js',
+ version: process.version.replace('v', '')
+ }
+ ]
};
// Add the dependencies to the client info object.
- Object
- .keys(pkg.dependencies)
- .forEach(function (name) {
- clientInfo.dependencies.push({
- name: name,
- version: pkg.dependencies[name]
- });
+ Object.keys(pkg.dependencies).forEach(function(name) {
+ clientInfo.dependencies.push({
+ name: name,
+ version: pkg.dependencies[name]
});
+ });
return clientInfo;
};
-
/**
* Get all connections.
*
@@ -286,7 +286,6 @@ ManagementClient.prototype.getClientInfo = function () {
*/
utils.wrapPropertyMethod(ManagementClient, 'getConnections', 'connections.getAll');
-
/**
* Create a new connection.
*
@@ -309,7 +308,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getConnections', 'connections.getAll
*/
utils.wrapPropertyMethod(ManagementClient, 'createConnection', 'connections.create');
-
/**
* Get an Auth0 connection.
*
@@ -333,7 +331,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createConnection', 'connections.crea
*/
utils.wrapPropertyMethod(ManagementClient, 'getConnection', 'connections.get');
-
/**
* Delete an existing connection.
*
@@ -357,7 +354,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getConnection', 'connections.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteConnection', 'connections.delete');
-
/**
* Update an existing connection.
*
@@ -385,7 +381,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteConnection', 'connections.dele
*/
utils.wrapPropertyMethod(ManagementClient, 'updateConnection', 'connections.update');
-
/**
* Get all Auth0 clients.
*
@@ -403,7 +398,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateConnection', 'connections.upda
*/
utils.wrapPropertyMethod(ManagementClient, 'getClients', 'clients.getAll');
-
/**
* Get an Auth0 client.
*
@@ -427,7 +421,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getClients', 'clients.getAll');
*/
utils.wrapPropertyMethod(ManagementClient, 'getClient', 'clients.get');
-
/**
* Create an Auth0 client.
*
@@ -450,7 +443,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getClient', 'clients.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'createClient', 'clients.create');
-
/**
* Update an Auth0 client.
*
@@ -478,7 +470,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createClient', 'clients.create');
*/
utils.wrapPropertyMethod(ManagementClient, 'updateClient', 'clients.update');
-
/**
* Delete an Auth0 client.
*
@@ -502,7 +493,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateClient', 'clients.update');
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteClient', 'clients.delete');
-
/**
* Get all Auth0 Client Grants.
*
@@ -520,7 +510,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteClient', 'clients.delete');
*/
utils.wrapPropertyMethod(ManagementClient, 'getClientGrants', 'clientGrants.getAll');
-
/**
* Create an Auth0 client grant.
*
@@ -543,7 +532,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getClientGrants', 'clientGrants.getA
*/
utils.wrapPropertyMethod(ManagementClient, 'createClientGrant', 'clientGrants.create');
-
/**
* Update an Auth0 client grant.
*
@@ -575,7 +563,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createClientGrant', 'clientGrants.cr
*/
utils.wrapPropertyMethod(ManagementClient, 'updateClientGrant', 'clientGrants.update');
-
/**
* Delete an Auth0 client grant.
*
@@ -599,7 +586,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateClientGrant', 'clientGrants.up
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteClientGrant', 'clientGrants.delete');
-
/**
* Create an Auth0 credential.
*
@@ -620,8 +606,11 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteClientGrant', 'clientGrants.de
*
* @return {Promise|undefined}
*/
-utils.wrapPropertyMethod(ManagementClient, 'createDevicePublicKey', 'deviceCredentials.createPublicKey');
-
+utils.wrapPropertyMethod(
+ ManagementClient,
+ 'createDevicePublicKey',
+ 'deviceCredentials.createPublicKey'
+);
/**
* Get all Auth0 credentials.
@@ -640,7 +629,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createDevicePublicKey', 'deviceCrede
*/
utils.wrapPropertyMethod(ManagementClient, 'getDeviceCredentials', 'deviceCredentials.getAll');
-
/**
* Delete an Auth0 device credential.
*
@@ -666,7 +654,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getDeviceCredentials', 'deviceCreden
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteDeviceCredential', 'deviceCredentials.delete');
-
/**
* Get all rules.
*
@@ -684,7 +671,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteDeviceCredential', 'deviceCred
*/
utils.wrapPropertyMethod(ManagementClient, 'getRules', 'rules.getAll');
-
/**
* Create a new rule.
*
@@ -707,7 +693,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getRules', 'rules.getAll');
*/
utils.wrapPropertyMethod(ManagementClient, 'createRule', 'rules.create');
-
/**
* Get an Auth0 rule.
*
@@ -731,7 +716,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createRule', 'rules.create');
*/
utils.wrapPropertyMethod(ManagementClient, 'getRule', 'rules.get');
-
/**
* Delete an existing rule.
*
@@ -755,7 +739,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getRule', 'rules.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteRule', 'rules.delete');
-
/**
* Update an existing rule.
*
@@ -782,7 +765,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteRule', 'rules.delete');
*/
utils.wrapPropertyMethod(ManagementClient, 'updateRule', 'rules.update');
-
/**
* Get all users.
*
@@ -835,8 +817,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getUsers', 'users.getAll');
*/
utils.wrapPropertyMethod(ManagementClient, 'getUsersByEmail', 'users.getByEmail');
-
-
/**
* Get a user by its id.
*
@@ -856,7 +836,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getUsersByEmail', 'users.getByEmail'
*/
utils.wrapPropertyMethod(ManagementClient, 'getUser', 'users.get');
-
/**
* Delete all users.
*
@@ -878,7 +857,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getUser', 'users.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteAllUsers', 'users.deleteAll');
-
/**
* Delete a user by its id.
*
@@ -902,7 +880,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteAllUsers', 'users.deleteAll');
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteUser', 'users.delete');
-
/**
* Create a new user.
*
@@ -925,7 +902,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteUser', 'users.delete');
*/
utils.wrapPropertyMethod(ManagementClient, 'createUser', 'users.create');
-
/**
* Update a user by its id.
*
@@ -953,7 +929,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createUser', 'users.create');
*/
utils.wrapPropertyMethod(ManagementClient, 'updateUser', 'users.update');
-
/**
* Update the user metadata for a user.
*
@@ -984,7 +959,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateUser', 'users.update');
*/
utils.wrapPropertyMethod(ManagementClient, 'updateUserMetadata', 'users.updateUserMetadata');
-
/**
* Update the app metadata for a user.
*
@@ -1015,7 +989,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateUserMetadata', 'users.updateUs
*/
utils.wrapPropertyMethod(ManagementClient, 'updateAppMetadata', 'users.updateAppMetadata');
-
/**
* Delete a multifactor provider for a user.
*
@@ -1040,8 +1013,11 @@ utils.wrapPropertyMethod(ManagementClient, 'updateAppMetadata', 'users.updateApp
*
* @return {Promise|undefined}
*/
-utils.wrapPropertyMethod(ManagementClient, 'deleteUserMultifcator', 'users.deleteMultifactorProvider');
-
+utils.wrapPropertyMethod(
+ ManagementClient,
+ 'deleteUserMultifcator',
+ 'users.deleteMultifactorProvider'
+);
/**
* Unlink the given accounts.
@@ -1070,7 +1046,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteUserMultifcator', 'users.delet
*/
utils.wrapPropertyMethod(ManagementClient, 'unlinkUsers', 'users.unlink');
-
/**
* Link the user with another account.
*
@@ -1148,8 +1123,11 @@ utils.wrapPropertyMethod(ManagementClient, 'getUserLogs', 'users.logs');
*
* @return {Promise|undefined}
*/
-utils.wrapPropertyMethod(ManagementClient, 'getGuardianEnrollments', 'users.getGuardianEnrollments');
-
+utils.wrapPropertyMethod(
+ ManagementClient,
+ 'getGuardianEnrollments',
+ 'users.getGuardianEnrollments'
+);
/**
* Get all blacklisted tokens.
@@ -1168,7 +1146,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getGuardianEnrollments', 'users.getG
*/
utils.wrapPropertyMethod(ManagementClient, 'getBlacklistedTokens', 'blacklistedTokens.getAll');
-
/**
* Blacklist a new token.
*
@@ -1198,7 +1175,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getBlacklistedTokens', 'blacklistedT
*/
utils.wrapPropertyMethod(ManagementClient, 'blacklistToken', 'blacklistedTokens.add');
-
/**
* Get the email provider.
*
@@ -1216,7 +1192,6 @@ utils.wrapPropertyMethod(ManagementClient, 'blacklistToken', 'blacklistedTokens.
*/
utils.wrapPropertyMethod(ManagementClient, 'getEmailProvider', 'emailProvider.get');
-
/**
* Configure the email provider.
*
@@ -1239,7 +1214,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getEmailProvider', 'emailProvider.ge
*/
utils.wrapPropertyMethod(ManagementClient, 'configureEmailProvider', 'emailProvider.configure');
-
/**
* Delete email provider.
*
@@ -1261,7 +1235,6 @@ utils.wrapPropertyMethod(ManagementClient, 'configureEmailProvider', 'emailProvi
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteEmailProvider', 'emailProvider.delete');
-
/**
* Update the email provider.
*
@@ -1286,7 +1259,6 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteEmailProvider', 'emailProvider
*/
utils.wrapPropertyMethod(ManagementClient, 'updateEmailProvider', 'emailProvider.update');
-
/**
* Get a the active users count.
*
@@ -1308,7 +1280,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateEmailProvider', 'emailProvider
*/
utils.wrapPropertyMethod(ManagementClient, 'getActiveUsersCount', 'stats.getActiveUsersCount');
-
/**
* Get the daily stats.
*
@@ -1338,7 +1309,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getActiveUsersCount', 'stats.getActi
*/
utils.wrapPropertyMethod(ManagementClient, 'getDailyStats', 'stats.getDaily');
-
/**
* Get the tenant settings..
*
@@ -1360,7 +1330,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getDailyStats', 'stats.getDaily');
*/
utils.wrapPropertyMethod(ManagementClient, 'getTenantSettings', 'tenant.getSettings');
-
/**
* Update the tenant settings.
*
@@ -1381,7 +1350,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getTenantSettings', 'tenant.getSetti
*/
utils.wrapPropertyMethod(ManagementClient, 'updateTenantSettings', 'tenant.updateSettings');
-
/**
* Get a job by its ID.
*
@@ -1410,7 +1378,6 @@ utils.wrapPropertyMethod(ManagementClient, 'updateTenantSettings', 'tenant.updat
*/
utils.wrapPropertyMethod(ManagementClient, 'getJob', 'jobs.get');
-
/**
* Given a path to a file and a connection id, create a new job that imports the
* users contained in the file and associate them with the given connection.
@@ -1439,7 +1406,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getJob', 'jobs.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'importUsers', 'jobs.importUsers');
-
/**
* Send a verification email to a user.
*
@@ -1465,7 +1431,6 @@ utils.wrapPropertyMethod(ManagementClient, 'importUsers', 'jobs.importUsers');
*/
utils.wrapPropertyMethod(ManagementClient, 'sendEmailVerification', 'jobs.verifyEmail');
-
/**
* Create a new password change ticket.
*
@@ -1491,7 +1456,6 @@ utils.wrapPropertyMethod(ManagementClient, 'sendEmailVerification', 'jobs.verify
*/
utils.wrapPropertyMethod(ManagementClient, 'createPasswordChangeTicket', 'tickets.changePassword');
-
/**
* Create an email verification ticket.
*
@@ -1556,7 +1520,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getLog', 'logs.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'getLogs', 'logs.getAll');
-
/**
* Create a new resource server.
*
@@ -1597,7 +1560,6 @@ utils.wrapPropertyMethod(ManagementClient, 'createResourceServer', 'resourceServ
*/
utils.wrapPropertyMethod(ManagementClient, 'getResourceServers', 'resourceServers.getAll');
-
/**
* Get a Resource Server.
*
@@ -1621,7 +1583,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getResourceServers', 'resourceServer
*/
utils.wrapPropertyMethod(ManagementClient, 'getResourceServer', 'resourceServers.get');
-
/**
* Delete an existing resource server.
*
@@ -1645,7 +1606,6 @@ utils.wrapPropertyMethod(ManagementClient, 'getResourceServer', 'resourceServers
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteResourceServer', 'resourceServers.delete');
-
/**
* Update an existing resource server.
*
diff --git a/src/utils.js b/src/utils.js
index dbc9b273a..8ba259f61 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,12 +1,10 @@
var Promise = require('bluebird');
var request = require('request');
-
/**
* @module utils
*/
-var utils = module.exports = {};
-
+var utils = (module.exports = {});
/**
* Given a JSON string, convert it to its base64 representation.
@@ -14,7 +12,7 @@ var utils = module.exports = {};
* @method jsonToBase64
* @memberOf module:utils
*/
-utils.jsonToBase64 = function (json) {
+utils.jsonToBase64 = function(json) {
var bytes = new Buffer(JSON.stringify(json));
return bytes
@@ -24,7 +22,6 @@ utils.jsonToBase64 = function (json) {
.replace(/=+$/, '');
};
-
/**
* Simple wrapper that, given a class, a property name and a method name,
* creates a new method in the class that is a wrapper for the given
@@ -33,20 +30,19 @@ utils.jsonToBase64 = function (json) {
* @method wrapPropertyMethod
* @memberOf module:utils
*/
-utils.wrapPropertyMethod = function (Parent, name, propertyMethod) {
+utils.wrapPropertyMethod = function(Parent, name, propertyMethod) {
var path = propertyMethod.split('.');
var property = path.shift();
var method = path.pop();
Object.defineProperty(Parent.prototype, name, {
enumerable: false,
- get: function () {
+ get: function() {
return this[property][method].bind(this[property]);
}
});
};
-
/**
* Perform a request with the given settings and return a promise that resolves
* when the request is successfull and rejects when there's an error.
@@ -54,22 +50,24 @@ utils.wrapPropertyMethod = function (Parent, name, propertyMethod) {
* @method getRequestPromise
* @memberOf module:utils
*/
-utils.getRequestPromise = function (settings) {
- return new Promise(function (resolve, reject) {
- request({
- url: settings.url,
- method: settings.method,
- body: settings.data,
- json: typeof settings.data === 'object',
- headers: settings.headers
- }, function (err, res, body) {
- if (err) {
- reject(err);
- return;
- }
+utils.getRequestPromise = function(settings) {
+ return new Promise(function(resolve, reject) {
+ request(
+ {
+ url: settings.url,
+ method: settings.method,
+ body: settings.data,
+ json: typeof settings.data === 'object',
+ headers: settings.headers
+ },
+ function(err, res, body) {
+ if (err) {
+ reject(err);
+ return;
+ }
- resolve(res.body);
- });
-
+ resolve(res.body);
+ }
+ );
});
-}
+};
diff --git a/test/auth/authentication-client.tests.js b/test/auth/authentication-client.tests.js
index 878e2c22c..edb873936 100644
--- a/test/auth/authentication-client.tests.js
+++ b/test/auth/authentication-client.tests.js
@@ -11,44 +11,41 @@ var TokensManager = require('../../src/auth/TokensManager');
var ensureProperty = require('../utils').ensureProperty;
-
-describe('AuthenticationClient', function () {
-
- describe('#constructor', function () {
- it('should raise an error when no options object is provided', function () {
- expect(AuthenticationClient)
- .to.throw(ArgumentError, 'Authentication Client SDK options must be an object');
+describe('AuthenticationClient', function() {
+ describe('#constructor', function() {
+ it('should raise an error when no options object is provided', function() {
+ expect(AuthenticationClient).to.throw(
+ ArgumentError,
+ 'Authentication Client SDK options must be an object'
+ );
});
-
- it('should raise an error when the domain is not valid', function () {
+ it('should raise an error when the domain is not valid', function() {
var client = AuthenticationClient.bind(null, { token: 'token', domain: '' });
- expect(client)
- .to.throw(ArgumentError, 'Must provide a domain');
+ expect(client).to.throw(ArgumentError, 'Must provide a domain');
});
});
-
- describe('instance properties', function () {
+ describe('instance properties', function() {
var properties = {
- 'OAuthAuthenticator': {
+ OAuthAuthenticator: {
name: 'oauth',
cls: OAuthAuthenticator
},
- 'DatabaseAuthenticator': {
+ DatabaseAuthenticator: {
name: 'database',
cls: DatabaseAuthenticator
},
- 'PasswordlessAuthenticator': {
+ PasswordlessAuthenticator: {
name: 'passwordless',
cls: PasswordlessAuthenticator
},
- 'UsersManager': {
+ UsersManager: {
name: 'users',
cls: UsersManager
},
- 'TokensManager': {
+ TokensManager: {
name: 'tokens',
cls: TokensManager
}
@@ -63,17 +60,19 @@ describe('AuthenticationClient', function () {
for (var name in properties) {
var property = properties[name];
- it('should expose an instance of ' + name, ensureProperty(client, property.name, property.cls));
+ it(
+ 'should expose an instance of ' + name,
+ ensureProperty(client, property.name, property.cls)
+ );
}
});
-
- describe('instance methods', function () {
+ describe('instance methods', function() {
var method;
var methods = [];
var client = new AuthenticationClient({ token: 'token', domain: 'auth0.com' });
- methods.forEach(function (method) {
+ methods.forEach(function(method) {
ensureMethod(client, method);
});
});
diff --git a/test/auth/database-auth.tests.js b/test/auth/database-auth.tests.js
index 01a667fca..d54b07167 100644
--- a/test/auth/database-auth.tests.js
+++ b/test/auth/database-auth.tests.js
@@ -17,51 +17,44 @@ var validOptions = {
clientId: CLIENT_ID
};
-
-describe('DatabaseAuthenticator', function () {
-
- afterEach(function () {
+describe('DatabaseAuthenticator', function() {
+ afterEach(function() {
nock.cleanAll();
});
+ describe('#constructor', function() {
+ it('should require an options object', function() {
+ expect(Authenticator).to.throw(ArgumentError, 'Missing authenticator options');
- describe('#constructor', function () {
- it('should require an options object', function () {
- expect(Authenticator)
- .to.throw(ArgumentError, 'Missing authenticator options');
-
- expect(Authenticator.bind(null, 1))
- .to.throw(ArgumentError, 'The authenticator options must be an object');
+ expect(Authenticator.bind(null, 1)).to.throw(
+ ArgumentError,
+ 'The authenticator options must be an object'
+ );
- expect(Authenticator.bind(null, validOptions))
- .to.not.throw(ArgumentError);
+ expect(Authenticator.bind(null, validOptions)).to.not.throw(ArgumentError);
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['signIn', 'signUp', 'changePassword', 'requestChangePasswordEmail'];
var oauth = new OAuth(validOptions);
var authenticator = new Authenticator(validOptions, oauth);
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(authenticator[method])
- .to.exist
- .to.be.an.instanceOf(Function);
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(authenticator[method]).to.exist.to.be.an.instanceOf(Function);
});
});
});
-
- describe('#signIn', function () {
+ describe('#signIn', function() {
var path = '/oauth/ro';
var userData = {
username: 'username',
password: 'pwd'
};
- beforeEach(function () {
+ beforeEach(function() {
var oauth = new OAuth(validOptions);
this.authenticator = new Authenticator(validOptions, oauth);
this.request = nock(API_URL)
@@ -69,70 +62,55 @@ describe('DatabaseAuthenticator', function () {
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.signIn)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.signIn).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require a username', function () {
+ it('should require a username', function() {
var auth = this.authenticator;
var userData = { password: 'password' };
var signIn = auth.signIn.bind(auth, userData);
- expect(signIn)
- .to.throw(ArgumentError, 'username field is required');
+ expect(signIn).to.throw(ArgumentError, 'username field is required');
});
-
- it('should require a password', function () {
+ it('should require a password', function() {
var auth = this.authenticator;
var userData = { username: 'username' };
var signIn = auth.signIn.bind(auth, userData);
- expect(signIn)
- .to.throw(ArgumentError, 'password field is required');
+ expect(signIn).to.throw(ArgumentError, 'password field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .signIn(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.signIn(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.signIn(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -143,146 +121,126 @@ describe('DatabaseAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use Username-Password-Authentication by default', function (done) {
+ it('should use Username-Password-Authentication by default', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'Username-Password-Authentication';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should allow the user to specify the connection', function (done) {
+ it('should allow the user to specify the connection', function(done) {
nock.cleanAll();
var data = extend({ connection: 'TEST_CONNECTION' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'TEST_CONNECTION';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use password as default grant type', function (done) {
+ it('should use password as default grant type', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'password';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should allow the user to specify the grant type', function (done) {
+ it('should allow the user to specify the grant type', function(done) {
nock.cleanAll();
var data = extend({ grant_type: 'TEST_GRANT' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'TEST_GRANT';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the openid scope by default', function (done) {
+ it('should use the openid scope by default', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.scope === 'openid';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -290,8 +248,7 @@ describe('DatabaseAuthenticator', function () {
});
});
-
- describe('#signUp', function () {
+ describe('#signUp', function() {
var path = '/dbconnections/signup';
var userData = {
email: 'test@domain.com',
@@ -299,87 +256,70 @@ describe('DatabaseAuthenticator', function () {
connection: 'TEST_CONNECTION'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.signUp)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.signUp).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require an email', function () {
+ it('should require an email', function() {
var auth = this.authenticator;
var userData = { password: 'password' };
var signUp = auth.signUp.bind(auth, userData);
- expect(signUp)
- .to.throw(ArgumentError, 'email field is required');
+ expect(signUp).to.throw(ArgumentError, 'email field is required');
});
-
- it('should require a password', function () {
+ it('should require a password', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com' };
var signUp = auth.signUp.bind(auth, userData);
- expect(signUp)
- .to.throw(ArgumentError, 'password field is required');
+ expect(signUp).to.throw(ArgumentError, 'password field is required');
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com', password: 'test' };
var signUp = auth.signUp.bind(auth, userData);
- expect(signUp)
- .to.throw(ArgumentError, 'connection field is required');
+ expect(signUp).to.throw(ArgumentError, 'connection field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .signUp(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.signUp(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.signUp(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.signUp(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -390,34 +330,29 @@ describe('DatabaseAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signUp(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signUp(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -425,8 +360,7 @@ describe('DatabaseAuthenticator', function () {
});
});
-
- describe('#changePassword', function () {
+ describe('#changePassword', function() {
var path = '/dbconnections/change_password';
var userData = {
email: 'test@domain.com',
@@ -434,87 +368,70 @@ describe('DatabaseAuthenticator', function () {
connection: 'TEST_CONNECTION'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.changePassword)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.changePassword).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require an email', function () {
+ it('should require an email', function() {
var auth = this.authenticator;
var userData = { password: 'password' };
var changePassword = auth.changePassword.bind(auth, userData);
- expect(changePassword)
- .to.throw(ArgumentError, 'email field is required');
+ expect(changePassword).to.throw(ArgumentError, 'email field is required');
});
-
- it('should require a password', function () {
+ it('should require a password', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com' };
var changePassword = auth.changePassword.bind(auth, userData);
- expect(changePassword)
- .to.throw(ArgumentError, 'password field is required');
+ expect(changePassword).to.throw(ArgumentError, 'password field is required');
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com', password: 'test' };
var changePassword = auth.changePassword.bind(auth, userData);
- expect(changePassword)
- .to.throw(ArgumentError, 'connection field is required');
+ expect(changePassword).to.throw(ArgumentError, 'connection field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .changePassword(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.changePassword(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.changePassword(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.changePassword(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -525,34 +442,29 @@ describe('DatabaseAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.changePassword(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.changePassword(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -560,85 +472,72 @@ describe('DatabaseAuthenticator', function () {
});
});
-
- describe('#requestChangePasswordEmail', function () {
+ describe('#requestChangePasswordEmail', function() {
var path = '/dbconnections/change_password';
var userData = {
email: 'test@domain.com',
connection: 'TEST_CONNECTION'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.requestChangePasswordEmail)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.requestChangePasswordEmail).to.throw(
+ ArgumentError,
+ 'Missing user data object'
+ );
});
-
- it('should require an email', function () {
+ it('should require an email', function() {
var auth = this.authenticator;
var userData = {};
var requestChangePasswordEmail = auth.requestChangePasswordEmail.bind(auth, userData);
- expect(requestChangePasswordEmail)
- .to.throw(ArgumentError, 'email field is required');
+ expect(requestChangePasswordEmail).to.throw(ArgumentError, 'email field is required');
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com' };
var requestChangePasswordEmail = auth.requestChangePasswordEmail.bind(auth, userData);
- expect(requestChangePasswordEmail)
- .to.throw(ArgumentError, 'connection field is required');
+ expect(requestChangePasswordEmail).to.throw(ArgumentError, 'connection field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .requestChangePasswordEmail(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.requestChangePasswordEmail(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.requestChangePasswordEmail(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.requestChangePasswordEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -649,39 +548,33 @@ describe('DatabaseAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.requestChangePasswordEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.requestChangePasswordEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
});
-
});
diff --git a/test/auth/oauth.tests.js b/test/auth/oauth.tests.js
index 54ec2025f..fdd5f3e83 100644
--- a/test/auth/oauth.tests.js
+++ b/test/auth/oauth.tests.js
@@ -16,46 +16,39 @@ var Authenticator = require(SRC_DIR + '/auth/OAuthAuthenticator');
var validOptions = {
baseUrl: API_URL,
clientId: CLIENT_ID,
- clientSecret: CLIENT_SECRET,
+ clientSecret: CLIENT_SECRET
};
-
-describe('OAuthAuthenticator', function () {
-
- afterEach(function () {
+describe('OAuthAuthenticator', function() {
+ afterEach(function() {
nock.cleanAll();
});
+ describe('#constructor', function() {
+ it('should require an options object', function() {
+ expect(Authenticator).to.throw(ArgumentError, 'Missing authenticator options');
- describe('#constructor', function () {
- it('should require an options object', function () {
- expect(Authenticator)
- .to.throw(ArgumentError, 'Missing authenticator options');
-
- expect(Authenticator.bind(null, 1))
- .to.throw(ArgumentError, 'The authenticator options must be an object');
+ expect(Authenticator.bind(null, 1)).to.throw(
+ ArgumentError,
+ 'The authenticator options must be an object'
+ );
- expect(Authenticator.bind(null, validOptions))
- .to.not.throw(ArgumentError);
+ expect(Authenticator.bind(null, validOptions)).to.not.throw(ArgumentError);
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['signIn', 'socialSignIn', 'passwordGrant'];
var authenticator = new Authenticator(validOptions);
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(authenticator[method])
- .to.exist
- .to.be.an.instanceOf(Function);
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(authenticator[method]).to.exist.to.be.an.instanceOf(Function);
});
});
});
-
- describe('#signIn', function () {
+ describe('#signIn', function() {
var path = '/oauth/ro';
var userData = {
username: 'username',
@@ -63,66 +56,53 @@ describe('OAuthAuthenticator', function () {
connection: 'Username-Password-Authentication'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.signIn)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.signIn).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var signIn = auth.signIn.bind(auth, {});
- expect(signIn)
- .to.throw(ArgumentError, 'connection field is required');
+ expect(signIn).to.throw(ArgumentError, 'connection field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .signIn(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.signIn(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.signIn(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data un the request', function (done) {
+ it('should include the user data un the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -133,123 +113,106 @@ describe('OAuthAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should allow the user to specify the connection', function (done) {
+ it('should allow the user to specify the connection', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'Username-Password-Authentication';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use password as default grant type', function (done) {
+ it('should use password as default grant type', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'password';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should allow the user to specify the grant type', function (done) {
+ it('should allow the user to specify the grant type', function(done) {
nock.cleanAll();
var data = extend({ grant_type: 'TEST_GRANT' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'TEST_GRANT';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the openid scope by default', function (done) {
+ it('should use the openid scope by default', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.scope === 'openid';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -257,80 +220,67 @@ describe('OAuthAuthenticator', function () {
});
});
- describe('#passwordGrant', function () {
+ describe('#passwordGrant', function() {
var path = '/oauth/token';
var userData = {
username: 'username',
password: 'pwd'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.passwordGrant)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.passwordGrant).to.throw(ArgumentError, 'Missing user data object');
});
- it('should require a username', function () {
+ it('should require a username', function() {
var auth = this.authenticator;
- var signIn = auth.passwordGrant.bind(auth, {password: 'pwd'});
+ var signIn = auth.passwordGrant.bind(auth, { password: 'pwd' });
- expect(signIn)
- .to.throw(ArgumentError, 'username field is required');
+ expect(signIn).to.throw(ArgumentError, 'username field is required');
});
- it('should require a password', function () {
+ it('should require a password', function() {
var auth = this.authenticator;
- var signIn = auth.passwordGrant.bind(auth, {username: 'samples@auth0.com'});
+ var signIn = auth.passwordGrant.bind(auth, { username: 'samples@auth0.com' });
- expect(signIn)
- .to.throw(ArgumentError, 'password field is required');
+ expect(signIn).to.throw(ArgumentError, 'password field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .passwordGrant(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.passwordGrant(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.passwordGrant(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.passwordGrant(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -341,99 +291,89 @@ describe('OAuthAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.passwordGrant(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.passwordGrant(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
- it('should include the Auth0 client secret in the request', function (done) {
+ it('should include the Auth0 client secret in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_secret === CLIENT_SECRET;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.passwordGrant(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
- it('should allow the user to specify the realm', function (done) {
+ it('should allow the user to specify the realm', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
- return body.realm === 'Username-Password-Authentication'
- && body.grant_type === 'http://auth0.com/oauth/grant-type/password-realm';
+ .post(path, function(body) {
+ return (
+ body.realm === 'Username-Password-Authentication' &&
+ body.grant_type === 'http://auth0.com/oauth/grant-type/password-realm'
+ );
})
.reply(200);
- this
- .authenticator
- .passwordGrant(Object.assign({realm: 'Username-Password-Authentication'}, userData))
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator
+ .passwordGrant(Object.assign({ realm: 'Username-Password-Authentication' }, userData))
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use password as default grant type', function (done) {
+ it('should use password as default grant type', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'password';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.passwordGrant(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -441,46 +381,39 @@ describe('OAuthAuthenticator', function () {
});
});
-
- describe('#socialSignIn', function () {
+ describe('#socialSignIn', function() {
var path = '/oauth/access_token';
var userData = {
access_token: 'TEST_ACCESS_TOKEN',
connection: 'facebook'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
+ it('should require an object as first argument', function() {
var auth = this.authenticator;
var socialSignIn = auth.socialSignIn.bind(auth);
var message = 'Missing user credential objects';
- expect(socialSignIn)
- .to.throw(ArgumentError, message);
+ expect(socialSignIn).to.throw(ArgumentError, message);
- expect(socialSignIn.bind(auth, userData))
- .to.not.throw(ArgumentError, message);
+ expect(socialSignIn.bind(auth, userData)).to.not.throw(ArgumentError, message);
});
-
- it('should require an access token', function () {
+ it('should require an access token', function() {
var auth = this.authenticator;
var socialSignIn = auth.socialSignIn.bind(auth, {});
var message = 'access_token field is required';
- expect(socialSignIn)
- .to.throw(ArgumentError, message);
+ expect(socialSignIn).to.throw(ArgumentError, message);
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var data = {
access_token: userData.access_token
@@ -488,12 +421,10 @@ describe('OAuthAuthenticator', function () {
var socialSignIn = auth.socialSignIn.bind(auth, data);
var message = 'connection field is required';
- expect(socialSignIn)
- .to.throw(ArgumentError, message);
+ expect(socialSignIn).to.throw(ArgumentError, message);
});
-
- it('should require a connection', function () {
+ it('should require a connection', function() {
var auth = this.authenticator;
var data = {
access_token: userData.access_token
@@ -501,51 +432,37 @@ describe('OAuthAuthenticator', function () {
var socialSignIn = auth.socialSignIn.bind(auth, data);
var message = 'connection field is required';
- expect(socialSignIn)
- .to.throw(ArgumentError, message);
+ expect(socialSignIn).to.throw(ArgumentError, message);
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .socialSignIn(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.socialSignIn(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function () {
+ it('should return a promise when no callback is given', function() {
var returnValue = this.authenticator.socialSignIn(userData);
- expect(returnValue)
- .to.be.an.instanceOf(Promise);
+ expect(returnValue).to.be.an.instanceOf(Promise);
});
-
- it('should not return a promise when a callback is given', function () {
- var cb = function () {};
+ it('should not return a promise when a callback is given', function() {
+ var cb = function() {};
var returnValue = this.authenticator.socialSignIn(userData, cb);
- expect(returnValue)
- .to.be.undefined;
+ expect(returnValue).to.be.undefined;
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
- .socialSignIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(userData).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should use the default client ID if none specified', function (done) {
+ it('should use the default client ID if none specified', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -553,19 +470,14 @@ describe('OAuthAuthenticator', function () {
.query({ client_id: CLIENT_ID })
.reply(200);
- this
- .authenticator
- .socialSignIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(userData).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should allow the user to specify a custom client ID', function (done) {
+ it('should allow the user to specify a custom client ID', function(done) {
nock.cleanAll();
var data = extend({}, userData);
@@ -576,19 +488,14 @@ describe('OAuthAuthenticator', function () {
data.client_id = 'OVERRIDEN_ID';
- this
- .authenticator
- .socialSignIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should use the openid scope by default', function (done) {
+ it('should use the openid scope by default', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -596,19 +503,14 @@ describe('OAuthAuthenticator', function () {
.query({ scope: 'openid' })
.reply(200);
- this
- .authenticator
- .socialSignIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(userData).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should allow the user to specify the scope', function (done) {
+ it('should allow the user to specify the scope', function(done) {
nock.cleanAll();
var data = extend({}, userData);
@@ -619,19 +521,14 @@ describe('OAuthAuthenticator', function () {
data.scope = 'openid name email';
- this
- .authenticator
- .socialSignIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should use application/json as Content-Type', function (done) {
+ it('should use application/json as Content-Type', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -639,86 +536,72 @@ describe('OAuthAuthenticator', function () {
.matchHeader('Content-Type', 'application/json')
.reply(200);
- this
- .authenticator
- .socialSignIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.authenticator.socialSignIn(userData).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
- describe('#clientCredentials', function () {
+ describe('#clientCredentials', function() {
var path = '/oauth/token';
var options = {
audience: 'audience',
scope: 'scope'
};
- beforeEach(function () {
+ beforeEach(function() {
this.authenticator = new Authenticator(validOptions);
this.request = nock(API_URL)
.post(path)
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.clientCredentialsGrant)
- .to.throw(ArgumentError, 'Missing options object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.clientCredentialsGrant).to.throw(
+ ArgumentError,
+ 'Missing options object'
+ );
});
- it('should require the client_id', function () {
+ it('should require the client_id', function() {
var authenticator = new Authenticator({});
- expect(function(){
- authenticator.clientCredentialsGrant({})
+ expect(function() {
+ authenticator.clientCredentialsGrant({});
}).to.throw(ArgumentError, 'client_id field is required');
});
- it('should require the client_secret', function () {
+ it('should require the client_secret', function() {
var authenticator = new Authenticator({
clientId: CLIENT_ID
});
- expect(function(){
- authenticator.clientCredentialsGrant({})
+ expect(function() {
+ authenticator.clientCredentialsGrant({});
}).to.throw(ArgumentError, 'client_secret field is required');
});
- it('should accept a callback', function (done) {
- this
- .authenticator
- .clientCredentialsGrant(options, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.clientCredentialsGrant(options, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function () {
- return this
- .authenticator
- .clientCredentialsGrant(options);
+ it('should return a promise when no callback is provided', function() {
+ return this.authenticator.clientCredentialsGrant(options);
});
-
- it('should perform a POST request to ' + path, function () {
+ it('should perform a POST request to ' + path, function() {
var request = this.request;
- return this
- .authenticator
- .clientCredentialsGrant(options)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(options).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
- it('should include the options in the request', function () {
+ it('should include the options in the request', function() {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in options) {
if (options[property] !== body[property]) {
return false;
@@ -729,92 +612,66 @@ describe('OAuthAuthenticator', function () {
})
.reply(200);
- return this
- .authenticator
- .clientCredentialsGrant(options)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(options).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
- it('should include the Auth0 client ID and secret in the request', function () {
+ it('should include the Auth0 client ID and secret in the request', function() {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID && body.client_secret === CLIENT_SECRET;
})
.reply(200);
- return this
- .authenticator
- .clientCredentialsGrant(options)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(options).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
- it('should allow the user to specify the audience and scope', function () {
+ it('should allow the user to specify the audience and scope', function() {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.audience === 'audience' && body.scope === 'scope';
})
.reply(200);
- return this
- .authenticator
- .clientCredentialsGrant(options)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(options).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
- it('should use client_credentials as default grant type', function () {
+ it('should use client_credentials as default grant type', function() {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'client_credentials';
})
.reply(200);
- return this
- .authenticator
- .clientCredentialsGrant(options)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(options).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
- it('should allow the user to specify the grant type', function () {
+ it('should allow the user to specify the grant type', function() {
nock.cleanAll();
var data = extend({ grant_type: 'TEST_GRANT' }, options);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'TEST_GRANT';
})
.reply(200);
- return this
- .authenticator
- .clientCredentialsGrant(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- });
+ return this.authenticator.clientCredentialsGrant(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ });
});
-
});
-
});
diff --git a/test/auth/passwordless.tests.js b/test/auth/passwordless.tests.js
index a8aeb3c2e..67271376d 100644
--- a/test/auth/passwordless.tests.js
+++ b/test/auth/passwordless.tests.js
@@ -17,51 +17,44 @@ var validOptions = {
clientId: CLIENT_ID
};
-
-describe('PasswordlessAuthenticator', function () {
-
- afterEach(function () {
+describe('PasswordlessAuthenticator', function() {
+ afterEach(function() {
nock.cleanAll();
});
+ describe('#constructor', function() {
+ it('should require an options object', function() {
+ expect(Authenticator).to.throw(ArgumentError, 'Missing authenticator options');
- describe('#constructor', function () {
- it('should require an options object', function () {
- expect(Authenticator)
- .to.throw(ArgumentError, 'Missing authenticator options');
-
- expect(Authenticator.bind(null, 1))
- .to.throw(ArgumentError, 'The authenticator options must be an object');
+ expect(Authenticator.bind(null, 1)).to.throw(
+ ArgumentError,
+ 'The authenticator options must be an object'
+ );
- expect(Authenticator.bind(null, validOptions))
- .to.not.throw(ArgumentError);
+ expect(Authenticator.bind(null, validOptions)).to.not.throw(ArgumentError);
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['signIn', 'sendEmail', 'sendSMS'];
var oauth = new OAuth(validOptions);
var authenticator = new Authenticator(validOptions, oauth);
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(authenticator[method])
- .to.exist
- .to.be.an.instanceOf(Function);
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(authenticator[method]).to.exist.to.be.an.instanceOf(Function);
});
});
});
-
- describe('#signIn', function () {
+ describe('#signIn', function() {
var path = '/oauth/ro';
var userData = {
username: 'username',
password: 'pwd'
};
- beforeEach(function () {
+ beforeEach(function() {
var oauth = new OAuth(validOptions);
this.authenticator = new Authenticator(validOptions, oauth);
this.request = nock(API_URL)
@@ -69,70 +62,55 @@ describe('PasswordlessAuthenticator', function () {
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.signIn)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.signIn).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require a phone number', function () {
+ it('should require a phone number', function() {
var auth = this.authenticator;
var userData = { password: 'password' };
var signIn = auth.signIn.bind(auth, userData);
- expect(signIn)
- .to.throw(ArgumentError, 'username field (phone number) is required');
+ expect(signIn).to.throw(ArgumentError, 'username field (phone number) is required');
});
-
- it('should require a verification code', function () {
+ it('should require a verification code', function() {
var auth = this.authenticator;
var userData = { username: 'username' };
var signIn = auth.signIn.bind(auth, userData);
- expect(signIn)
- .to.throw(ArgumentError, 'password field (verification code) is required');
+ expect(signIn).to.throw(ArgumentError, 'password field (verification code) is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .signIn(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.signIn(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.signIn(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -143,145 +121,125 @@ describe('PasswordlessAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use SMS connection', function (done) {
+ it('should use SMS connection', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'sms';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use email connection', function (done) {
+ it('should use email connection', function(done) {
nock.cleanAll();
var data = extend({ connection: 'email' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'email';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should allow the user to specify the connection as sms or email', function (done) {
+ it('should allow the user to specify the connection as sms or email', function(done) {
nock.cleanAll();
var data = extend({ connection: 'TEST_CONNECTION' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'sms' || body.connection === 'email';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use password as grant type', function (done) {
+ it('should use password as grant type', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.grant_type === 'password';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the openid scope', function (done) {
+ it('should use the openid scope', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.scope === 'openid';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.signIn(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -289,15 +247,14 @@ describe('PasswordlessAuthenticator', function () {
});
});
-
- describe('#sendEmail', function () {
+ describe('#sendEmail', function() {
var path = '/passwordless/start';
var userData = {
email: 'email@domain.com',
send: 'link'
};
- beforeEach(function () {
+ beforeEach(function() {
var oauth = new OAuth(validOptions);
this.authenticator = new Authenticator(validOptions, oauth);
this.request = nock(API_URL)
@@ -305,70 +262,55 @@ describe('PasswordlessAuthenticator', function () {
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.sendEmail)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.sendEmail).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require an email', function () {
+ it('should require an email', function() {
var auth = this.authenticator;
var userData = {};
var sendEmail = auth.sendEmail.bind(auth, userData);
- expect(sendEmail)
- .to.throw(ArgumentError, 'email field is required');
+ expect(sendEmail).to.throw(ArgumentError, 'email field is required');
});
-
- it('should require the send field', function () {
+ it('should require the send field', function() {
var auth = this.authenticator;
var userData = { email: 'email@domain.com' };
var sendEmail = auth.sendEmail.bind(auth, userData);
- expect(sendEmail)
- .to.throw(ArgumentError, 'send field is required');
+ expect(sendEmail).to.throw(ArgumentError, 'send field is required');
});
-
- it('should accept a callback', function (done) {
- this
- .authenticator
- .sendEmail(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.sendEmail(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.sendEmail(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.sendEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -379,104 +321,90 @@ describe('PasswordlessAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the email connection', function (done) {
+ it('should use the email connection', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'email';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendEmail(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the specified send type', function (done) {
+ it('should use the specified send type', function(done) {
nock.cleanAll();
var data = extend({}, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.send === 'code';
})
.reply(200);
data.send = 'code';
- this
- .authenticator
+ this.authenticator
.sendEmail(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('shouldn\'t allow the user to specify the connection', function (done) {
+ it("shouldn't allow the user to specify the connection", function(done) {
nock.cleanAll();
var data = extend({ connection: 'TEST_CONNECTION' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'email';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendEmail(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -484,14 +412,13 @@ describe('PasswordlessAuthenticator', function () {
});
});
-
- describe('#sendSMS', function () {
+ describe('#sendSMS', function() {
var path = '/passwordless/start';
var userData = {
phone_number: '12345678'
};
- beforeEach(function () {
+ beforeEach(function() {
var oauth = new OAuth(validOptions);
this.authenticator = new Authenticator(validOptions, oauth);
this.request = nock(API_URL)
@@ -499,59 +426,47 @@ describe('PasswordlessAuthenticator', function () {
.reply(200);
});
-
- it('should require an object as first argument', function () {
- expect(this.authenticator.sendSMS)
- .to.throw(ArgumentError, 'Missing user data object');
+ it('should require an object as first argument', function() {
+ expect(this.authenticator.sendSMS).to.throw(ArgumentError, 'Missing user data object');
});
-
- it('should require a phone number', function () {
+ it('should require a phone number', function() {
var auth = this.authenticator;
var userData = {};
var sendSMS = auth.sendSMS.bind(auth, userData);
- expect(sendSMS)
- .to.throw(ArgumentError, 'phone_number field is required');
+ expect(sendSMS).to.throw(ArgumentError, 'phone_number field is required');
});
- it('should accept a callback', function (done) {
- this
- .authenticator
- .sendSMS(userData, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.authenticator.sendSMS(userData, done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function (done) {
- this
- .authenticator
+ it('should return a promise when no callback is provided', function(done) {
+ this.authenticator
.sendSMS(userData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- this
- .authenticator
+ this.authenticator
.sendSMS(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the user data in the request', function (done) {
+ it('should include the user data in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in userData) {
if (userData[property] !== body[property]) {
return false;
@@ -562,79 +477,68 @@ describe('PasswordlessAuthenticator', function () {
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendSMS(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the Auth0 client ID in the request', function (done) {
+ it('should include the Auth0 client ID in the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === CLIENT_ID;
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendSMS(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the sms connection', function (done) {
+ it('should use the sms connection', function(done) {
nock.cleanAll();
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'sms';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendSMS(userData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('shouldn\'t allow the user to specify the connection', function (done) {
+ it("shouldn't allow the user to specify the connection", function(done) {
nock.cleanAll();
var data = extend({ connection: 'TEST_CONNECTION' }, userData);
var request = nock(API_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.connection === 'sms';
})
.reply(200);
- this
- .authenticator
+ this.authenticator
.sendSMS(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
diff --git a/test/auth/tokens-manager.tests.js b/test/auth/tokens-manager.tests.js
index f6ad4013d..43241e9cd 100644
--- a/test/auth/tokens-manager.tests.js
+++ b/test/auth/tokens-manager.tests.js
@@ -7,8 +7,7 @@ var Promise = require('bluebird');
var ArgumentError = require('rest-facade').ArgumentError;
var TokensManager = require('../../src/auth/TokensManager');
-
-describe('TokensManager', function () {
+describe('TokensManager', function() {
var validOptions = {
baseUrl: BASE_URL,
headers: {
@@ -18,112 +17,88 @@ describe('TokensManager', function () {
clientId: 'CLIENT_ID'
};
- afterEach(function () {
+ afterEach(function() {
nock.cleanAll();
});
-
- describe('#constructor', function () {
- it('should require an options object', function () {
- expect(TokensManager)
- .to.throw(ArgumentError, 'Missing tokens manager options');
+ describe('#constructor', function() {
+ it('should require an options object', function() {
+ expect(TokensManager).to.throw(ArgumentError, 'Missing tokens manager options');
});
- it('should require a base URL', function () {
+ it('should require a base URL', function() {
var manager = TokensManager.bind(null, {});
- expect(manager)
- .to.throw(ArgumentError, 'baseUrl field is required');
+ expect(manager).to.throw(ArgumentError, 'baseUrl field is required');
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getInfo', 'getDelegationToken'];
var manager = new TokensManager(validOptions);
- methods.forEach(function (methodName) {
- it('should have a ' + methodName + ' method', function () {
- expect(manager[methodName])
- .to.exist
- .to.be.an.instanceOf(Function);
+ methods.forEach(function(methodName) {
+ it('should have a ' + methodName + ' method', function() {
+ expect(manager[methodName]).to.exist.to.be.an.instanceOf(Function);
});
});
});
-
- describe('#getInfo', function () {
+ describe('#getInfo', function() {
var manager = new TokensManager(validOptions);
var path = '/tokeninfo';
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(BASE_URL)
.post(path)
.reply(200);
});
-
- it('should require an ID token', function () {
+ it('should require an ID token', function() {
var getInfo = manager.getInfo.bind(manager);
- expect(getInfo)
- .to.throw(ArgumentError, 'An ID token is required');
+ expect(getInfo).to.throw(ArgumentError, 'An ID token is required');
});
-
- it('should throw an error when the token is invalid', function () {
+ it('should throw an error when the token is invalid', function() {
var getInfo = manager.getInfo.bind(manager, '');
- expect(getInfo)
- .to.throw(ArgumentError, 'The ID token is not valid');
+ expect(getInfo).to.throw(ArgumentError, 'The ID token is not valid');
});
-
- it('should not throw errors when the token is valid', function () {
+ it('should not throw errors when the token is valid', function() {
var getInfo = manager.getInfo.bind(manager, 'VALID_TOKEN');
- expect(getInfo)
- .to.not.throw(ArgumentError);
+ expect(getInfo).to.not.throw(ArgumentError);
});
-
- it('should accept a callback', function (done) {
- manager
- .getInfo('VALID_TOKEN', done.bind(null, null));
+ it('should accept a callback', function(done) {
+ manager.getInfo('VALID_TOKEN', done.bind(null, null));
});
-
- it('should return a promise when no callback is provided', function () {
+ it('should return a promise when no callback is provided', function() {
var returnValue = manager.getInfo('VALID_TOKEN');
- expect(returnValue)
- .to.be.an.instanceOf(Promise);
+ expect(returnValue).to.be.an.instanceOf(Promise);
});
+ it('should not return a promise when a callback is provided', function() {
+ var returnValue = manager.getInfo('VALID_TOKEN', function() {});
- it('should not return a promise when a callback is provided', function () {
- var returnValue = manager.getInfo('VALID_TOKEN', function () {});
-
- expect(returnValue)
- .to.be.undefined;
+ expect(returnValue).to.be.undefined;
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
- manager
- .getInfo('VALID_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getInfo('VALID_TOKEN').then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the headers specified in the instance options', function (done) {
+ it('should include the headers specified in the instance options', function(done) {
nock.cleanAll();
var request = nock(BASE_URL)
@@ -131,97 +106,84 @@ describe('TokensManager', function () {
.matchHeader('Content-Type', validOptions.headers['Content-Type'])
.reply(200);
- manager
- .getInfo('VALID_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getInfo('VALID_TOKEN').then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should send the ID token in the body of the request', function (done) {
+ it('should send the ID token in the body of the request', function(done) {
nock.cleanAll();
var request = nock(BASE_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.id_token === 'VALID_TOKEN';
})
.reply(200);
- manager
- .getInfo('VALID_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getInfo('VALID_TOKEN').then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#getDelegationToken', function () {
+ describe('#getDelegationToken', function() {
var path = '/delegation';
var manager = new TokensManager(validOptions);
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(BASE_URL)
.post(path)
.reply(200);
});
-
- it('should require a data object', function () {
+ it('should require a data object', function() {
var getDelegationToken = manager.getDelegationToken.bind(manager);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'Missing token data object');
+ expect(getDelegationToken).to.throw(ArgumentError, 'Missing token data object');
});
-
- it('should require an ID token or refresh token' ,function () {
+ it('should require an ID token or refresh token', function() {
var data = {};
var getDelegationToken = manager.getDelegationToken.bind(manager, data);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'one of id_token or refresh_token is required');
+ expect(getDelegationToken).to.throw(
+ ArgumentError,
+ 'one of id_token or refresh_token is required'
+ );
});
-
- it('should not accept an ID token and a refresh token simulatenously' ,function () {
- var data = { id_token: 'foo', refresh_token: 'bar'};
+ it('should not accept an ID token and a refresh token simulatenously', function() {
+ var data = { id_token: 'foo', refresh_token: 'bar' };
var getDelegationToken = manager.getDelegationToken.bind(manager, data);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'id_token and refresh_token fields cannot be specified simulatenously');
+ expect(getDelegationToken).to.throw(
+ ArgumentError,
+ 'id_token and refresh_token fields cannot be specified simulatenously'
+ );
});
-
- it('should require a target client', function () {
+ it('should require a target client', function() {
var data = { id_token: 'TEST_ID_TOKEN' };
var getDelegationToken = manager.getDelegationToken.bind(manager, data);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'target field is required');
+ expect(getDelegationToken).to.throw(ArgumentError, 'target field is required');
});
-
- it('should require an API type', function () {
+ it('should require an API type', function() {
var data = {
id_token: 'TEST_ID_TOKEN',
target: 'TEST_TARGET'
};
var getDelegationToken = manager.getDelegationToken.bind(manager, data);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'api_type field is required');
+ expect(getDelegationToken).to.throw(ArgumentError, 'api_type field is required');
});
-
- it('should require an grant type', function () {
+ it('should require an grant type', function() {
var data = {
id_token: 'TEST_ID_TOKEN',
target: 'TEST_TARGET',
@@ -229,12 +191,10 @@ describe('TokensManager', function () {
};
var getDelegationToken = manager.getDelegationToken.bind(manager, data);
- expect(getDelegationToken)
- .to.throw(ArgumentError, 'grant_type field is required');
+ expect(getDelegationToken).to.throw(ArgumentError, 'grant_type field is required');
});
-
- it('should accept a callback', function (done) {
+ it('should accept a callback', function(done) {
var data = {
id_token: 'TEST_ID_TOKEN',
target: 'TEST_TARGET',
@@ -245,8 +205,7 @@ describe('TokensManager', function () {
manager.getDelegationToken(data, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function () {
+ it('should return a promise when no callback is given', function() {
var data = {
id_token: 'TEST_ID_TOKEN',
target: 'TEST_TARGET',
@@ -255,33 +214,24 @@ describe('TokensManager', function () {
};
var returnValue = manager.getDelegationToken(data);
- expect(returnValue)
- .to.be.an.instanceOf(Promise);
+ expect(returnValue).to.be.an.instanceOf(Promise);
});
-
- it('should not return a promise when a callback is given', function () {
+ it('should not return a promise when a callback is given', function() {
var data = {
id_token: 'TEST_ID_TOKEN',
target: 'TEST_TARGET',
api_type: 'aws',
grant_type: 'SAMPLE_GRANT_TYPE'
};
- var returnValue = manager.getDelegationToken(
- data,
- function () {}
- );
+ var returnValue = manager.getDelegationToken(data, function() {});
- expect(returnValue)
- .to.equal(undefined);
+ expect(returnValue).to.equal(undefined);
});
+ it('should perform a POST request to ' + path, function() {});
- it('should perform a POST request to ' + path, function () {
-
- });
-
- it('should include the data in the body of the request', function (done) {
+ it('should include the data in the body of the request', function(done) {
nock.cleanAll();
var data = {
@@ -292,7 +242,7 @@ describe('TokensManager', function () {
};
var request = nock(BASE_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
for (var property in data) {
if (body[property] !== data[property]) {
return false;
@@ -303,18 +253,14 @@ describe('TokensManager', function () {
})
.reply();
- manager
- .getDelegationToken(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getDelegationToken(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should use the instance client ID if none specified', function (done) {
+ it('should use the instance client ID if none specified', function(done) {
nock.cleanAll();
var data = {
@@ -325,23 +271,19 @@ describe('TokensManager', function () {
};
var request = nock(BASE_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === validOptions.clientId;
})
.reply();
- manager
- .getDelegationToken(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getDelegationToken(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should let the user override the default client ID', function (done) {
+ it('should let the user override the default client ID', function(done) {
nock.cleanAll();
var data = {
@@ -353,23 +295,19 @@ describe('TokensManager', function () {
};
var request = nock(BASE_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.client_id === data.client_id;
})
.reply();
- manager
- .getDelegationToken(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getDelegationToken(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the headers specified in the instance options', function (done) {
+ it('should include the headers specified in the instance options', function(done) {
nock.cleanAll();
var data = {
@@ -384,15 +322,11 @@ describe('TokensManager', function () {
.matchHeader('Test-Header', validOptions.headers['Test-Header'])
.reply(200);
- manager
- .getDelegationToken(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.getDelegationToken(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/auth/user-profile.tests.js b/test/auth/user-profile.tests.js
index 5297bc891..5f8fd5610 100644
--- a/test/auth/user-profile.tests.js
+++ b/test/auth/user-profile.tests.js
@@ -16,7 +16,4 @@ var validOptions = {
clientId: CLIENT_ID
};
-
-describe('UserProfile', function () {
-
-});
+describe('UserProfile', function() {});
diff --git a/test/auth/users-manager.tests.js b/test/auth/users-manager.tests.js
index c2fafde1e..d5815337c 100644
--- a/test/auth/users-manager.tests.js
+++ b/test/auth/users-manager.tests.js
@@ -8,8 +8,7 @@ var CLIENT_ID = 'TEST_CLIENT_ID';
var ArgumentError = require('rest-facade').ArgumentError;
var UsersManager = require('../../src/auth/UsersManager');
-
-describe('UsersManager', function () {
+describe('UsersManager', function() {
var options = {
baseUrl: BASE_URL,
clientId: CLIENT_ID,
@@ -18,112 +17,89 @@ describe('UsersManager', function () {
}
};
- afterEach(function () {
+ afterEach(function() {
nock.cleanAll();
});
-
- describe('#constructor', function () {
- it ('should require an options object', function () {
- expect(UsersManager)
- .to.throw(ArgumentError, 'Missing users manager options');
+ describe('#constructor', function() {
+ it('should require an options object', function() {
+ expect(UsersManager).to.throw(ArgumentError, 'Missing users manager options');
});
-
- it ('should require a base URL', function () {
- expect(UsersManager.bind(null, {}))
- .to.throw(ArgumentError, 'baseUrl field is required');
+ it('should require a base URL', function() {
+ expect(UsersManager.bind(null, {})).to.throw(ArgumentError, 'baseUrl field is required');
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var manager = new UsersManager(options);
var methods = ['getInfo', 'impersonate'];
- methods.forEach(function (methodName) {
- it('should have a ' + methodName + ' method', function () {
- expect(manager[methodName])
- .to.exist
- .to.be.an.instanceOf(Function);
+ methods.forEach(function(methodName) {
+ it('should have a ' + methodName + ' method', function() {
+ expect(manager[methodName]).to.exist.to.be.an.instanceOf(Function);
});
});
});
-
- describe('#getInfo', function () {
+ describe('#getInfo', function() {
var manager = new UsersManager(options);
var path = '/userinfo';
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(BASE_URL)
.get(path)
.reply(200);
});
-
- it('should require an access token', function () {
+ it('should require an access token', function() {
var getInfo = manager.getInfo.bind(manager);
- expect(getInfo)
- .to.throw(ArgumentError, 'An access token is required');
+ expect(getInfo).to.throw(ArgumentError, 'An access token is required');
});
-
- it('should throw an error when the token is invalid', function () {
+ it('should throw an error when the token is invalid', function() {
var getInfo = manager.getInfo.bind(manager, '');
- expect(getInfo)
- .to.throw(ArgumentError, 'Invalid access token');
+ expect(getInfo).to.throw(ArgumentError, 'Invalid access token');
});
-
- it('should not throw errors when the token is valid', function () {
+ it('should not throw errors when the token is valid', function() {
var getInfo = manager.getInfo.bind(manager, 'VALID_TOKEN');
- expect(getInfo)
- .to.not.throw(ArgumentError);
+ expect(getInfo).to.not.throw(ArgumentError);
});
-
- it('should accept a callback', function (done) {
- manager
- .getInfo('ACCESS_TOKEN', done.bind(null, null))
+ it('should accept a callback', function(done) {
+ manager.getInfo('ACCESS_TOKEN', done.bind(null, null));
});
+ it('should not return a promise when a callback is provided', function() {
+ var returnValue = manager.getInfo('ACCESS_TOKEN', function() {});
- it('should not return a promise when a callback is provided', function () {
- var returnValue = manager.getInfo('ACCESS_TOKEN', function () {});
-
- expect(returnValue)
- .to.equal(undefined);
+ expect(returnValue).to.equal(undefined);
});
-
- it('should return a promise when no callback is provided', function () {
+ it('should return a promise when no callback is provided', function() {
var returnValue = manager.getInfo('ACCESS_TOKEN');
- expect(returnValue)
- .to.be.an.instanceOf(Promise);
+ expect(returnValue).to.be.an.instanceOf(Promise);
});
-
- it('should perform a GET request to ' + path, function (done) {
+ it('should perform a GET request to ' + path, function(done) {
var request = this.request;
manager
.getInfo('ACCESS_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should include the headers specified in the UsersManager options', function (done) {
+ it('should include the headers specified in the UsersManager options', function(done) {
nock.cleanAll();
var request = nock(BASE_URL)
@@ -133,17 +109,15 @@ describe('UsersManager', function () {
manager
.getInfo('ACCESS_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should send the access token in the Authorization header', function (done) {
+ it('should send the access token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(BASE_URL)
@@ -153,9 +127,8 @@ describe('UsersManager', function () {
manager
.getInfo('ACCESS_TOKEN')
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
@@ -163,74 +136,62 @@ describe('UsersManager', function () {
});
});
-
- describe('#impersonate', function () {
+ describe('#impersonate', function() {
var USER_ID = encodeURIComponent('github|12345');
var token = 'API V1 TOKEN';
var manager = new UsersManager(options);
var path = '/users/' + USER_ID + '/impersonate';
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(BASE_URL)
.post(path)
.reply(200);
});
-
- it('should require a user ID', function () {
+ it('should require a user ID', function() {
var impersonate = manager.impersonate.bind(manager);
- expect(impersonate)
- .to.throw(ArgumentError, 'You must specify a user ID');
+ expect(impersonate).to.throw(ArgumentError, 'You must specify a user ID');
});
-
- it('should throw an error when the user ID is not valid', function () {
+ it('should throw an error when the user ID is not valid', function() {
var impersonate = manager.impersonate.bind(manager, '');
- expect(impersonate)
- .to.throw(ArgumentError, 'The user ID is not valid');
+ expect(impersonate).to.throw(ArgumentError, 'The user ID is not valid');
});
-
- it('should require the impersonation settings object', function () {
+ it('should require the impersonation settings object', function() {
var impersonate = manager.impersonate.bind(manager, USER_ID);
- expect(impersonate)
- .to.throw(ArgumentError, 'Missing impersonation settings object');
+ expect(impersonate).to.throw(ArgumentError, 'Missing impersonation settings object');
});
-
- it('should require an impersonator ID', function () {
+ it('should require an impersonator ID', function() {
var impersonate = manager.impersonate.bind(manager, USER_ID, {});
- expect(impersonate)
- .to.throw(ArgumentError, 'impersonator_id field is required');
+ expect(impersonate).to.throw(ArgumentError, 'impersonator_id field is required');
});
- it('should require a token', function () {
+ it('should require a token', function() {
var settings = {
impersonator_id: 'auth0|12345',
protocol: 'oauth2'
};
var impersonate = manager.impersonate.bind(manager, USER_ID, settings);
- expect(impersonate)
- .to.throw(ArgumentError, 'token field is required');
+ expect(impersonate).to.throw(ArgumentError, 'token field is required');
});
- it('should require a protocol', function () {
+ it('should require a protocol', function() {
var settings = {
impersonator_id: 'auth0|12345'
};
var impersonate = manager.impersonate.bind(manager, USER_ID, settings);
- expect(impersonate)
- .to.throw(ArgumentError, 'protocol field is required');
+ expect(impersonate).to.throw(ArgumentError, 'protocol field is required');
});
-
- it('should accept a callback', function (done) {
+ it('should accept a callback', function(done) {
var settings = {
impersonator_id: 'auth0|12345',
protocol: 'oauth2',
@@ -240,25 +201,18 @@ describe('UsersManager', function () {
manager.impersonate(USER_ID, settings, done.bind(null, null));
});
-
- it('should not return a promise when a callback is provided', function () {
+ it('should not return a promise when a callback is provided', function() {
var settings = {
impersonator_id: 'auth0|12345',
protocol: 'oauth2',
token: token
};
- var returnValue = manager.impersonate(
- USER_ID,
- settings,
- function () {}
- );
-
- expect(returnValue)
- .to.equal(undefined);
- });
+ var returnValue = manager.impersonate(USER_ID, settings, function() {});
+ expect(returnValue).to.equal(undefined);
+ });
- it('should return a promise when no callback is provided', function () {
+ it('should return a promise when no callback is provided', function() {
var settings = {
impersonator_id: 'auth0|12345',
protocol: 'oauth2',
@@ -266,12 +220,10 @@ describe('UsersManager', function () {
};
var returnValue = manager.impersonate(USER_ID, settings);
- expect(returnValue)
- .to.be.an.instanceOf(Promise);
+ expect(returnValue).to.be.an.instanceOf(Promise);
});
-
- it('should perform a POST request to ' + path, function (done) {
+ it('should perform a POST request to ' + path, function(done) {
var request = this.request;
var settings = {
impersonator_id: 'auth0|12345',
@@ -281,17 +233,15 @@ describe('UsersManager', function () {
manager
.impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should use the default client ID', function (done) {
+ it('should use the default client ID', function(done) {
nock.cleanAll();
var settings = {
@@ -300,23 +250,19 @@ describe('UsersManager', function () {
token: token
};
var request = nock(BASE_URL)
- .post(path, function (body) {
- return body.client_id === CLIENT_ID
+ .post(path, function(body) {
+ return body.client_id === CLIENT_ID;
})
.reply(200);
- manager
- .impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.impersonate(USER_ID, settings).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should allow the user to override the client ID', function (done) {
+ it('should allow the user to override the client ID', function(done) {
nock.cleanAll();
var settings = {
@@ -326,23 +272,19 @@ describe('UsersManager', function () {
token: token
};
var request = nock(BASE_URL)
- .post(path, function (body) {
- return body.client_id === 'OVERRIDEN_CLIENT_ID'
+ .post(path, function(body) {
+ return body.client_id === 'OVERRIDEN_CLIENT_ID';
})
.reply(200);
- manager
- .impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.impersonate(USER_ID, settings).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should use the default headers', function (done) {
+ it('should use the default headers', function(done) {
nock.cleanAll();
var settings = {
@@ -355,17 +297,14 @@ describe('UsersManager', function () {
.matchHeader('Content-Type', options.headers['Content-Type'])
.reply(200);
- manager
- .impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.impersonate(USER_ID, settings).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
- it('should use the authorization header', function (done) {
+ it('should use the authorization header', function(done) {
nock.cleanAll();
var settings = {
@@ -378,17 +317,14 @@ describe('UsersManager', function () {
.matchHeader('Authorization', `Bearer ${token}`)
.reply(200);
- manager
- .impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ manager.impersonate(USER_ID, settings).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
- it('should allow the user to add additional parameters', function (done) {
+ it('should allow the user to add additional parameters', function(done) {
nock.cleanAll();
var settings = {
@@ -400,21 +336,16 @@ describe('UsersManager', function () {
token: token
};
var request = nock(BASE_URL)
- .post(path, function (body) {
+ .post(path, function(body) {
return body.additionalParameters.response_type === 'code';
})
.reply(200);
- manager
- .impersonate(USER_ID, settings)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
-
- done();
- });
+ manager.impersonate(USER_ID, settings).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
});
diff --git a/test/auth0-rest-client.tests.js b/test/auth0-rest-client.tests.js
index f65d62532..10721ebfd 100644
--- a/test/auth0-rest-client.tests.js
+++ b/test/auth0-rest-client.tests.js
@@ -2,83 +2,83 @@ var expect = require('chai').expect;
var nock = require('nock');
var ArgumentError = require('rest-facade').ArgumentError;
-var ManagementTokenProvider = require('../src/management/ManagementTokenProvider')
+var ManagementTokenProvider = require('../src/management/ManagementTokenProvider');
var Auth0RestClient = require('../src/Auth0RestClient');
var API_URL = 'https://tenant.auth0.com';
-describe('Auth0RestClient', function () {
- before(function () {
+describe('Auth0RestClient', function() {
+ before(function() {
this.providerMock = {
- getAccessToken: function () {
+ getAccessToken: function() {
return Promise.resolve('access_token');
}
- }
+ };
});
- it('should raise an error when no resource Url is provided', function () {
- expect(Auth0RestClient)
- .to.throw(ArgumentError, 'Must provide a Resource Url');
+ it('should raise an error when no resource Url is provided', function() {
+ expect(Auth0RestClient).to.throw(ArgumentError, 'Must provide a Resource Url');
});
- it('should raise an error when resource Url is invalid', function () {
+ it('should raise an error when resource Url is invalid', function() {
var client = Auth0RestClient.bind(null, '');
- expect(client)
- .to.throw(ArgumentError, 'The provided Resource Url is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided Resource Url is invalid');
});
- it('should raise an error when no options is provided', function () {
+ it('should raise an error when no options is provided', function() {
var client = Auth0RestClient.bind(null, '/some-resource');
- expect(client)
- .to.throw(ArgumentError, 'Must provide options');
+ expect(client).to.throw(ArgumentError, 'Must provide options');
});
- it('should accept a callback', function (done) {
- nock(API_URL).get('/some-resource')
+ it('should accept a callback', function(done) {
+ nock(API_URL)
+ .get('/some-resource')
.reply(200, { data: 'value' });
var options = {
headers: {}
- }
+ };
var client = new Auth0RestClient(API_URL + '/some-resource', options, this.providerMock);
- client.getAll(function (err, data) {
+ client.getAll(function(err, data) {
expect(data).to.deep.equal({ data: 'value' });
done();
- nock.cleanAll()
+ nock.cleanAll();
});
});
- it('should return a promise if no callback is given', function (done) {
- nock(API_URL).get('/some-resource')
+ it('should return a promise if no callback is given', function(done) {
+ nock(API_URL)
+ .get('/some-resource')
.reply(200, { data: 'value' });
var options = {
headers: {}
- }
+ };
var client = new Auth0RestClient(API_URL + '/some-resource', options, this.providerMock);
- client.getAll().then(function(data){
+ client.getAll().then(function(data) {
expect(data).to.deep.equal({ data: 'value' });
done();
- nock.cleanAll()
+ nock.cleanAll();
});
});
- it('should accept a callback and handle errors', function (done) {
+ it('should accept a callback and handle errors', function(done) {
var providerMock = {
- getAccessToken: function () {
+ getAccessToken: function() {
return Promise.reject(new Error('Some Error'));
}
- }
+ };
- nock(API_URL).get('/some-resource')
+ nock(API_URL)
+ .get('/some-resource')
.reply(500);
var options = {
headers: {}
- }
+ };
var client = new Auth0RestClient(API_URL + '/some-resource', options, providerMock);
- client.getAll(function (err, data) {
+ client.getAll(function(err, data) {
expect(err).to.not.null;
expect(err.message).to.be.equal('Some Error');
done();
@@ -86,34 +86,35 @@ describe('Auth0RestClient', function () {
});
});
- it('should set access token as Authorization header in options object', function (done) {
- nock(API_URL).get('/some-resource')
+ it('should set access token as Authorization header in options object', function(done) {
+ nock(API_URL)
+ .get('/some-resource')
.reply(200);
var options = {
headers: {}
- }
+ };
var client = new Auth0RestClient(API_URL + '/some-resource', options, this.providerMock);
- client.getAll().then(function(data){
+ client.getAll().then(function(data) {
expect(client.options.headers['Authorization']).to.be.equal('Bearer access_token');
done();
nock.cleanAll();
});
});
- it('should catch error when provider.getAccessToken throws an error', function (done) {
+ it('should catch error when provider.getAccessToken throws an error', function(done) {
var providerMock = {
- getAccessToken: function () {
+ getAccessToken: function() {
return Promise.reject(new Error('Some Error'));
}
- }
+ };
var client = new Auth0RestClient('/some-resource', {}, providerMock);
- client.getAll().catch(function (err) {
+ client.getAll().catch(function(err) {
expect(err).to.not.null;
expect(err.message).to.be.equal('Some Error');
done();
- })
+ });
});
});
diff --git a/test/auth0.tests.js b/test/auth0.tests.js
index 71f1d9a32..bb22ed825 100644
--- a/test/auth0.tests.js
+++ b/test/auth0.tests.js
@@ -3,19 +3,14 @@ var expect = require('chai').expect;
var auth0 = require('../src');
var AuthenticationClient = require('../src/auth');
var ManagementClient = require('../src/management');
-var ManagementTokenProvider = require('../src/management/ManagementTokenProvider')
+var ManagementTokenProvider = require('../src/management/ManagementTokenProvider');
+describe('Auth0 module', function() {
+ it('should expose the AuthenticationClient', function() {
+ expect(auth0.AuthenticationClient).to.equal(AuthenticationClient);
+ });
-describe('Auth0 module', function () {
-
- it('should expose the AuthenticationClient', function () {
- expect(auth0.AuthenticationClient)
- .to.equal(AuthenticationClient);
- });
-
-
- it('should expose the ManagementClient', function () {
- expect(auth0.ManagementClient)
- .to.equal(ManagementClient);
- });
+ it('should expose the ManagementClient', function() {
+ expect(auth0.ManagementClient).to.equal(ManagementClient);
+ });
});
diff --git a/test/constants.js b/test/constants.js
index 4037eaf8e..cdb00baab 100644
--- a/test/constants.js
+++ b/test/constants.js
@@ -1,4 +1,4 @@
-var constants = module.exports = {};
+var constants = (module.exports = {});
constants.BASE_API_URL = 'https://login.auth0.com/api/v2/';
constants.EU_BASE_API_URL = 'https://login.eu.auth0.com/api/v2/';
diff --git a/test/management/blacklisted-tokens.tests.js b/test/management/blacklisted-tokens.tests.js
index 63835f7bd..45e95eb75 100644
--- a/test/management/blacklisted-tokens.tests.js
+++ b/test/management/blacklisted-tokens.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var BlacklistedTokensManager = require(SRC_DIR + '/management/BlacklistedTokensManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('BlacklistedTokensManager', function () {
- before(function () {
+describe('BlacklistedTokensManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.blacklistedTokens = new BlacklistedTokensManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,88 +16,68 @@ describe('BlacklistedTokensManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['add', 'getAll'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.blacklistedTokens[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.blacklistedTokens[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(BlacklistedTokensManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(BlacklistedTokensManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = BlacklistedTokensManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = BlacklistedTokensManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/blacklists/tokens')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .blacklistedTokens
- .getAll(function () {
+ it('should accept a callback', function(done) {
+ this.blacklistedTokens.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .blacklistedTokens
+ it('should return a promise if no callback is given', function(done) {
+ this.blacklistedTokens
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/blacklists/tokens')
.reply(500);
- this
- .blacklistedTokens
- .getAll()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.blacklistedTokens.getAll().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -106,56 +85,41 @@ describe('BlacklistedTokensManager', function () {
.get('/blacklists/tokens')
.reply(200, data);
- this
- .blacklistedTokens
- .getAll()
- .then(function (blacklistedTokens) {
- expect(blacklistedTokens)
- .to.be.an.instanceOf(Array);
+ this.blacklistedTokens.getAll().then(function(blacklistedTokens) {
+ expect(blacklistedTokens).to.be.an.instanceOf(Array);
- expect(blacklistedTokens.length)
- .to.equal(data.length);
+ expect(blacklistedTokens.length).to.equal(data.length);
- expect(blacklistedTokens[0].test)
- .to.equal(data[0].test);
+ expect(blacklistedTokens[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/blacklists/tokens', function (done) {
+ it('should perform a GET request to /api/v2/blacklists/tokens', function(done) {
var request = this.request;
- this
- .blacklistedTokens
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.blacklistedTokens.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/blacklists/tokens')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .blacklistedTokens
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.blacklistedTokens.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -164,115 +128,88 @@ describe('BlacklistedTokensManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
-
- this
- .blacklistedTokens
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ .reply(200);
+
+ this.blacklistedTokens.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#add', function () {
+ describe('#add', function() {
var tokenData = {
aud: '',
jti: ''
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/blacklists/tokens')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .blacklistedTokens
- .add(tokenData, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.blacklistedTokens.add(tokenData, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .blacklistedTokens
+ it('should return a promise if no callback is given', function(done) {
+ this.blacklistedTokens
.add(tokenData)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/blacklists/tokens')
.reply(500);
- this
- .blacklistedTokens
- .add(tokenData)
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.blacklistedTokens.add(tokenData).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/blacklists/tokens', function (done) {
+ it('should perform a POST request to /api/v2/blacklists/tokens', function(done) {
var request = this.request;
- this
- .blacklistedTokens
- .add(tokenData)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.blacklistedTokens.add(tokenData).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the token data in the body of the request', function (done) {
+ it('should pass the token data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/blacklists/tokens', tokenData)
.reply(200);
- this
- .blacklistedTokens
- .add(tokenData)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.blacklistedTokens.add(tokenData).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/blacklists/tokens')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .blacklistedTokens
- .add(tokenData)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.blacklistedTokens.add(tokenData).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
});
diff --git a/test/management/client-grants.tests.js b/test/management/client-grants.tests.js
index a31bfabfc..08a27ca52 100644
--- a/test/management/client-grants.tests.js
+++ b/test/management/client-grants.tests.js
@@ -8,9 +8,8 @@ var API_URL = 'https://tenant.auth0.com';
var ClientGrantsManager = require(SRC_DIR + '/management/ClientGrantsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('ClientGrantsManager', function () {
- before(function () {
+describe('ClientGrantsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.grants = new ClientGrantsManager({
headers: {
@@ -20,90 +19,72 @@ describe('ClientGrantsManager', function () {
});
});
- afterEach(function () {
+ afterEach(function() {
nock.cleanAll();
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getAll', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.grants[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.grants[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(ClientGrantsManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(ClientGrantsManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var grants = ClientGrantsManager.bind(null, {});
- expect(grants)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(grants).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var grants = ClientGrantsManager.bind(null, { baseUrl: '' });
- expect(grants)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(grants).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
-
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/client-grants')
.reply(200);
});
- it('should accept a callback', function (done) {
- this.grants.getAll(function () {
+ it('should accept a callback', function(done) {
+ this.grants.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .grants
+ it('should return a promise if no callback is given', function(done) {
+ this.grants
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/client-grants')
.reply(500);
- this
- .grants
- .getAll()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.grants.getAll().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -111,55 +92,41 @@ describe('ClientGrantsManager', function () {
.get('/client-grants')
.reply(200, data);
- this
- .grants
- .getAll()
- .then(function (grants) {
- expect(grants)
- .to.be.an.instanceOf(Array);
+ this.grants.getAll().then(function(grants) {
+ expect(grants).to.be.an.instanceOf(Array);
- expect(grants.length)
- .to.equal(data.length);
+ expect(grants.length).to.equal(data.length);
- expect(grants[0].test)
- .to.equal(data[0].test);
+ expect(grants[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/client-grants', function (done) {
+ it('should perform a GET request to /api/v2/client-grants', function(done) {
var request = this.request;
- this
- .grants
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.grants.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/client-grants')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .grants
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.grants.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -168,106 +135,81 @@ describe('ClientGrantsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
-
- this
- .grants
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ .reply(200);
+
+ this.grants.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
-
- describe('#create', function () {
+ describe('#create', function() {
var data = {
client_id: 'CLIENT_ID',
audience: 'AUDIENCE',
scope: ['user']
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/client-grants')
- .reply(201, data)
- })
-
- it('should accept a callback', function (done) {
- this
- .grants
- .create(data, done.bind(null, null));
+ .reply(201, data);
});
+ it('should accept a callback', function(done) {
+ this.grants.create(data, done.bind(null, null));
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .grants
+ it('should return a promise if no callback is given', function(done) {
+ this.grants
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to /api/v2/client-grants', function (done) {
+ it('should perform a POST request to /api/v2/client-grants', function(done) {
var request = this.request;
- this
- .grants
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/client-grants')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(201, data)
+ .reply(201, data);
- this
- .grants
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new client grant data in the request body', function (done) {
+ it('should include the new client grant data in the request body', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/client-grants', data)
- .reply(201, data)
+ .reply(201, data);
- this
- .grants
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
- beforeEach(function () {
+ describe('#update', function() {
+ beforeEach(function() {
this.data = { id: 5 };
this.request = nock(API_URL)
@@ -275,95 +217,67 @@ describe('ClientGrantsManager', function () {
.reply(200, this.data);
});
-
- it('should accept a callback', function (done) {
- this
- .grants
- .update({ id: 5 }, {}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.grants.update({ id: 5 }, {}, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .grants
+ it('should return a promise if no callback is given', function(done) {
+ this.grants
.update({ id: 5 }, {})
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a PATCH request to /api/v2/client-grants/5', function (done) {
+ it('should perform a PATCH request to /api/v2/client-grants/5', function(done) {
var request = this.request;
- this
- .grants
- .update({ id: 5 }, {})
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.update({ id: 5 }, {}).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new data in the body of the request', function (done) {
+ it('should include the new data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/client-grants/' + this.data.id, this.data)
.reply(200);
- this
- .grants
- .update({ id: 5 }, this.data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.update({ id: 5 }, this.data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/client-grants/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .grants
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.grants.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .grants
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.grants.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to /client-grants/' + id, function (done) {
+ it('should perform a DELETE request to /client-grants/' + id, function(done) {
var request = this.request;
- this
- .grants
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.grants.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
});
diff --git a/test/management/client.tests.js b/test/management/client.tests.js
index f550caf33..e3325c277 100644
--- a/test/management/client.tests.js
+++ b/test/management/client.tests.js
@@ -8,10 +8,8 @@ var API_URL = 'https://tenant.auth0.com';
var ClientsManager = require(SRC_DIR + '/management/ClientsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('ClientsManager', function () {
-
- before(function () {
+describe('ClientsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.clients = new ClientsManager({
headers: {
@@ -21,91 +19,72 @@ describe('ClientsManager', function () {
});
});
-
- afterEach(function () {
+ afterEach(function() {
nock.cleanAll();
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getAll', 'get', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.clients[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.clients[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(ClientsManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(ClientsManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = ClientsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = ClientsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
-
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/clients')
.reply(200);
});
- it('should accept a callback', function (done) {
- this.clients.getAll(function () {
+ it('should accept a callback', function(done) {
+ this.clients.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .clients
+ it('should return a promise if no callback is given', function(done) {
+ this.clients
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/clients')
.reply(500);
- this
- .clients
- .getAll()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.clients.getAll().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -113,54 +92,41 @@ describe('ClientsManager', function () {
.get('/clients')
.reply(200, data);
- this
- .clients
- .getAll()
- .then(function (clients) {
- expect(clients)
- .to.be.an.instanceOf(Array);
+ this.clients.getAll().then(function(clients) {
+ expect(clients).to.be.an.instanceOf(Array);
- expect(clients.length)
- .to.equal(data.length);
+ expect(clients.length).to.equal(data.length);
- expect(clients[0].test)
- .to.equal(data[0].test);
+ expect(clients[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/clients', function (done) {
+ it('should perform a GET request to /api/v2/clients', function(done) {
var request = this.request;
- this
- .clients
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.clients.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/clients')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .clients
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.clients.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -169,101 +135,77 @@ describe('ClientsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .clients
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.clients.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#create', function () {
+ describe('#create', function() {
var data = { name: 'Test client' };
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/clients')
- .reply(201, data)
- })
-
- it('should accept a callback', function (done) {
- this
- .clients
- .create(data, done.bind(null, null));
+ .reply(201, data);
});
+ it('should accept a callback', function(done) {
+ this.clients.create(data, done.bind(null, null));
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .clients
+ it('should return a promise if no callback is given', function(done) {
+ this.clients
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to /api/v2/clients', function (done) {
+ it('should perform a POST request to /api/v2/clients', function(done) {
var request = this.request;
- this
- .clients
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/clients')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(201, data)
+ .reply(201, data);
- this
- .clients
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new client data in the request body', function (done) {
+ it('should include the new client data in the request body', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/clients', data)
- .reply(201, data)
+ .reply(201, data);
- this
- .clients
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#get', function () {
- beforeEach(function () {
+ describe('#get', function() {
+ beforeEach(function() {
this.data = {
id: 5,
name: 'John Doe',
@@ -273,45 +215,34 @@ describe('ClientsManager', function () {
this.request = nock(API_URL)
.get('/clients/' + this.data.id)
.reply(201, this.data);
- })
-
+ });
- it('should accept a callback', function (done) {
+ it('should accept a callback', function(done) {
var params = { id: this.data.id };
- this
- .clients
- .get(params, done.bind(null, null));
+ this.clients.get(params, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .clients
+ it('should return a promise if no callback is given', function(done) {
+ this.clients
.get({ id: this.data.id })
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to /api/v2/clients/5', function (done) {
+ it('should perform a POST request to /api/v2/clients/5', function(done) {
var request = this.request;
- this
- .clients
- .get({ client_id: this.data.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.get({ client_id: this.data.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
- beforeEach(function () {
+ describe('#update', function() {
+ beforeEach(function() {
this.data = { id: 5 };
this.request = nock(API_URL)
@@ -319,96 +250,67 @@ describe('ClientsManager', function () {
.reply(200, this.data);
});
-
- it('should accept a callback', function (done) {
- this
- .clients
- .update({ client_id: 5 }, {}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.clients.update({ client_id: 5 }, {}, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .clients
+ it('should return a promise if no callback is given', function(done) {
+ this.clients
.update({ client_id: 5 }, {})
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a PATCH request to /api/v2/clients/5', function (done) {
+ it('should perform a PATCH request to /api/v2/clients/5', function(done) {
var request = this.request;
- this
- .clients
- .update({ client_id: 5 }, {})
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.update({ client_id: 5 }, {}).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new data in the body of the request', function (done) {
+ it('should include the new data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/clients/' + this.data.id, this.data)
.reply(200);
- this
- .clients
- .update({ client_id: 5 }, this.data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.update({ client_id: 5 }, this.data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/clients/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .clients
- .delete({ client_id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.clients.delete({ client_id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .clients
- .delete({ client_id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.clients.delete({ client_id: id }).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to /clients/' + id, function (done) {
+ it('should perform a DELETE request to /clients/' + id, function(done) {
var request = this.request;
- this
- .clients
- .delete({ client_id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.clients.delete({ client_id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
});
-
diff --git a/test/management/connections.tests.js b/test/management/connections.tests.js
index 6a49e870f..a0764ca1f 100644
--- a/test/management/connections.tests.js
+++ b/test/management/connections.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var ConnectionsManager = require(SRC_DIR + '/management/ConnectionsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('ConnectionsManager', function () {
- before(function () {
+describe('ConnectionsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.connections = new ConnectionsManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,90 +16,69 @@ describe('ConnectionsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getAll', 'get', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.connections[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.connections[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(ConnectionsManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(ConnectionsManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = ConnectionsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = ConnectionsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/connections')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .connections
- .getAll(function () {
+ it('should accept a callback', function(done) {
+ this.connections.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .connections
+ it('should return a promise if no callback is given', function(done) {
+ this.connections
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/connections')
.reply(500);
- this
- .connections
- .getAll()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.connections.getAll().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -108,59 +86,42 @@ describe('ConnectionsManager', function () {
.get('/connections')
.reply(200, data);
- this
- .connections
- .getAll()
- .then(function (connections) {
- expect(connections)
- .to.be.an.instanceOf(Array);
+ this.connections.getAll().then(function(connections) {
+ expect(connections).to.be.an.instanceOf(Array);
- expect(connections.length)
- .to.equal(data.length);
+ expect(connections.length).to.equal(data.length);
- expect(connections[0].test)
- .to.equal(data[0].test);
+ expect(connections[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/connections', function (done) {
+ it('should perform a GET request to /api/v2/connections', function(done) {
var request = this.request;
- this
- .connections
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/connections')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .connections
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- done();
- });
+ this.connections.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -169,127 +130,96 @@ describe('ConnectionsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .connections
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#get', function () {
+ describe('#get', function() {
var params = { id: 5 };
var data = {
id: params.id,
name: 'Test connection'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/connections/' + data.id)
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .connections
- .get(params, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.connections.get(params, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .connections
+ it('should return a promise if no callback is given', function(done) {
+ this.connections
.get(params)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/connections/' + params.id)
.reply(500);
- this
- .connections
- .get()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.connections.get().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/connections/' + params.id)
.reply(200, data);
- this
- .connections
- .get(params)
- .then(function (connection) {
- expect(connection.id)
- .to.equal(data.id);
+ this.connections.get(params).then(function(connection) {
+ expect(connection.id).to.equal(data.id);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/connections/:id', function (done) {
+ it('should perform a GET request to /api/v2/connections/:id', function(done) {
var request = this.request;
- this
- .connections
- .get(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.get(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/connections')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .connections
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -298,127 +228,96 @@ describe('ConnectionsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .connections
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#create', function () {
+ describe('#create', function() {
var data = {
name: 'Test connection',
options: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/connections')
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .connections
- .create(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.connections.create(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .connections
+ it('should return a promise if no callback is given', function(done) {
+ this.connections
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/connections')
.reply(500);
- this
- .connections
- .create(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.connections.create(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/connections', function (done) {
+ it('should perform a POST request to /api/v2/connections', function(done) {
var request = this.request;
- this
- .connections
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/connections', data)
.reply(200);
- this
- .connections
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/connections')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .connections
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
+ describe('#update', function() {
var params = { id: 5 };
var data = {
id: 5,
@@ -426,183 +325,133 @@ describe('ConnectionsManager', function () {
options: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.patch('/connections/' + data.id)
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .connections
- .update(params, data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.connections.update(params, data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .connections
+ it('should return a promise if no callback is given', function(done) {
+ this.connections
.update(params, data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/connections/' + data.id)
.reply(500);
- this
- .connections
- .update(params, data)
- .catch(function (err) {
- expect(err)
- .to.exist
- .to.be.an.instanceOf(Error);
+ this.connections.update(params, data).catch(function(err) {
+ expect(err).to.exist.to.be.an.instanceOf(Error);
- done();
- });
+ done();
+ });
});
-
- it('should perform a PATCH request to /api/v2/connections/:id', function (done) {
+ it('should perform a PATCH request to /api/v2/connections/:id', function(done) {
var request = this.request;
- this
- .connections
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/connections/' + data.id, data)
.reply(200);
- this
- .connections
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/connections/' + data.id)
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .connections
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/connections/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .connections
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.connections.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .connections
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.connections.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to /connections/' + id, function (done) {
+ it('should perform a DELETE request to /connections/' + id, function(done) {
var request = this.request;
- this
- .connections
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/connections/' + id)
.reply(500);
- this
- .connections
- .delete({ id: id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.connections.delete({ id: id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/connections/' + id)
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .connections
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.connections.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/device-credentials.tests.js b/test/management/device-credentials.tests.js
index 2a02c419e..5f1c50d07 100644
--- a/test/management/device-credentials.tests.js
+++ b/test/management/device-credentials.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var DeviceCredentialsManager = require(SRC_DIR + '/management/DeviceCredentialsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('DeviceCredentialsManager', function () {
- before(function () {
+describe('DeviceCredentialsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.credentials = new DeviceCredentialsManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,88 +16,68 @@ describe('DeviceCredentialsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['createPublicKey', 'getAll', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.credentials[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.credentials[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(DeviceCredentialsManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(DeviceCredentialsManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = DeviceCredentialsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = DeviceCredentialsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/device-credentials')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .credentials
- .getAll(function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.credentials.getAll(function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .credentials
+ it('should return a promise if no callback is given', function(done) {
+ this.credentials
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/device-credentials')
.reply(500);
- this
- .credentials
- .getAll()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.credentials.getAll().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -106,56 +85,41 @@ describe('DeviceCredentialsManager', function () {
.get('/device-credentials')
.reply(200, data);
- this
- .credentials
- .getAll()
- .then(function (credentials) {
- expect(credentials)
- .to.be.an.instanceOf(Array);
+ this.credentials.getAll().then(function(credentials) {
+ expect(credentials).to.be.an.instanceOf(Array);
- expect(credentials.length)
- .to.equal(data.length);
+ expect(credentials.length).to.equal(data.length);
- expect(credentials[0].test)
- .to.equal(data[0].test);
+ expect(credentials[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/device-credentials', function (done) {
+ it('should perform a GET request to /api/v2/device-credentials', function(done) {
var request = this.request;
- this
- .credentials
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.credentials.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/device-credentials')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .credentials
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.credentials.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var params = {
@@ -165,204 +129,150 @@ describe('DeviceCredentialsManager', function () {
var request = nock(API_URL)
.get('/device-credentials')
.query(params)
- .reply(200)
+ .reply(200);
- this
- .credentials
- .getAll(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.getAll(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#createPublicKey', function () {
+ describe('#createPublicKey', function() {
var data = {
- 'device_name': 'Sample device',
+ device_name: 'Sample device',
type: 'public_key',
- 'user_id': 'github|1234'
+ user_id: 'github|1234'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/device-credentials')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .credentials
- .createPublicKey(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.credentials.createPublicKey(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .credentials
+ it('should return a promise if no callback is given', function(done) {
+ this.credentials
.createPublicKey(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/device-credentials')
.reply(500);
- this
- .credentials
- .createPublicKey(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.credentials.createPublicKey(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/device-credentials', function (done) {
+ it('should perform a POST request to /api/v2/device-credentials', function(done) {
var request = this.request;
- this
- .credentials
- .createPublicKey(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.createPublicKey(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/device-credentials', data)
.reply(200);
- this
- .credentials
- .createPublicKey(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.createPublicKey(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/device-credentials')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .credentials
- .createPublicKey(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.createPublicKey(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/device-credentials/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .credentials
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.credentials.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .credentials
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.credentials.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a delete request to /device-credentials/' + id, function (done) {
+ it('should perform a delete request to /device-credentials/' + id, function(done) {
var request = this.request;
- this
- .credentials
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/device-credentials/' + id)
.reply(500);
- this
- .credentials
- .delete({ id: id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.credentials.delete({ id: id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/device-credentials/' + id)
.matchHeader('authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .credentials
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.credentials.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/email-provider.tests.js b/test/management/email-provider.tests.js
index 9349b9d49..2d059b639 100644
--- a/test/management/email-provider.tests.js
+++ b/test/management/email-provider.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var EmailProviderManager = require(SRC_DIR + '/management/EmailProviderManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('EmailProviderManager', function () {
- before(function () {
+describe('EmailProviderManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.emailProvider = new EmailProviderManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,149 +16,113 @@ describe('EmailProviderManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['configure', 'get', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.emailProvider[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.emailProvider[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(EmailProviderManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(EmailProviderManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = EmailProviderManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = EmailProviderManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#get', function () {
+ describe('#get', function() {
var data = {
name: 'Test provider',
options: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/emails/provider')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .emailProvider
- .get(function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.emailProvider.get(function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .emailProvider
+ it('should return a promise if no callback is given', function(done) {
+ this.emailProvider
.get()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/emails/provider')
.reply(500);
- this
- .emailProvider
- .get()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.emailProvider.get().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/emails/provider')
.reply(200, data);
- this
- .emailProvider
- .get()
- .then(function (provider) {
- expect(provider.id)
- .to.equal(data.id);
+ this.emailProvider.get().then(function(provider) {
+ expect(provider.id).to.equal(data.id);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/emails/provider', function (done) {
+ it('should perform a GET request to /api/v2/emails/provider', function(done) {
var request = this.request;
- this
- .emailProvider
- .get()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.get().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/emails/provider')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .emailProvider
- .get()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.get().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var params = {
@@ -170,307 +133,226 @@ describe('EmailProviderManager', function () {
var request = nock(API_URL)
.get('/emails/provider')
.query(params)
- .reply(200)
+ .reply(200);
- this
- .emailProvider
- .get(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.get(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#configure', function () {
+ describe('#configure', function() {
var data = {
name: 'Test provider',
credentials: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/emails/provider')
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .emailProvider
- .configure(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.emailProvider.configure(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .emailProvider
+ it('should return a promise if no callback is given', function(done) {
+ this.emailProvider
.configure(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/emails/provider')
.reply(500);
- this
- .emailProvider
- .configure(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.emailProvider.configure(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/emails/provider', function (done) {
+ it('should perform a POST request to /api/v2/emails/provider', function(done) {
var request = this.request;
- this
- .emailProvider
- .configure(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.configure(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/emails/provider', data)
.reply(200);
- this
- .emailProvider
- .configure(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.configure(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/emails/provider')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .emailProvider
- .configure(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.configure(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
+ describe('#update', function() {
var data = {
name: 'Test provider',
credentials: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.patch('/emails/provider')
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .emailProvider
- .update({}, data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.emailProvider.update({}, data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .emailProvider
+ it('should return a promise if no callback is given', function(done) {
+ this.emailProvider
.update({}, data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/emails/provider/' + data.id)
.reply(500);
- this
- .emailProvider
- .update({}, data)
- .catch(function (err) {
- expect(err)
- .to.exist
- .to.be.an.instanceOf(Error);
+ this.emailProvider.update({}, data).catch(function(err) {
+ expect(err).to.exist.to.be.an.instanceOf(Error);
- done();
- });
+ done();
+ });
});
-
- it('should perform a PATCH request to /api/v2/emails/provider', function (done) {
+ it('should perform a PATCH request to /api/v2/emails/provider', function(done) {
var request = this.request;
- this
- .emailProvider
- .update({}, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.update({}, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/emails/provider', data)
.reply(200);
- this
- .emailProvider
- .update({}, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.update({}, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/emails/provider')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .emailProvider
- .update({}, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.update({}, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
- beforeEach(function () {
+ describe('#delete', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/emails/provider')
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .emailProvider
- .delete({}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.emailProvider.delete({}, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .emailProvider
- .delete()
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.emailProvider.delete().then(done.bind(null, null));
});
-
- it('should perform a DELETE request to /emails/provider', function (done) {
+ it('should perform a DELETE request to /emails/provider', function(done) {
var request = this.request;
- this
- .emailProvider
- .delete()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.delete().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/emails/provider')
.reply(500);
- this
- .emailProvider
- .delete()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.emailProvider.delete().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/emails/provider')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .emailProvider
- .delete()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.emailProvider.delete().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/jobs.tests.js b/test/management/jobs.tests.js
index eba223bd1..8e05b0777 100644
--- a/test/management/jobs.tests.js
+++ b/test/management/jobs.tests.js
@@ -9,9 +9,8 @@ var API_URL = 'https://tenant.auth0.com';
var JobsManager = require(SRC_DIR + '/management/JobsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('JobsManager', function () {
- before(function () {
+describe('JobsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.id = 'testJob';
this.jobs = new JobsManager({
@@ -20,88 +19,68 @@ describe('JobsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['verifyEmail', 'importUsers', 'get'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.jobs[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.jobs[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(JobsManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(JobsManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = JobsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = JobsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#get', function () {
- beforeEach(function () {
+ describe('#get', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/jobs/' + this.id)
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .jobs
- .get({ id: this.id }, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.jobs.get({ id: this.id }, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .jobs
+ it('should return a promise if no callback is given', function(done) {
+ this.jobs
.get({ id: this.id })
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/jobs/' + this.id)
.reply(500);
- this
- .jobs
- .get({ id: this.id })
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.jobs.get({ id: this.id }).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -109,58 +88,42 @@ describe('JobsManager', function () {
.get('/jobs/' + this.id)
.reply(200, data);
- this
- .jobs
- .get({ id: this.id })
- .then(function (blacklistedTokens) {
- expect(blacklistedTokens)
- .to.be.an.instanceOf(Array);
+ this.jobs.get({ id: this.id }).then(function(blacklistedTokens) {
+ expect(blacklistedTokens).to.be.an.instanceOf(Array);
- expect(blacklistedTokens.length)
- .to.equal(data.length);
+ expect(blacklistedTokens.length).to.equal(data.length);
- expect(blacklistedTokens[0].test)
- .to.equal(data[0].test);
+ expect(blacklistedTokens[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/jobs', function (done) {
+ it('should perform a GET request to /api/v2/jobs', function(done) {
var request = this.request;
- this
- .jobs
- .get({ id: this.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.get({ id: this.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/jobs/' + this.id)
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .jobs
- .get({ id: this.id })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.jobs.get({ id: this.id }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -169,271 +132,208 @@ describe('JobsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
-
- this
- .jobs
- .get({ id: this.id, include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ .reply(200);
+
+ this.jobs.get({ id: this.id, include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#importUsers', function () {
+ describe('#importUsers', function() {
var data = {
users: path.join(__dirname, '../data/users.json'),
connection_id: 'con_test'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/jobs/users-imports')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .jobs
- .importUsers(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.jobs.importUsers(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .jobs
+ it('should return a promise if no callback is given', function(done) {
+ this.jobs
.importUsers(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/users-imports')
.reply(500);
- this
- .jobs
- .importUsers(data)
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.jobs.importUsers(data).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/jobs/users-imports', function (done) {
+ it('should perform a POST request to /api/v2/jobs/users-imports', function(done) {
var request = this.request;
- this
- .jobs
- .importUsers(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.importUsers(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should be a multipart request', function (done) {
+ it('should be a multipart request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/users-imports')
- .matchHeader('Content-Type', function (header) {
+ .matchHeader('Content-Type', function(header) {
return header.indexOf('multipart/form-data') === 0;
})
.reply(200);
- this
- .jobs
- .importUsers(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.importUsers(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should have two parts: connection_id and users file', function (done) {
+ it('should have two parts: connection_id and users file', function(done) {
nock.cleanAll();
var boundary = null;
var request = nock(API_URL)
- .matchHeader('Content-Type', function (header) {
+ .matchHeader('Content-Type', function(header) {
boundary = '--' + header.match(/boundary=([^\n]*)/)[1];
return true;
})
- .post('/jobs/users-imports', function (body) {
+ .post('/jobs/users-imports', function(body) {
var parts = extractParts(body, boundary);
// Validate the connection id.
expect(parts.connection_id)
- .to.exist
- .to.be.a('string')
+ .to.exist.to.be.a('string')
.to.equal(data.connection_id);
// Validate the content type of the users JSON.
expect(parts.users)
- .to.exist
- .to.be.a('string')
+ .to.exist.to.be.a('string')
.to.contain('Content-Type: application/json');
// Validate the content of the users JSON.
- expect(parts.users.slice(-2))
- .to.equal('[]');
+ expect(parts.users.slice(-2)).to.equal('[]');
return true;
})
.reply(200);
- this
- .jobs
- .importUsers(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.importUsers(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/users-imports')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .jobs
- .importUsers(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.importUsers(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#verifyEmail', function () {
+ describe('#verifyEmail', function() {
var data = {
- user_id: 'github|12345',
+ user_id: 'github|12345'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/jobs/verification-email')
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .jobs
- .verifyEmail(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.jobs.verifyEmail(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .jobs
+ it('should return a promise if no callback is given', function(done) {
+ this.jobs
.verifyEmail(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/verification-email')
.reply(500);
- this
- .jobs
- .verifyEmail(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.jobs.verifyEmail(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/jobs/verification-email', function (done) {
+ it('should perform a POST request to /api/v2/jobs/verification-email', function(done) {
var request = this.request;
- this
- .jobs
- .verifyEmail(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.verifyEmail(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/verification-email', data)
.reply(200);
- this
- .jobs
- .verifyEmail(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.verifyEmail(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/jobs/verification-email')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .jobs
- .verifyEmail(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.jobs.verifyEmail(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/logs.tests.js b/test/management/logs.tests.js
index 7a1452948..37e6ed5e6 100644
--- a/test/management/logs.tests.js
+++ b/test/management/logs.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var LogsManager = require(SRC_DIR + '/management/LogsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('LogsManager', function () {
- before(function () {
+describe('LogsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.logs = new LogsManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,90 +16,69 @@ describe('LogsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getAll', 'get'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.logs[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.logs[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(LogsManager)
- .to.throw(ArgumentError, 'Must provide client options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(LogsManager).to.throw(ArgumentError, 'Must provide client options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = LogsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = LogsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/logs')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .logs
- .getAll(function () {
+ it('should accept a callback', function(done) {
+ this.logs.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .logs
+ it('should return a promise if no callback is given', function(done) {
+ this.logs
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/logs')
.reply(500);
- this
- .logs
- .getAll()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.logs.getAll().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -108,59 +86,42 @@ describe('LogsManager', function () {
.get('/logs')
.reply(200, data);
- this
- .logs
- .getAll()
- .then(function (logs) {
- expect(logs)
- .to.be.an.instanceOf(Array);
+ this.logs.getAll().then(function(logs) {
+ expect(logs).to.be.an.instanceOf(Array);
- expect(logs.length)
- .to.equal(data.length);
+ expect(logs.length).to.equal(data.length);
- expect(logs[0].test)
- .to.equal(data[0].test);
+ expect(logs[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/logs', function (done) {
+ it('should perform a GET request to /api/v2/logs', function(done) {
var request = this.request;
- this
- .logs
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.logs.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/logs')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .logs
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- done();
- });
+ this.logs.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -169,127 +130,96 @@ describe('LogsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .logs
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.logs.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#get', function () {
+ describe('#get', function() {
var params = { id: 5 };
var data = {
id: params.id,
name: 'Test log'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/logs/' + data.id)
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .logs
- .get(params, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.logs.get(params, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .logs
+ it('should return a promise if no callback is given', function(done) {
+ this.logs
.get(params)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/logs/' + params.id)
.reply(500);
- this
- .logs
- .get()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.logs.get().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/logs/' + params.id)
.reply(200, data);
- this
- .logs
- .get(params)
- .then(function (log) {
- expect(log.id)
- .to.equal(data.id);
+ this.logs.get(params).then(function(log) {
+ expect(log.id).to.equal(data.id);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/logs/:id', function (done) {
+ it('should perform a GET request to /api/v2/logs/:id', function(done) {
var request = this.request;
- this
- .logs
- .get(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.logs.get(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/logs')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .logs
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.logs.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -298,18 +228,13 @@ describe('LogsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .logs
- .getAll({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.logs.getAll({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/management-client.tests.js b/test/management/management-client.tests.js
index 941e02c76..9de874ed0 100644
--- a/test/management/management-client.tests.js
+++ b/test/management/management-client.tests.js
@@ -17,210 +17,198 @@ var StatsManager = require('../../src/management/StatsManager');
var TenantManager = require('../../src/management/TenantManager');
-describe('ManagementClient', function () {
- var withTokenProviderConfig = {
- clientId: 'clientId',
- clientSecret: 'clientSecret',
- domain: 'auth0-node-sdk.auth0.com'
- };
-
- var withTokenConfig = {
- domain: 'auth0-node-sdk.auth0.com',
- token: 'fake-token'
+describe('ManagementClient', function() {
+ var withTokenProviderConfig = {
+ clientId: 'clientId',
+ clientSecret: 'clientSecret',
+ domain: 'auth0-node-sdk.auth0.com'
+ };
+
+ var withTokenConfig = {
+ domain: 'auth0-node-sdk.auth0.com',
+ token: 'fake-token'
+ };
+
+ it('should expose an instance of ManagementClient when withTokenConfig is passed', function() {
+ expect(new ManagementClient(withTokenConfig)).to.exist.to.be.an.instanceOf(ManagementClient);
+ });
+
+ it('should expose an instance of ManagementClient when withTokenProviderConfig is passed', function() {
+ expect(new ManagementClient(withTokenProviderConfig)).to.exist.to.be.an.instanceOf(
+ ManagementClient
+ );
+ });
+
+ it('should expose an instance of ManagementClient when withTokenProviderConfig and audience is passed', function() {
+ var config = assign({ audience: 'https://auth0-node-sdk.auth0.com/api/v2/' }, withTokenConfig);
+ expect(new ManagementClient(config)).to.exist.to.be.an.instanceOf(ManagementClient);
+ });
+
+ it('should raise an error when no options object is provided', function() {
+ expect(ManagementClient).to.throw(
+ ArgumentError,
+ 'Management API SDK options must be an object'
+ );
+ });
+
+ it('should raise an error when the domain is not set', function() {
+ var config = assign({}, withTokenConfig);
+ delete config.domain;
+ var client = ManagementClient.bind(null, config);
+
+ expect(client).to.throw(ArgumentError, 'Must provide a domain');
+ });
+
+ it('should raise an error when the domain is not valid', function() {
+ var config = assign({}, withTokenConfig);
+ config.domain = '';
+ var client = ManagementClient.bind(null, config);
+
+ expect(client).to.throw(ArgumentError, 'Must provide a domain');
+ });
+
+ it('should raise an error when the token is not valid', function() {
+ var config = assign({}, withTokenConfig);
+ config.token = '';
+ var client = ManagementClient.bind(null, config);
+
+ expect(client).to.throw(ArgumentError, 'Must provide a token');
+ });
+
+ it('should raise an error when the token and clientId are not set', function() {
+ var config = assign({}, withTokenProviderConfig);
+ delete config.clientId;
+ var client = ManagementClient.bind(null, config);
+
+ expect(client).to.throw(ArgumentError, 'Must provide a clientId');
+ });
+
+ it('should raise an error when the token and clientSecret are not set', function() {
+ var config = assign({}, withTokenProviderConfig);
+ delete config.clientSecret;
+ var client = ManagementClient.bind(null, config);
+
+ expect(client).to.throw(ArgumentError, 'Must provide a clientSecret');
+ });
+
+ describe('instance properties', function() {
+ var manager;
+ var managers = {
+ UsersManager: {
+ property: 'users',
+ cls: UsersManager
+ },
+ BlacklistedTokensManager: {
+ property: 'blacklistedTokens',
+ cls: BlacklistedTokensManager
+ },
+ ClientsManager: {
+ property: 'clients',
+ cls: ClientsManager
+ },
+ ClientGrantsManager: {
+ property: 'clientGrants',
+ cls: ClientGrantsManager
+ },
+ ConnectionsManager: {
+ property: 'connections',
+ cls: ConnectionsManager
+ },
+ DeviceCredentialsManager: {
+ property: 'deviceCredentials',
+ cls: DeviceCredentialsManager
+ },
+ EmailProviderManager: {
+ property: 'emailProvider',
+ cls: EmailProviderManager
+ },
+ JobsManager: {
+ property: 'jobs',
+ cls: JobsManager
+ },
+ RulesManager: {
+ property: 'rules',
+ cls: RulesManager
+ },
+ StatsManager: {
+ property: 'stats',
+ cls: StatsManager
+ },
+ TenantManager: {
+ property: 'tenant',
+ cls: TenantManager
+ }
};
- it('should expose an instance of ManagementClient when withTokenConfig is passed', function () {
- expect(new ManagementClient(withTokenConfig))
- .to.exist
- .to.be.an.instanceOf(ManagementClient);
- });
-
- it('should expose an instance of ManagementClient when withTokenProviderConfig is passed', function () {
- expect(new ManagementClient(withTokenProviderConfig))
- .to.exist
- .to.be.an.instanceOf(ManagementClient);
- });
-
- it('should expose an instance of ManagementClient when withTokenProviderConfig and audience is passed', function () {
- var config = assign({audience: 'https://auth0-node-sdk.auth0.com/api/v2/'}, withTokenConfig);
- expect(new ManagementClient(config))
- .to.exist
- .to.be.an.instanceOf(ManagementClient);
- });
-
- it('should raise an error when no options object is provided', function () {
- expect(ManagementClient)
- .to.throw(ArgumentError, 'Management API SDK options must be an object');
- });
-
- it('should raise an error when the domain is not set', function () {
- var config = assign({}, withTokenConfig);
- delete config.domain;
- var client = ManagementClient.bind(null, config);
-
- expect(client)
- .to.throw(ArgumentError, 'Must provide a domain');
- });
-
- it('should raise an error when the domain is not valid', function () {
+ before(function() {
var config = assign({}, withTokenConfig);
- config.domain = '';
- var client = ManagementClient.bind(null, config);
-
- expect(client)
- .to.throw(ArgumentError, 'Must provide a domain');
+ this.client = new ManagementClient(config);
});
- it('should raise an error when the token is not valid', function () {
- var config = assign({}, withTokenConfig);
- config.token = '';
- var client = ManagementClient.bind(null, config);
+ // Tests common to all managers.
+ for (var name in managers) {
+ manager = managers[name];
- expect(client)
- .to.throw(ArgumentError, 'Must provide a token');
- });
-
- it('should raise an error when the token and clientId are not set', function () {
- var config = assign({}, withTokenProviderConfig);
- delete config.clientId;
- var client = ManagementClient.bind(null, config);
-
- expect(client)
- .to.throw(ArgumentError, 'Must provide a clientId');
- });
-
- it('should raise an error when the token and clientSecret are not set', function () {
- var config = assign({}, withTokenProviderConfig);
- delete config.clientSecret;
- var client = ManagementClient.bind(null, config);
-
- expect(client)
- .to.throw(ArgumentError, 'Must provide a clientSecret');
- });
-
- describe('instance properties', function () {
- var manager;
- var managers = {
- 'UsersManager': {
- property: 'users',
- cls: UsersManager
- },
- 'BlacklistedTokensManager': {
- property: 'blacklistedTokens',
- cls: BlacklistedTokensManager
- },
- 'ClientsManager': {
- property: 'clients',
- cls: ClientsManager
- },
- 'ClientGrantsManager': {
- property: 'clientGrants',
- cls: ClientGrantsManager
- },
- 'ConnectionsManager': {
- property: 'connections',
- cls: ConnectionsManager
- },
- 'DeviceCredentialsManager': {
- property: 'deviceCredentials',
- cls: DeviceCredentialsManager
- },
- 'EmailProviderManager': {
- property: 'emailProvider',
- cls: EmailProviderManager
- },
- 'JobsManager': {
- property: 'jobs',
- cls: JobsManager
- },
- 'RulesManager': {
- property: 'rules',
- cls: RulesManager
- },
- 'StatsManager': {
- property: 'stats',
- cls: StatsManager
- },
- 'TenantManager': {
- property: 'tenant',
- cls: TenantManager
- }
- };
-
- before(function () {
- var config = assign({}, withTokenConfig);
- this.client = new ManagementClient(config);
+ it('should expose an instance of ' + name, function() {
+ expect(this.client[manager.property]).to.exist.to.be.an.instanceOf(manager.cls);
});
-
- // Tests common to all managers.
- for (var name in managers) {
- manager = managers[name];
-
- it('should expose an instance of ' + name, function () {
- expect(this.client[manager.property])
- .to.exist
- .to.be.an.instanceOf(manager.cls);
- });
- }
+ }
+ });
+
+ describe('instance methods', function() {
+ var method;
+ var methods = [
+ 'getConnections',
+ 'createConnection',
+ 'getConnection',
+ 'deleteConnection',
+ 'updateConnection',
+ 'getClients',
+ 'getClient',
+ 'createClient',
+ 'updateClient',
+ 'deleteClient',
+ 'getClientGrants',
+ 'createClientGrant',
+ 'updateClientGrant',
+ 'deleteClientGrant',
+ 'createDevicePublicKey',
+ 'getDeviceCredentials',
+ 'deleteDeviceCredential',
+ 'getRules',
+ 'createRule',
+ 'getRule',
+ 'deleteRule',
+ 'updateRule',
+ 'getUsers',
+ 'getUser',
+ 'deleteAllUsers',
+ 'deleteUsers',
+ 'createUser',
+ 'updateUser',
+ 'getBlacklistedTokens',
+ 'blacklistToken',
+ 'getEmailProvider',
+ 'configureEmailProvider',
+ 'deleteEmailProvider',
+ 'updateEmailProvider',
+ 'getActiveUsersCount',
+ 'getDailyStats',
+ 'getTenantSettings',
+ 'updateTenantSettings'
+ ];
+
+ before(function() {
+ var config = assign({}, withTokenConfig);
+ this.client = new ManagementClient(config);
});
+ for (var i = 0, l = methods.length; i < l; i++) {
+ method = methods[i];
- describe('instance methods', function () {
- var method;
- var methods = [
- 'getConnections',
- 'createConnection',
- 'getConnection',
- 'deleteConnection',
- 'updateConnection',
- 'getClients',
- 'getClient',
- 'createClient',
- 'updateClient',
- 'deleteClient',
- 'getClientGrants',
- 'createClientGrant',
- 'updateClientGrant',
- 'deleteClientGrant',
- 'createDevicePublicKey',
- 'getDeviceCredentials',
- 'deleteDeviceCredential',
- 'getRules',
- 'createRule',
- 'getRule',
- 'deleteRule',
- 'updateRule',
- 'getUsers',
- 'getUser',
- 'deleteAllUsers',
- 'deleteUsers',
- 'createUser',
- 'updateUser',
- 'getBlacklistedTokens',
- 'blacklistToken',
- 'getEmailProvider',
- 'configureEmailProvider',
- 'deleteEmailProvider',
- 'updateEmailProvider',
- 'getActiveUsersCount',
- 'getDailyStats',
- 'getTenantSettings',
- 'updateTenantSettings'
- ];
-
- before(function () {
- var config = assign({}, withTokenConfig);
- this.client = new ManagementClient(config);
+ it('should have a ' + method + ' method', function() {
+ expect(this.client[method]).to.exist.to.be.an.instanceOf(Function);
});
-
- for (var i = 0, l = methods.length; i < l; i++) {
- method = methods[i];
-
- it('should have a ' + method + ' method', function () {
- expect(this.client[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- });
- }
- });
+ }
+ });
});
diff --git a/test/management/management-token-provider.tests.js b/test/management/management-token-provider.tests.js
index d6494d850..d7a18cd88 100644
--- a/test/management/management-token-provider.tests.js
+++ b/test/management/management-token-provider.tests.js
@@ -6,151 +6,140 @@ var APIError = require('rest-facade').APIError;
var ManagementTokenProvider = require('../../src/management/ManagementTokenProvider');
-describe('ManagementTokenProvider', function () {
- var defaultConfig = {
- clientId: 'clientId',
- clientSecret: 'clientSecret',
+describe('ManagementTokenProvider', function() {
+ var defaultConfig = {
+ clientId: 'clientId',
+ clientSecret: 'clientSecret',
domain: 'auth0-node-sdk.auth0.com',
- audience: 'https://auth0-node-sdk.auth0.com/api/v2/'
+ audience: 'https://auth0-node-sdk.auth0.com/api/v2/'
};
- it('should expose an instance of ManagementTokenProvider', function () {
- expect(new ManagementTokenProvider(defaultConfig))
- .to.exist
- .to.be.an.instanceOf(ManagementTokenProvider);
+ it('should expose an instance of ManagementTokenProvider', function() {
+ expect(new ManagementTokenProvider(defaultConfig)).to.exist.to.be.an.instanceOf(
+ ManagementTokenProvider
+ );
});
- it('should raise an error when no options object is provided', function () {
- expect(ManagementTokenProvider)
- .to.throw(ArgumentError, 'Options must be an object');
+ it('should raise an error when no options object is provided', function() {
+ expect(ManagementTokenProvider).to.throw(ArgumentError, 'Options must be an object');
});
- it('should raise an error when domain is not set', function () {
+ it('should raise an error when domain is not set', function() {
var config = assign({}, defaultConfig);
delete config.domain;
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a domain');
+ expect(provider).to.throw(ArgumentError, 'Must provide a domain');
});
- it('should raise an error when domain is not valid', function () {
+ it('should raise an error when domain is not valid', function() {
var config = assign({}, defaultConfig);
config.domain = '';
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a domain');
+ expect(provider).to.throw(ArgumentError, 'Must provide a domain');
});
- it('should raise an error when clientId is not set', function () {
+ it('should raise an error when clientId is not set', function() {
var config = assign({}, defaultConfig);
delete config.clientId;
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a clientId');
+ expect(provider).to.throw(ArgumentError, 'Must provide a clientId');
});
- it('should raise an error when clientId is not valid', function () {
+ it('should raise an error when clientId is not valid', function() {
var config = assign({}, defaultConfig);
config.clientId = '';
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a clientId');
+ expect(provider).to.throw(ArgumentError, 'Must provide a clientId');
});
- it('should raise an error when clientSecret is not set', function () {
+ it('should raise an error when clientSecret is not set', function() {
var config = assign({}, defaultConfig);
delete config.clientSecret;
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a clientSecret');
+ expect(provider).to.throw(ArgumentError, 'Must provide a clientSecret');
});
- it('should raise an error when clientSecret is not valid', function () {
+ it('should raise an error when clientSecret is not valid', function() {
var config = assign({}, defaultConfig);
config.clientSecret = '';
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'Must provide a clientSecret');
+ expect(provider).to.throw(ArgumentError, 'Must provide a clientSecret');
});
- it('should raise an error when enableCache is not of type boolean', function () {
+ it('should raise an error when enableCache is not of type boolean', function() {
var config = assign({}, defaultConfig);
config.enableCache = 'string';
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'enableCache must be a boolean');
+ expect(provider).to.throw(ArgumentError, 'enableCache must be a boolean');
});
- it('should raise an error when scope is not of type string', function () {
+ it('should raise an error when scope is not of type string', function() {
var config = assign({}, defaultConfig);
config.scope = ['foo', 'bar'];
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'scope must be a string');
+ expect(provider).to.throw(ArgumentError, 'scope must be a string');
});
- it('should set scope to read:users when passed as read:users', function () {
+ it('should set scope to read:users when passed as read:users', function() {
var config = assign({}, defaultConfig);
config.scope = 'read:users';
var provider = new ManagementTokenProvider(config);
expect(provider.options.scope).to.be.equal('read:users');
});
- it('should set enableCache to true when not specified', function () {
- var config = assign({}, defaultConfig);
- delete config.enableCache;
- var provider = new ManagementTokenProvider(config);
- expect(provider.options.enableCache).to.be.true;
+ it('should set enableCache to true when not specified', function() {
+ var config = assign({}, defaultConfig);
+ delete config.enableCache;
+ var provider = new ManagementTokenProvider(config);
+ expect(provider.options.enableCache).to.be.true;
});
- it('should set enableCache to true when passed as true', function () {
+ it('should set enableCache to true when passed as true', function() {
var config = assign({}, defaultConfig);
config.enableCache = true;
var provider = new ManagementTokenProvider(config);
expect(provider.options.enableCache).to.be.true;
});
- it('should set enableCache to false when passed as false', function () {
+ it('should set enableCache to false when passed as false', function() {
var config = assign({}, defaultConfig);
config.enableCache = false;
var provider = new ManagementTokenProvider(config);
expect(provider.options.enableCache).to.be.false;
});
- it('should raise an error when the cacheTTLInSeconds is not of type number', function () {
+ it('should raise an error when the cacheTTLInSeconds is not of type number', function() {
var config = assign({}, defaultConfig);
config.cacheTTLInSeconds = 'string';
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'cacheTTLInSeconds must be a number');
+ expect(provider).to.throw(ArgumentError, 'cacheTTLInSeconds must be a number');
});
- it('should raise an error when the cacheTTLInSeconds is not a greater than 0', function () {
+ it('should raise an error when the cacheTTLInSeconds is not a greater than 0', function() {
var config = assign({}, defaultConfig);
config.cacheTTLInSeconds = -1;
var provider = ManagementTokenProvider.bind(null, config);
- expect(provider)
- .to.throw(ArgumentError, 'cacheTTLInSeconds must be a greater than 0');
+ expect(provider).to.throw(ArgumentError, 'cacheTTLInSeconds must be a greater than 0');
});
- it('should set cacheTTLInSeconds to 15 when passed as 15', function () {
+ it('should set cacheTTLInSeconds to 15 when passed as 15', function() {
var config = assign({}, defaultConfig);
config.cacheTTLInSeconds = 15;
var provider = new ManagementTokenProvider(config);
expect(provider.options.cacheTTLInSeconds).to.be.equal(15);
});
- it('should handle network errors correctly', function (done) {
+ it('should handle network errors correctly', function(done) {
var config = assign({}, defaultConfig);
config.domain = 'domain';
var client = new ManagementTokenProvider(config);
@@ -159,33 +148,29 @@ describe('ManagementTokenProvider', function () {
.post('/oauth/token')
.reply(401);
- client.getAccessToken()
- .catch(function(err){
- expect(err).to.exist
- done();
- });
- });
+ client.getAccessToken().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
+ });
- it('should handle unauthorized errors correctly', function (done) {
+ it('should handle unauthorized errors correctly', function(done) {
var client = new ManagementTokenProvider(defaultConfig);
nock('https://' + defaultConfig.domain)
.post('/oauth/token')
.reply(401);
- client.getAccessToken()
- .catch(function(err){
- expect(err)
- .to.exist
- .to.be.an.instanceOf(APIError);
- expect(err.statusCode).to.be.equal(401);
- done();
- nock.cleanAll();
- });
- });
+ client.getAccessToken().catch(function(err) {
+ expect(err).to.exist.to.be.an.instanceOf(APIError);
+ expect(err.statusCode).to.be.equal(401);
+ done();
+ nock.cleanAll();
+ });
+ });
- it('should return access token', function (done) {
+ it('should return access token', function(done) {
var config = assign({}, defaultConfig);
- config.domain = 'auth0-node-sdk-1.auth0.com'
+ config.domain = 'auth0-node-sdk-1.auth0.com';
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -193,24 +178,23 @@ describe('ManagementTokenProvider', function () {
.reply(200, {
access_token: 'token',
expires_in: 3600
- })
-
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('token');
- done();
- nock.cleanAll();
});
- });
- it('should contain correct body payload', function (done) {
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('token');
+ done();
+ nock.cleanAll();
+ });
+ });
+
+ it('should contain correct body payload', function(done) {
var config = assign({}, defaultConfig);
- config.domain = 'auth0-node-sdk-2.auth0.com'
+ config.domain = 'auth0-node-sdk-2.auth0.com';
var client = new ManagementTokenProvider(config);
-
+
nock('https://' + config.domain)
- .post('/oauth/token',function(body) {
+ .post('/oauth/token', function(body) {
expect(body.client_id).to.equal('clientId');
expect(body.client_secret).to.equal('clientSecret');
expect(body.grant_type).to.equal('client_credentials');
@@ -220,17 +204,15 @@ describe('ManagementTokenProvider', function () {
return cb(null, [200, { access_token: 'token', expires_in: 3600 }]);
});
- client.getAccessToken()
- .then(function(data){
-
- done();
- nock.cleanAll();
- });
+ client.getAccessToken().then(function(data) {
+ done();
+ nock.cleanAll();
+ });
});
- it('should return access token from the cache the second call', function (done) {
+ it('should return access token from the cache the second call', function(done) {
var config = assign({}, defaultConfig);
- config.domain = 'auth0-node-sdk-3.auth0.com'
+ config.domain = 'auth0-node-sdk-3.auth0.com';
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -241,30 +223,31 @@ describe('ManagementTokenProvider', function () {
expires_in: 3600
});
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
-
- setTimeout(function() {
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
- done();
- nock.cleanAll();
- }).catch(function(err){
- expect.fail();
- done();
- nock.cleanAll();
- });;
- }, 40); // 40ms
- });
- });
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+
+ setTimeout(function() {
+ client
+ .getAccessToken()
+ .then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+ done();
+ nock.cleanAll();
+ })
+ .catch(function(err) {
+ expect.fail();
+ done();
+ nock.cleanAll();
+ });
+ }, 40); // 40ms
+ });
+ });
- it('should request new access token when cache is expired', function (done) {
+ it('should request new access token when cache is expired', function(done) {
var config = assign({}, defaultConfig);
- config.domain = 'auth0-node-sdk-4.auth0.com'
+ config.domain = 'auth0-node-sdk-4.auth0.com';
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -277,33 +260,34 @@ describe('ManagementTokenProvider', function () {
.reply(200, {
access_token: 'new_access_token',
expires_in: 3600
- })
-
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
-
- setTimeout(function() {
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('new_access_token');
- done();
- nock.cleanAll();
- }).catch(function(err){
- expect.fail();
- done();
- nock.cleanAll();
- });;
- }, 40); // 40ms
});
+
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+
+ setTimeout(function() {
+ client
+ .getAccessToken()
+ .then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('new_access_token');
+ done();
+ nock.cleanAll();
+ })
+ .catch(function(err) {
+ expect.fail();
+ done();
+ nock.cleanAll();
+ });
+ }, 40); // 40ms
+ });
});
- it('should return new access token on the second call when cache is disabled', function (done) {
+ it('should return new access token on the second call when cache is disabled', function(done) {
var config = assign({}, defaultConfig);
config.enableCache = false;
- config.domain = 'auth0-node-sdk-3.auth0.com'
+ config.domain = 'auth0-node-sdk-3.auth0.com';
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -316,33 +300,34 @@ describe('ManagementTokenProvider', function () {
.reply(200, {
access_token: 'new_access_token',
expires_in: 3600
- })
-
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
-
- setTimeout(function() {
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('new_access_token');
- done();
- nock.cleanAll();
- }).catch(function(err){
- expect.fail();
- done();
- nock.cleanAll();
- });
- }, 40); // 40ms
});
+
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+
+ setTimeout(function() {
+ client
+ .getAccessToken()
+ .then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('new_access_token');
+ done();
+ nock.cleanAll();
+ })
+ .catch(function(err) {
+ expect.fail();
+ done();
+ nock.cleanAll();
+ });
+ }, 40); // 40ms
+ });
});
- it('should return cached access token on the second call when cacheTTLInSeconds is not passed', function (done) {
+ it('should return cached access token on the second call when cacheTTLInSeconds is not passed', function(done) {
var config = assign({}, defaultConfig);
config.domain = 'auth0-node-sdk-5.auth0.com';
- config.cacheTTLInSeconds = 10 // 1sec / 40 = 25ms;
+ config.cacheTTLInSeconds = 10; // 1sec / 40 = 25ms;
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -353,33 +338,34 @@ describe('ManagementTokenProvider', function () {
.post('/oauth/token')
.reply(200, {
access_token: 'new_access_token'
- })
-
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
-
- setTimeout(function() {
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
- done();
- nock.cleanAll();
- }).catch(function(err){
- expect.fail();
- done();
- nock.cleanAll();
- });
- }, 40); // 40ms
});
+
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+
+ setTimeout(function() {
+ client
+ .getAccessToken()
+ .then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+ done();
+ nock.cleanAll();
+ })
+ .catch(function(err) {
+ expect.fail();
+ done();
+ nock.cleanAll();
+ });
+ }, 40); // 40ms
+ });
});
- it('should return new access token on the second call when cacheTTLInSeconds is passed', function (done) {
+ it('should return new access token on the second call when cacheTTLInSeconds is passed', function(done) {
var config = assign({}, defaultConfig);
- config.domain = 'auth0-node-sdk-6.auth0.com'
- config.cacheTTLInSeconds = 1 / 40 // 1sec / 40 = 25ms
+ config.domain = 'auth0-node-sdk-6.auth0.com';
+ config.cacheTTLInSeconds = 1 / 40; // 1sec / 40 = 25ms
var client = new ManagementTokenProvider(config);
nock('https://' + config.domain)
@@ -390,37 +376,37 @@ describe('ManagementTokenProvider', function () {
.post('/oauth/token')
.reply(200, {
access_token: 'new_access_token'
- })
-
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('access_token');
-
- setTimeout(function() {
- client.getAccessToken()
- .then(function(access_token){
- expect(access_token).to.exist;
- expect(access_token).to.be.equal('new_access_token');
- done();
- nock.cleanAll();
- }).catch(function(err){
- expect.fail();
- done();
- nock.cleanAll();
- });
- }, 40); // 40ms
});
- });
+ client.getAccessToken().then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('access_token');
+
+ setTimeout(function() {
+ client
+ .getAccessToken()
+ .then(function(access_token) {
+ expect(access_token).to.exist;
+ expect(access_token).to.be.equal('new_access_token');
+ done();
+ nock.cleanAll();
+ })
+ .catch(function(err) {
+ expect.fail();
+ done();
+ nock.cleanAll();
+ });
+ }, 40); // 40ms
+ });
+ });
- it('should pass the correct payload in the body of the oauth/token request with cache enabled', function (done) {
+ it('should pass the correct payload in the body of the oauth/token request with cache enabled', function(done) {
var config = assign({}, defaultConfig);
var client = new ManagementTokenProvider(config);
-
+
nock('https://' + config.domain)
- .post('/oauth/token', function(payload){
- expect(payload).to.exist;
+ .post('/oauth/token', function(payload) {
+ expect(payload).to.exist;
expect(payload.client_id).to.be.equal('clientId');
expect(payload.client_secret).to.be.equal('clientSecret');
expect(payload.grant_type).to.be.equal('client_credentials');
@@ -428,21 +414,20 @@ describe('ManagementTokenProvider', function () {
})
.reply(200);
- client.getAccessToken()
- .then(function(access_token){
- done();
- nock.cleanAll();
- });
+ client.getAccessToken().then(function(access_token) {
+ done();
+ nock.cleanAll();
+ });
});
- it('should pass the correct payload in the body of the oauth/token request with cache disabled', function (done) {
+ it('should pass the correct payload in the body of the oauth/token request with cache disabled', function(done) {
var config = assign({}, defaultConfig);
config.enableCache = false;
var client = new ManagementTokenProvider(config);
-
+
nock('https://' + config.domain)
- .post('/oauth/token', function(payload){
- expect(payload).to.exist;
+ .post('/oauth/token', function(payload) {
+ expect(payload).to.exist;
expect(payload.client_id).to.be.equal('clientId');
expect(payload.client_secret).to.be.equal('clientSecret');
expect(payload.grant_type).to.be.equal('client_credentials');
@@ -450,10 +435,9 @@ describe('ManagementTokenProvider', function () {
})
.reply(200);
- client.getAccessToken()
- .then(function(access_token){
- done();
- nock.cleanAll();
- });
+ client.getAccessToken().then(function(access_token) {
+ done();
+ nock.cleanAll();
+ });
});
});
diff --git a/test/management/resource-servers.tests.js b/test/management/resource-servers.tests.js
index d42fbb073..829a35233 100644
--- a/test/management/resource-servers.tests.js
+++ b/test/management/resource-servers.tests.js
@@ -8,9 +8,8 @@ var API_URL = 'https://tenant.auth0.com';
var ResourceServersManager = require(SRC_DIR + '/management/ResourceServersManager');
var ArgumentError = require('rest-facade').ArgumentError;
-describe('ResourceServersManager', function () {
-
- before(function () {
+describe('ResourceServersManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.resourceServers = new ResourceServersManager({
headers: {
@@ -20,91 +19,76 @@ describe('ResourceServersManager', function () {
});
});
- afterEach(function () {
+ afterEach(function() {
nock.cleanAll();
});
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['get', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.resourceServers[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.resourceServers[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(ResourceServersManager)
- .to.throw(ArgumentError, 'Must provide resource server options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(ResourceServersManager).to.throw(
+ ArgumentError,
+ 'Must provide resource server options'
+ );
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var resourceServerManager = ResourceServersManager.bind(null, {});
- expect(resourceServerManager)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(resourceServerManager).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var resourceServerManager = ResourceServersManager.bind(null, { baseUrl: '' });
- expect(resourceServerManager)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(resourceServerManager).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/resource-servers')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .resourceServers
- .getAll(function () {
+ it('should accept a callback', function(done) {
+ this.resourceServers.getAll(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .resourceServers
+ it('should return a promise if no callback is given', function(done) {
+ this.resourceServers
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/resource-servers')
.reply(500);
- this
- .resourceServers
- .getAll()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.resourceServers.getAll().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -112,272 +96,202 @@ describe('ResourceServersManager', function () {
.get('/resource-servers')
.reply(200, data);
- this
- .resourceServers
- .getAll()
- .then(function (resourceServers) {
- expect(resourceServers)
- .to.be.an.instanceOf(Array);
+ this.resourceServers.getAll().then(function(resourceServers) {
+ expect(resourceServers).to.be.an.instanceOf(Array);
- expect(resourceServers.length)
- .to.equal(data.length);
+ expect(resourceServers.length).to.equal(data.length);
- expect(resourceServers[0].test)
- .to.equal(data[0].test);
+ expect(resourceServers[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/resource-servers', function (done) {
+ it('should perform a GET request to /api/v2/resource-servers', function(done) {
var request = this.request;
- this
- .resourceServers
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/resource-servers')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .resourceServers
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
- done();
- });
+ this.resourceServers.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#get', function () {
+ describe('#get', function() {
var params = { id: 5 };
var data = {
id: params.id,
name: 'Test Resource Server'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/resource-servers/' + data.id)
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .resourceServers
- .get(params, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.resourceServers.get(params, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .resourceServers
+ it('should return a promise if no callback is given', function(done) {
+ this.resourceServers
.get(params)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/resource-servers/' + params.id)
.reply(500);
- this
- .resourceServers
- .get()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.resourceServers.get().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/resource-servers/' + params.id)
.reply(200, data);
- this
- .resourceServers
- .get(params)
- .then(function (connection) {
- expect(connection.id)
- .to.equal(data.id);
+ this.resourceServers.get(params).then(function(connection) {
+ expect(connection.id).to.equal(data.id);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/resource-servers/:id', function (done) {
+ it('should perform a GET request to /api/v2/resource-servers/:id', function(done) {
var request = this.request;
- this
- .resourceServers
- .get(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.get(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/resource-servers')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .resourceServers
- .get()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.get().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
});
-
- describe('#create', function () {
+ describe('#create', function() {
var data = {
name: 'Acme Backend API',
options: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/resource-servers')
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .resourceServers
- .create(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.resourceServers.create(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .resourceServers
+ it('should return a promise if no callback is given', function(done) {
+ this.resourceServers
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/resource-servers')
.reply(500);
- this
- .resourceServers
- .create(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.resourceServers.create(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/resource-servers', function (done) {
+ it('should perform a POST request to /api/v2/resource-servers', function(done) {
var request = this.request;
- this
- .resourceServers
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/resource-servers', data)
.reply(200);
- this
- .resourceServers
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/resource-servers')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .resourceServers
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
+ describe('#update', function() {
var params = { id: 5 };
var data = {
id: 5,
@@ -385,182 +299,133 @@ describe('ResourceServersManager', function () {
options: {}
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.patch('/resource-servers/' + data.id)
.reply(200, data);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .resourceServers
- .update(params, data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.resourceServers.update(params, data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .resourceServers
+ it('should return a promise if no callback is given', function(done) {
+ this.resourceServers
.update(params, data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/resource-servers/' + data.id)
.reply(500);
- this
- .resourceServers
- .update(params, data)
- .catch(function (err) {
- expect(err)
- .to.exist
- .to.be.an.instanceOf(Error);
+ this.resourceServers.update(params, data).catch(function(err) {
+ expect(err).to.exist.to.be.an.instanceOf(Error);
- done();
- });
+ done();
+ });
});
-
- it('should perform a PATCH request to /api/v2/resource-servers/:id', function (done) {
+ it('should perform a PATCH request to /api/v2/resource-servers/:id', function(done) {
var request = this.request;
- this
- .resourceServers
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/resource-servers/' + data.id, data)
.reply(200);
- this
- .resourceServers
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/resource-servers/' + data.id)
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .resourceServers
- .update(params, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.update(params, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/resource-servers/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .resourceServers
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.resourceServers.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .resourceServers
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.resourceServers.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to /resource-servers/' + id, function (done) {
+ it('should perform a DELETE request to /resource-servers/' + id, function(done) {
var request = this.request;
- this
- .resourceServers
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/resource-servers/' + id)
.reply(500);
- this
- .resourceServers
- .delete({ id: id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.resourceServers.delete({ id: id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/resource-servers/' + id)
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .resourceServers
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.resourceServers.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/rules.tests.js b/test/management/rules.tests.js
index 59264b236..dcf900952 100644
--- a/test/management/rules.tests.js
+++ b/test/management/rules.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var RulesManager = require(SRC_DIR + '/management/RulesManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('RulesManager', function () {
- before(function () {
+describe('RulesManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.rules = new RulesManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,88 +16,68 @@ describe('RulesManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['get', 'getAll', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.rules[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.rules[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(RulesManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(RulesManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = RulesManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = RulesManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/rules')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .rules
- .getAll(function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.rules.getAll(function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .rules
+ it('should return a promise if no callback is given', function(done) {
+ this.rules
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/rules')
.reply(500);
- this
- .rules
- .getAll()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.rules.getAll().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -106,56 +85,41 @@ describe('RulesManager', function () {
.get('/rules')
.reply(200, data);
- this
- .rules
- .getAll()
- .then(function (credentials) {
- expect(credentials)
- .to.be.an.instanceOf(Array);
+ this.rules.getAll().then(function(credentials) {
+ expect(credentials).to.be.an.instanceOf(Array);
- expect(credentials.length)
- .to.equal(data.length);
+ expect(credentials.length).to.equal(data.length);
- expect(credentials[0].test)
- .to.equal(data[0].test);
+ expect(credentials[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/rules', function (done) {
+ it('should perform a GET request to /api/v2/rules', function(done) {
var request = this.request;
- this
- .rules
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.rules.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/rules')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .rules
- .getAll()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.rules.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var params = {
@@ -165,90 +129,69 @@ describe('RulesManager', function () {
var request = nock(API_URL)
.get('/rules')
.query(params)
- .reply(200)
+ .reply(200);
- this
- .rules
- .getAll(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.getAll(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#get', function () {
- beforeEach(function () {
+ describe('#get', function() {
+ beforeEach(function() {
this.data = {
id: 5,
name: 'Test rule',
enabled: true,
- script: 'function (user, contest, callback) { console.log(\'Test\'); }',
+ script: "function (user, contest, callback) { console.log('Test'); }",
stage: 'login_success'
};
this.request = nock(API_URL)
.get('/rules/' + this.data.id)
.reply(200, this.data);
- })
-
+ });
- it('should accept a callback', function (done) {
+ it('should accept a callback', function(done) {
var params = { id: this.data.id };
- this
- .rules
- .get(params, done.bind(null, null));
+ this.rules.get(params, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .rules
+ it('should return a promise if no callback is given', function(done) {
+ this.rules
.get({ id: this.data.id })
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to /api/v2/rules/5', function (done) {
+ it('should perform a POST request to /api/v2/rules/5', function(done) {
var request = this.request;
- this
- .rules
- .get({ id: this.data.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.get({ id: this.data.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/rules/' + this.data.id)
.reply(500);
- this
- .rules
- .get({ id: this.data.id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.rules.get({ id: this.data.id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -256,129 +199,98 @@ describe('RulesManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .rules
- .get({ id: this.data.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.get({ id: this.data.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#create', function () {
+ describe('#create', function() {
var data = {
id: 5,
name: 'Test rule',
enabled: true,
- script: 'function (user, contest, callback) { console.log(\'Test\'); }',
+ script: "function (user, contest, callback) { console.log('Test'); }",
stage: 'login_success'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/rules')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .rules
- .create(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.rules.create(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .rules
+ it('should return a promise if no callback is given', function(done) {
+ this.rules
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/rules')
.reply(500);
- this
- .rules
- .create(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.rules.create(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/rules', function (done) {
+ it('should perform a POST request to /api/v2/rules', function(done) {
var request = this.request;
- this
- .rules
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/rules', data)
.reply(200);
- this
- .rules
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/rules')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .rules
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
- beforeEach(function () {
+ describe('#update', function() {
+ beforeEach(function() {
this.data = { id: 5 };
this.request = nock(API_URL)
@@ -386,154 +298,110 @@ describe('RulesManager', function () {
.reply(200, this.data);
});
-
- it('should accept a callback', function (done) {
- this
- .rules
- .update({ id: 5 }, {}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.rules.update({ id: 5 }, {}, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .rules
+ it('should return a promise if no callback is given', function(done) {
+ this.rules
.update({ id: 5 }, {})
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a PATCH request to /api/v2/rules/5', function (done) {
+ it('should perform a PATCH request to /api/v2/rules/5', function(done) {
var request = this.request;
- this
- .rules
- .update({ id: 5 }, {})
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.update({ id: 5 }, {}).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new data in the body of the request', function (done) {
+ it('should include the new data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/rules/' + this.data.id, this.data)
.reply(200);
- this
- .rules
- .update({ id: 5 }, this.data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.update({ id: 5 }, this.data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/rules/' + this.data.id)
.reply(500);
- this
- .rules
- .update({ id: this.data.id }, this.data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.rules.update({ id: this.data.id }, this.data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 5;
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/rules/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .rules
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.rules.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .rules
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.rules.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a delete request to /rules/' + id, function (done) {
+ it('should perform a delete request to /rules/' + id, function(done) {
var request = this.request;
- this
- .rules
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/rules/' + id)
.reply(500);
- this
- .rules
- .delete({ id: id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.rules.delete({ id: id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/rules/' + id)
.matchHeader('authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .rules
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.rules.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
});
diff --git a/test/management/stats.tests.js b/test/management/stats.tests.js
index e2074ab08..eac10c623 100644
--- a/test/management/stats.tests.js
+++ b/test/management/stats.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenant.auth0.com';
var StatsManager = require(SRC_DIR + '/management/StatsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('StatsManager', function () {
- before(function () {
+describe('StatsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.stats = new StatsManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,88 +16,68 @@ describe('StatsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['getActiveUsersCount', 'getDaily'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.stats[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.stats[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(StatsManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(StatsManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var client = StatsManager.bind(null, {});
- expect(client)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var client = StatsManager.bind(null, { baseUrl: '' });
- expect(client)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(client).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getDaily', function () {
- beforeEach(function () {
+ describe('#getDaily', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/stats/daily')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .stats
- .getDaily({}, function () {
+ it('should accept a callback', function(done) {
+ this.stats.getDaily({}, function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .stats
+ it('should return a promise if no callback is given', function(done) {
+ this.stats
.getDaily()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/stats/daily')
.reply(500);
- this
- .stats
- .getDaily()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.stats.getDaily().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -106,56 +85,41 @@ describe('StatsManager', function () {
.get('/stats/daily')
.reply(200, data);
- this
- .stats
- .getDaily()
- .then(function (blacklistedTokens) {
- expect(blacklistedTokens)
- .to.be.an.instanceOf(Array);
+ this.stats.getDaily().then(function(blacklistedTokens) {
+ expect(blacklistedTokens).to.be.an.instanceOf(Array);
- expect(blacklistedTokens.length)
- .to.equal(data.length);
+ expect(blacklistedTokens.length).to.equal(data.length);
- expect(blacklistedTokens[0].test)
- .to.equal(data[0].test);
+ expect(blacklistedTokens[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/stats/daily', function (done) {
+ it('should perform a GET request to /api/v2/stats/daily', function(done) {
var request = this.request;
- this
- .stats
- .getDaily()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.stats.getDaily().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/stats/daily')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .stats
- .getDaily()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.stats.getDaily().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -164,110 +128,83 @@ describe('StatsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
-
- this
- .stats
- .getDaily({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ .reply(200);
+
+ this.stats.getDaily({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#getActiveUsersCount', function () {
- beforeEach(function () {
+ describe('#getActiveUsersCount', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/stats/active-users')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .stats
- .getActiveUsersCount(function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.stats.getActiveUsersCount(function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .stats
+ it('should return a promise if no callback is given', function(done) {
+ this.stats
.getActiveUsersCount()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/stats/active-users')
.reply(500);
- this
- .stats
- .getActiveUsersCount()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.stats.getActiveUsersCount().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/stats/active-users', function (done) {
+ it('should perform a GET request to /api/v2/stats/active-users', function(done) {
var request = this.request;
- this
- .stats
- .getActiveUsersCount()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.stats.getActiveUsersCount().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the token data in the body of the request', function (done) {
+ it('should pass the token data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/stats/active-users')
.reply(200);
- this
- .stats
- .getActiveUsersCount()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.stats.getActiveUsersCount().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/stats/active-users')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .stats
- .getActiveUsersCount()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.stats.getActiveUsersCount().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
});
diff --git a/test/management/tenant.tests.js b/test/management/tenant.tests.js
index 365012df6..0b541a6a4 100644
--- a/test/management/tenant.tests.js
+++ b/test/management/tenant.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenants.auth0.com';
var TenantManager = require(SRC_DIR + '/management/TenantManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('TenantManager', function () {
- before(function () {
+describe('TenantManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.tenant = new TenantManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,88 +16,68 @@ describe('TenantManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['updateSettings', 'getSettings'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.tenant[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.tenant[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(TenantManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(TenantManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var manager = TenantManager.bind(null, {});
- expect(manager)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(manager).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var manager = TenantManager.bind(null, { baseUrl: '' });
- expect(manager)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(manager).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getSettings', function () {
- beforeEach(function () {
+ describe('#getSettings', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/tenants/settings')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .tenant
- .getSettings(function () {
+ it('should accept a callback', function(done) {
+ this.tenant.getSettings(function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .tenant
+ it('should return a promise if no callback is given', function(done) {
+ this.tenant
.getSettings()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/tenants/settings')
.reply(500);
- this
- .tenant
- .getSettings()
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.tenant.getSettings().catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -106,56 +85,41 @@ describe('TenantManager', function () {
.get('/tenants/settings')
.reply(200, data);
- this
- .tenant
- .getSettings()
- .then(function (blacklistedTokens) {
- expect(blacklistedTokens)
- .to.be.an.instanceOf(Array);
+ this.tenant.getSettings().then(function(blacklistedTokens) {
+ expect(blacklistedTokens).to.be.an.instanceOf(Array);
- expect(blacklistedTokens.length)
- .to.equal(data.length);
+ expect(blacklistedTokens.length).to.equal(data.length);
- expect(blacklistedTokens[0].test)
- .to.equal(data[0].test);
+ expect(blacklistedTokens[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/tenants/settings', function (done) {
+ it('should perform a GET request to /api/v2/tenants/settings', function(done) {
var request = this.request;
- this
- .tenant
- .getSettings()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tenant.getSettings().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/tenants/settings')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .tenant
- .getSettings()
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tenant.getSettings().then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -164,114 +128,87 @@ describe('TenantManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
-
- this
- .tenant
- .getSettings({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ .reply(200);
+
+ this.tenant.getSettings({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
- describe('#updateSettings', function () {
+ describe('#updateSettings', function() {
var data = {
friendly_name: 'Test name'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.patch('/tenants/settings')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .tenant
- .updateSettings(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.tenant.updateSettings(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .tenant
+ it('should return a promise if no callback is given', function(done) {
+ this.tenant
.updateSettings(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/tenants/settings')
.reply(500);
- this
- .tenant
- .updateSettings(data)
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.tenant.updateSettings(data).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a PATCH request to /api/v2/tenants/settings', function (done) {
+ it('should perform a PATCH request to /api/v2/tenants/settings', function(done) {
var request = this.request;
- this
- .tenant
- .updateSettings(data)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tenant.updateSettings(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/tenants/settings', data)
.reply(200);
- this
- .tenant
- .updateSettings(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.tenant.updateSettings(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/tenants/settings')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .tenant
- .updateSettings(data)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tenant.updateSettings(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
});
diff --git a/test/management/tickets.tests.js b/test/management/tickets.tests.js
index 904f1183e..5185844bd 100644
--- a/test/management/tickets.tests.js
+++ b/test/management/tickets.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenants.auth0.com';
var TicketsManager = require(SRC_DIR + '/management/TicketsManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('TicketsManager', function () {
- before(function () {
+describe('TicketsManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.tickets = new TicketsManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,124 +16,96 @@ describe('TicketsManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = ['changePassword', 'verifyEmail'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.tickets[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.tickets[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(TicketsManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(TicketsManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var manager = TicketsManager.bind(null, {});
- expect(manager)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(manager).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var manager = TicketsManager.bind(null, { baseUrl: '' });
- expect(manager)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(manager).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#verifyEmail', function () {
+ describe('#verifyEmail', function() {
var data = {
- result_url: "http://myapp.com/callback",
- user_id: ""
+ result_url: 'http://myapp.com/callback',
+ user_id: ''
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/tickets/email-verification')
.reply(200);
- })
-
+ });
- it('should accept a callback', function (done) {
- this
- .tickets
- .verifyEmail(data, function () {
+ it('should accept a callback', function(done) {
+ this.tickets.verifyEmail(data, function() {
done();
});
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .tickets
+ it('should return a promise if no callback is given', function(done) {
+ this.tickets
.verifyEmail(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('tickets/email-verification')
.reply(500);
- this
- .tickets
- .verifyEmail(data)
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.tickets.verifyEmail(data).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2tickets/email-verification', function (done) {
+ it('should perform a POST request to /api/v2tickets/email-verification', function(done) {
var request = this.request;
- this
- .tickets
- .verifyEmail(data)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tickets.verifyEmail(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/tickets/email-verification')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
-
- this
- .tickets
- .verifyEmail({})
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
- });
+ .reply(200);
+ this.tickets.verifyEmail({}).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
+ });
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -143,121 +114,92 @@ describe('TicketsManager', function () {
include_fields: true,
fields: 'test'
})
- .reply(200)
+ .reply(200);
- this
- .tickets
- .verifyEmail({ include_fields: true, fields: 'test' })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.tickets.verifyEmail({ include_fields: true, fields: 'test' }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#changePassword', function () {
+ describe('#changePassword', function() {
var data = {
- result_url: "http://myapp.com/callback",
- user_id: "",
- new_password: "secret",
- connection_id: "con_0000000000000001",
- email: ""
+ result_url: 'http://myapp.com/callback',
+ user_id: '',
+ new_password: 'secret',
+ connection_id: 'con_0000000000000001',
+ email: ''
};
-
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/tickets/password-change')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .tickets
- .changePassword(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.tickets.changePassword(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .tickets
+ it('should return a promise if no callback is given', function(done) {
+ this.tickets
.changePassword(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/tickets/email-verification')
.reply(500);
- this
- .tickets
- .changePassword(data)
- .catch(function (err) {
- expect(err).to.exist;
- done();
- });
+ this.tickets.changePassword(data).catch(function(err) {
+ expect(err).to.exist;
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2tickets/email-verification', function (done) {
+ it('should perform a POST request to /api/v2tickets/email-verification', function(done) {
var request = this.request;
- this
- .tickets
- .changePassword(data)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tickets.changePassword(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/tickets/password-change', data)
.reply(200);
- this
- .tickets
- .changePassword(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.tickets.changePassword(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/tickets/password-change')
.matchHeader('Authorization', 'Bearer ' + this.token)
- .reply(200)
+ .reply(200);
- this
- .tickets
- .changePassword(data)
- .then(function () {
- expect(request.isDone()).to.be.true;
- done();
- });
+ this.tickets.changePassword(data).then(function() {
+ expect(request.isDone()).to.be.true;
+ done();
+ });
});
});
-
});
diff --git a/test/management/users.tests.js b/test/management/users.tests.js
index 1147f319a..33ede4485 100644
--- a/test/management/users.tests.js
+++ b/test/management/users.tests.js
@@ -7,9 +7,8 @@ var API_URL = 'https://tenants.auth0.com';
var UsersManager = require(SRC_DIR + '/management/UsersManager');
var ArgumentError = require('rest-facade').ArgumentError;
-
-describe('UsersManager', function () {
- before(function () {
+describe('UsersManager', function() {
+ before(function() {
this.token = 'TOKEN';
this.users = new UsersManager({
headers: { authorization: 'Bearer ' + this.token },
@@ -17,8 +16,7 @@ describe('UsersManager', function () {
});
});
-
- describe('instance', function () {
+ describe('instance', function() {
var methods = [
'get',
'getAll',
@@ -35,86 +33,66 @@ describe('UsersManager', function () {
'getGuardianEnrollments'
];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
- expect(this.users[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(this.users[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
-
- describe('#constructor', function () {
- it('should error when no options are provided', function () {
- expect(UsersManager)
- .to.throw(ArgumentError, 'Must provide manager options');
+ describe('#constructor', function() {
+ it('should error when no options are provided', function() {
+ expect(UsersManager).to.throw(ArgumentError, 'Must provide manager options');
});
-
- it('should throw an error when no base URL is provided', function () {
+ it('should throw an error when no base URL is provided', function() {
var manager = UsersManager.bind(null, {});
- expect(manager)
- .to.throw(ArgumentError, 'Must provide a base URL for the API');
+ expect(manager).to.throw(ArgumentError, 'Must provide a base URL for the API');
});
-
- it('should throw an error when the base URL is invalid', function () {
+ it('should throw an error when the base URL is invalid', function() {
var manager = UsersManager.bind(null, { baseUrl: '' });
- expect(manager)
- .to.throw(ArgumentError, 'The provided base URL is invalid');
+ expect(manager).to.throw(ArgumentError, 'The provided base URL is invalid');
});
});
-
- describe('#getAll', function () {
- beforeEach(function () {
+ describe('#getAll', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/users')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .users
- .getAll(function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.users.getAll(function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.getAll()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/users')
.reply(500);
- this
- .users
- .getAll()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.getAll().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -122,40 +100,28 @@ describe('UsersManager', function () {
.get('/users')
.reply(200, data);
- this
- .users
- .getAll()
- .then(function (users) {
- expect(users)
- .to.be.an.instanceOf(Array);
+ this.users.getAll().then(function(users) {
+ expect(users).to.be.an.instanceOf(Array);
- expect(users.length)
- .to.equal(data.length);
+ expect(users.length).to.equal(data.length);
- expect(users[0].test)
- .to.equal(data[0].test);
+ expect(users[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/users', function (done) {
+ it('should perform a GET request to /api/v2/users', function(done) {
var request = this.request;
- this
- .users
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -163,19 +129,14 @@ describe('UsersManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .getAll()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getAll().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var params = {
@@ -187,64 +148,49 @@ describe('UsersManager', function () {
.query(params)
.reply(200);
- this
- .users
- .getAll(params)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getAll(params).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
- describe('#getByEmail', function () {
- beforeEach(function () {
+ describe('#getByEmail', function() {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/users-by-email')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .users
- .getByEmail('someone@example.com', function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.users.getByEmail('someone@example.com', function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.getByEmail()
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/users-by-email')
.reply(500);
- this
- .users
- .getByEmail()
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.getByEmail().catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var data = [{ test: true }];
@@ -252,40 +198,28 @@ describe('UsersManager', function () {
.get('/users-by-email')
.reply(200, data);
- this
- .users
- .getByEmail()
- .then(function (users) {
- expect(users)
- .to.be.an.instanceOf(Array);
+ this.users.getByEmail().then(function(users) {
+ expect(users).to.be.an.instanceOf(Array);
- expect(users.length)
- .to.equal(data.length);
+ expect(users.length).to.equal(data.length);
- expect(users[0].test)
- .to.equal(data[0].test);
+ expect(users[0].test).to.equal(data[0].test);
- done();
- });
+ done();
+ });
});
-
- it('should perform a GET request to /api/v2/users-by-email', function (done) {
+ it('should perform a GET request to /api/v2/users-by-email', function(done) {
var request = this.request;
- this
- .users
- .getByEmail()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getByEmail().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -293,19 +227,14 @@ describe('UsersManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .getByEmail()
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getByEmail().then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass an email in as a query string', function (done) {
+ it('should pass an email in as a query string', function(done) {
nock.cleanAll();
var params = {
@@ -316,89 +245,67 @@ describe('UsersManager', function () {
.query(params)
.reply(200);
- this
- .users
- .getByEmail(params.email)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getByEmail(params.email).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
-
- describe('#get', function () {
- beforeEach(function () {
+ describe('#get', function() {
+ beforeEach(function() {
this.data = {
id: 5,
name: 'Test rule',
enabled: true,
- script: 'function (user, contest, callback) { console.log(\'Test\'); }',
+ script: "function (user, contest, callback) { console.log('Test'); }",
stage: 'login_success'
};
this.request = nock(API_URL)
.get('/users/' + this.data.id)
.reply(200, this.data);
- })
-
+ });
- it('should accept a callback', function (done) {
+ it('should accept a callback', function(done) {
var params = { id: this.data.id };
- this
- .users
- .get(params, done.bind(null, null));
+ this.users.get(params, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.get({ id: this.data.id })
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a POST request to /api/v2/users/5', function (done) {
+ it('should perform a POST request to /api/v2/users/5', function(done) {
var request = this.request;
- this
- .users
- .get({ id: this.data.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.get({ id: this.data.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/users/' + this.data.id)
.reply(500);
- this
- .users
- .get({ id: this.data.id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.get({ id: this.data.id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -406,107 +313,81 @@ describe('UsersManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .get({ id: this.data.id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.get({ id: this.data.id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#create', function () {
+ describe('#create', function() {
var data = {
id: 5,
name: 'Test rule',
enabled: true,
- script: 'function (user, contest, callback) { console.log(\'Test\'); }',
+ script: "function (user, contest, callback) { console.log('Test'); }",
stage: 'login_success'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/users')
.reply(200);
- })
-
-
- it('should accept a callback', function (done) {
- this
- .users
- .create(data, function () {
- done();
- });
});
+ it('should accept a callback', function(done) {
+ this.users.create(data, function() {
+ done();
+ });
+ });
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.create(data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/users')
.reply(500);
- this
- .users
- .create(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.create(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/users', function (done) {
+ it('should perform a POST request to /api/v2/users', function(done) {
var request = this.request;
- this
- .users
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/users', data)
.reply(200);
- this
- .users
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -514,21 +395,16 @@ describe('UsersManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .create(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.create(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#update', function () {
- beforeEach(function () {
+ describe('#update', function() {
+ beforeEach(function() {
this.data = { id: 5 };
this.request = nock(API_URL)
@@ -536,137 +412,98 @@ describe('UsersManager', function () {
.reply(200, this.data);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .update({ id: 5 }, {}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.update({ id: 5 }, {}, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.update({ id: 5 }, {})
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a PATCH request to /api/v2/users/5', function (done) {
+ it('should perform a PATCH request to /api/v2/users/5', function(done) {
var request = this.request;
- this
- .users
- .update({ id: 5 }, {})
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.update({ id: 5 }, {}).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the new data in the body of the request', function (done) {
+ it('should include the new data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/users/' + this.data.id, this.data)
.reply(200);
- this
- .users
- .update({ id: 5 }, this.data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.update({ id: 5 }, this.data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/users/' + this.data.id)
.reply(500);
- this
- .users
- .update({ id: this.data.id }, this.data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.update({ id: this.data.id }, this.data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
});
-
- describe('#delete', function () {
+ describe('#delete', function() {
var id = 'USER_5';
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete('/users/' + id)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .delete({ id: id }, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.delete({ id: id }, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .users
- .delete({ id: id })
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.users.delete({ id: id }).then(done.bind(null, null));
});
-
- it('should perform a delete request to /users/' + id, function (done) {
+ it('should perform a delete request to /users/' + id, function(done) {
var request = this.request;
- this
- .users
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete('/users/' + id)
.reply(500);
- this
- .users
- .delete({ id: id })
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.delete({ id: id }).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -674,118 +511,93 @@ describe('UsersManager', function () {
.matchHeader('authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .delete({ id: id })
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.delete({ id: id }).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#link', function () {
+ describe('#link', function() {
var userId = 'USER_ID';
var data = {
- provider: "twitter",
- user_id: "191919191919191",
+ provider: 'twitter',
+ user_id: '191919191919191'
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.post('/users/' + userId + '/identities')
.reply(200);
});
- it('should validate empty userId', function () {
+ it('should validate empty userId', function() {
var _this = this;
expect(function() {
- _this.users.link(null, data, function () {});
+ _this.users.link(null, data, function() {});
}).to.throw('The userId cannot be null or undefined');
});
- it('should validate non-string userId', function () {
+ it('should validate non-string userId', function() {
var _this = this;
expect(function() {
- _this.users.link(123, data, function () {});
+ _this.users.link(123, data, function() {});
}).to.throw('The userId has to be a string');
});
- it('should accept a callback', function (done) {
- this
- .users
- .link(userId, data, function () {
- done();
- });
+ it('should accept a callback', function(done) {
+ this.users.link(userId, data, function() {
+ done();
+ });
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.link(userId, data)
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/users/' + userId + '/identities')
.reply(500);
- this
- .users
- .link(userId, data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.link(userId, data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should perform a POST request to /api/v2/users', function (done) {
+ it('should perform a POST request to /api/v2/users', function(done) {
var request = this.request;
- this
- .users
- .link(userId, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.link(userId, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass the data in the body of the request', function (done) {
+ it('should pass the data in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.post('/users/' + userId + '/identities', data)
.reply(200);
- this
- .users
- .link(userId, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.link(userId, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the Authorization header', function (done) {
+ it('should include the token in the Authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -793,87 +605,61 @@ describe('UsersManager', function () {
.matchHeader('Authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .link(userId, data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.link(userId, data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#unlink', function () {
+ describe('#unlink', function() {
var data = {
id: 'u1',
user_id: 'u2',
provider: 'auth0'
};
- var url = (
- '/users/' + data.id + '/identities/' + data.provider + '/' + data.user_id
- );
+ var url = '/users/' + data.id + '/identities/' + data.provider + '/' + data.user_id;
-
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete(url)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .unlink(data, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.unlink(data, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .users
- .unlink(data)
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.users.unlink(data).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to ' + url, function (done) {
+ it('should perform a DELETE request to ' + url, function(done) {
var request = this.request;
- this
- .users
- .unlink(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.unlink(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete(url)
.reply(500);
- this
- .users
- .unlink(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.unlink(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -881,84 +667,60 @@ describe('UsersManager', function () {
.matchHeader('authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .unlink(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.unlink(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#deleteMultifactorProvider', function () {
+ describe('#deleteMultifactorProvider', function() {
var data = {
id: 'u1',
provider: 'auth0'
};
var url = '/users/' + data.id + '/multifactor/' + data.provider;
-
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.delete(url)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .deleteMultifactorProvider(data, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.deleteMultifactorProvider(data, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .users
- .deleteMultifactorProvider(data)
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.users.deleteMultifactorProvider(data).then(done.bind(null, null));
});
-
- it('should perform a DELETE request to ' + url, function (done) {
+ it('should perform a DELETE request to ' + url, function(done) {
var request = this.request;
- this
- .users
- .deleteMultifactorProvider(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.deleteMultifactorProvider(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.delete(url)
.reply(500);
- this
- .users
- .deleteMultifactorProvider(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.deleteMultifactorProvider(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -966,21 +728,16 @@ describe('UsersManager', function () {
.matchHeader('authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .deleteMultifactorProvider(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.deleteMultifactorProvider(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
-
- describe('#updateUserMetadata', function () {
- beforeEach(function () {
+ describe('#updateUserMetadata', function() {
+ beforeEach(function() {
this.data = {
id: 5,
foo: 'bar',
@@ -992,39 +749,28 @@ describe('UsersManager', function () {
.reply(200, this.data);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .updateUserMetadata({ id: 5 }, {}, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.updateUserMetadata({ id: 5 }, {}, done.bind(null, null));
});
-
- it('should return a promise if no callback is given', function (done) {
- this
- .users
+ it('should return a promise if no callback is given', function(done) {
+ this.users
.updateUserMetadata({ id: 5 }, {})
.then(done.bind(null, null))
.catch(done.bind(null, null));
});
-
- it('should perform a PATCH request to /api/v2/users/5', function (done) {
+ it('should perform a PATCH request to /api/v2/users/5', function(done) {
var request = this.request;
- this
- .users
- .updateUserMetadata({ id: 5 }, {})
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.updateUserMetadata({ id: 5 }, {}).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should include the metadata in the body of the request', function (done) {
+ it('should include the metadata in the body of the request', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -1033,100 +779,76 @@ describe('UsersManager', function () {
})
.reply(200);
- this
- .users
+ this.users
.updateUserMetadata({ id: 5 }, this.data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ .then(function() {
+ expect(request.isDone()).to.be.true;
done();
})
.catch(done);
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.patch('/users/' + this.data.id)
.reply(500);
- this
- .users
- .updateUserMetadata({ id: this.data.id }, this.data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.updateUserMetadata({ id: this.data.id }, this.data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
});
- describe('#logs', function () {
+ describe('#logs', function() {
var data = {
id: 'user_id'
};
- var url = (
- '/users/' + data.id + '/logs'
- );
+ var url = '/users/' + data.id + '/logs';
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get(url)
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .logs(data, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.logs(data, done.bind(null, null));
});
- it('should return a promise when no callback is given', function (done) {
- this
- .users
- .logs(data)
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.users.logs(data).then(done.bind(null, null));
});
- it('should perform a GET request to ' + url, function (done) {
+ it('should perform a GET request to ' + url, function(done) {
var request = this.request;
- this
- .users
- .logs(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.logs(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get(url)
.reply(500);
- this
- .users
- .logs(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.logs(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -1134,18 +856,14 @@ describe('UsersManager', function () {
.matchHeader('authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .logs(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.logs(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
- it('should pass the body of the response to the "then" handler', function (done) {
+ it('should pass the body of the response to the "then" handler', function(done) {
nock.cleanAll();
var response = [{ test: true }];
@@ -1153,24 +871,18 @@ describe('UsersManager', function () {
.get(url)
.reply(200, response);
- this
- .users
- .logs(data)
- .then(function (logs) {
- expect(logs)
- .to.be.an.instanceOf(Array);
+ this.users.logs(data).then(function(logs) {
+ expect(logs).to.be.an.instanceOf(Array);
- expect(logs.length)
- .to.equal(response.length);
+ expect(logs.length).to.equal(response.length);
- expect(logs[0].test)
- .to.equal(response[0].test);
+ expect(logs[0].test).to.equal(response[0].test);
- done();
- });
+ done();
+ });
});
- it('should pass the parameters in the query-string', function (done) {
+ it('should pass the parameters in the query-string', function(done) {
nock.cleanAll();
var params = {
@@ -1185,79 +897,58 @@ describe('UsersManager', function () {
data.page = params.page;
data.per_page = params.per_page;
- this
- .users
- .logs(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.logs(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
- describe('#getGuardianEnrollments', function () {
+ describe('#getGuardianEnrollments', function() {
var data = {
- id: 5,
+ id: 5
};
- beforeEach(function () {
+ beforeEach(function() {
this.request = nock(API_URL)
.get('/users/' + data.id + '/enrollments')
.reply(200);
});
-
- it('should accept a callback', function (done) {
- this
- .users
- .getGuardianEnrollments(data, done.bind(null, null));
+ it('should accept a callback', function(done) {
+ this.users.getGuardianEnrollments(data, done.bind(null, null));
});
-
- it('should return a promise when no callback is given', function (done) {
- this
- .users
- .getGuardianEnrollments(data)
- .then(done.bind(null, null));
+ it('should return a promise when no callback is given', function(done) {
+ this.users.getGuardianEnrollments(data).then(done.bind(null, null));
});
- it('should perform a GET request to /api/v2/users/5/enrollments', function (done) {
+ it('should perform a GET request to /api/v2/users/5/enrollments', function(done) {
var request = this.request;
- this
- .users
- .getGuardianEnrollments(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getGuardianEnrollments(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
-
- it('should pass any errors to the promise catch handler', function (done) {
+ it('should pass any errors to the promise catch handler', function(done) {
nock.cleanAll();
var request = nock(API_URL)
.get('/users/' + data.id + '/enrollments')
.reply(500);
- this
- .users
- .getGuardianEnrollments(data)
- .catch(function (err) {
- expect(err)
- .to.exist;
+ this.users.getGuardianEnrollments(data).catch(function(err) {
+ expect(err).to.exist;
- done();
- });
+ done();
+ });
});
-
- it('should include the token in the authorization header', function (done) {
+ it('should include the token in the authorization header', function(done) {
nock.cleanAll();
var request = nock(API_URL)
@@ -1265,15 +956,11 @@ describe('UsersManager', function () {
.matchHeader('authorization', 'Bearer ' + this.token)
.reply(200);
- this
- .users
- .getGuardianEnrollments(data)
- .then(function () {
- expect(request.isDone())
- .to.be.true;
+ this.users.getGuardianEnrollments(data).then(function() {
+ expect(request.isDone()).to.be.true;
- done();
- });
+ done();
+ });
});
});
});
diff --git a/test/retry-rest-client.tests.js b/test/retry-rest-client.tests.js
index 5993b7b44..e6e7ec366 100644
--- a/test/retry-rest-client.tests.js
+++ b/test/retry-rest-client.tests.js
@@ -3,356 +3,368 @@ var nock = require('nock');
var Promise = require('bluebird');
var ArgumentError = require('rest-facade').ArgumentError;
-var RestClient = require('rest-facade').Client;;
+var RestClient = require('rest-facade').Client;
var RetryRestClient = require('../src/RetryRestClient');
var API_URL = 'https://tenant.auth0.com';
-describe('RetryRestClient', function () {
- before(function () {
+describe('RetryRestClient', function() {
+ before(function() {
this.restClient = new RestClient(API_URL);
});
- it('should raise an error when no RestClient is provided', function () {
- expect(RetryRestClient)
- .to.throw(ArgumentError, 'Must provide RestClient');
+ it('should raise an error when no RestClient is provided', function() {
+ expect(RetryRestClient).to.throw(ArgumentError, 'Must provide RestClient');
});
- it('should raise an error when enabled is not of type boolean', function () {
+ it('should raise an error when enabled is not of type boolean', function() {
var options = { enabled: {} };
var client = RetryRestClient.bind(null, {}, options);
- expect(client)
- .to.throw(ArgumentError, 'Must provide enabled boolean value');
+ expect(client).to.throw(ArgumentError, 'Must provide enabled boolean value');
});
- it('should raise an error when maxRetries is negative', function () {
+ it('should raise an error when maxRetries is negative', function() {
var options = { maxRetries: -1 };
var client = RetryRestClient.bind(null, {}, options);
- expect(client)
- .to.throw(ArgumentError, 'Must provide maxRetries as a positive number');
+ expect(client).to.throw(ArgumentError, 'Must provide maxRetries as a positive number');
});
- describe('instance', function () {
+ describe('instance', function() {
var client = new RetryRestClient(new RestClient(API_URL));
var methods = ['getAll', 'get', 'create', 'update', 'delete'];
- methods.forEach(function (method) {
- it('should have a ' + method + ' method', function () {
-
- expect(client[method])
- .to.exist
- .to.be.an.instanceOf(Function);
- })
+ methods.forEach(function(method) {
+ it('should have a ' + method + ' method', function() {
+ expect(client[method]).to.exist.to.be.an.instanceOf(Function);
+ });
});
});
- it('should pass data to callback when provided', function(done){
+ it('should pass data to callback when provided', function(done) {
nock(API_URL)
.get('/')
.reply(200, { success: true });
var client = new RetryRestClient(this.restClient);
- client.getAll(function(err, data){
+ client.getAll(function(err, data) {
expect(err).to.null;
expect(data.success).to.be.true;
done();
});
});
- it('should return promise for successful request when no callback is provided', function(done){
+ it('should return promise for successful request when no callback is provided', function(done) {
nock(API_URL)
.get('/')
.reply(200, { success: true });
var client = new RetryRestClient(this.restClient);
- client.getAll()
- .then(function(data){
- expect(data.success).to.be.true;
- done();
- });
+ client.getAll().then(function(data) {
+ expect(data.success).to.be.true;
+ done();
+ });
});
- it('should pass err to callback when provided', function(done){
+ it('should pass err to callback when provided', function(done) {
nock(API_URL)
.get('/')
.reply(500);
var client = new RetryRestClient(this.restClient);
- client.getAll(function(err){
+ client.getAll(function(err) {
expect(err).to.not.null;
expect(err.statusCode).to.be.equal(500);
done();
});
});
- it('should return promise for failed request when no callback is provided', function(done){
+ it('should return promise for failed request when no callback is provided', function(done) {
nock(API_URL)
.get('/')
.reply(500);
var client = new RetryRestClient(this.restClient);
- client.getAll()
- .catch(function(err){
- expect(err).to.not.null;
- expect(err.statusCode).to.be.equal(500);
- done();
- });
+ client.getAll().catch(function(err) {
+ expect(err).to.not.null;
+ expect(err.statusCode).to.be.equal(500);
+ done();
+ });
});
- it('should retry once when an error is returned', function(done){
+ it('should retry once when an error is returned', function(done) {
var self = this;
var timesCalled = 0;
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
timesCalled += 1;
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": "1508253300",
- })
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': '1508253300'
+ }
+ )
.get('/')
- .reply(200, { success: true });;
+ .reply(200, { success: true });
var client = new RetryRestClient(restClientSpy);
- client.getAll()
- .then(function(data) {
- expect(data.success).to.be.true;
- expect(timesCalled).to.be.equal(2);
- done();
- });
+ client.getAll().then(function(data) {
+ expect(data.success).to.be.true;
+ expect(timesCalled).to.be.equal(2);
+ done();
+ });
});
- it('should try 4 times when request fails 3 times', function(done){
+ it('should try 4 times when request fails 3 times', function(done) {
var self = this;
var timesCalled = 0;
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
timesCalled += 1;
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
.times(3)
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": "1508253300",
- })
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': '1508253300'
+ }
+ )
.get('/')
- .reply(200, { success: true });;
+ .reply(200, { success: true });
var client = new RetryRestClient(restClientSpy);
- client.getAll()
- .then(function(data) {
- expect(data.success).to.be.true;
- expect(timesCalled).to.be.equal(4);
- done();
- });
+ client.getAll().then(function(data) {
+ expect(data.success).to.be.true;
+ expect(timesCalled).to.be.equal(4);
+ done();
+ });
});
- it('should retry 2 times and fail when maxRetries is exceeded with no delay time', function(done){
+ it('should retry 2 times and fail when maxRetries is exceeded with no delay time', function(done) {
var self = this;
var timesCalled = 0;
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
timesCalled += 1;
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
.times(4)
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": (new Date().getTime() - 10) / 1000 // past.
- });
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': (new Date().getTime() - 10) / 1000 // past.
+ }
+ );
var client = new RetryRestClient(restClientSpy, { maxRetries: 3 });
- client.getAll()
- .catch(function(err) {
- expect(err).to.not.null;
- expect(timesCalled).to.be.equal(4); // Initial call + 3 retires.
- done();
- });
+ client.getAll().catch(function(err) {
+ expect(err).to.not.null;
+ expect(timesCalled).to.be.equal(4); // Initial call + 3 retires.
+ done();
+ });
});
- it('should retry 2 times and fail when maxRetries is exceeded with delay time', function(done){
+ it('should retry 2 times and fail when maxRetries is exceeded with delay time', function(done) {
var self = this;
var timesCalled = 0;
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
timesCalled += 1;
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": (new Date().getTime() + 50) / 1000 // epoch seconds + 50ms
- })
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': (new Date().getTime() + 50) / 1000 // epoch seconds + 50ms
+ }
+ )
.get('/')
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": (new Date().getTime() + 100) / 1000 // epoch seconds + 100ms
- });
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': (new Date().getTime() + 100) / 1000 // epoch seconds + 100ms
+ }
+ );
var client = new RetryRestClient(restClientSpy, { maxRetries: 1 });
- client.getAll()
- .catch(function(err) {
- expect(err).to.not.null;
- expect(timesCalled).to.be.equal(2); // Initial call + 3 retires.
- done();
- });
+ client.getAll().catch(function(err) {
+ expect(err).to.not.null;
+ expect(timesCalled).to.be.equal(2); // Initial call + 3 retires.
+ done();
+ });
});
- it('should not retry when status code is not 429', function(done){
+ it('should not retry when status code is not 429', function(done) {
nock(API_URL)
.get('/')
.reply(500);
var client = new RetryRestClient(this.restClient);
- client.getAll()
- .catch(function(err) {
- expect(err).to.not.null;
- expect(err.statusCode).to.be.equal(500);
- done();
- });
+ client.getAll().catch(function(err) {
+ expect(err).to.not.null;
+ expect(err.statusCode).to.be.equal(500);
+ done();
+ });
});
- it('should delay the retry using x-ratelimit-reset header value and succeed after retry', function(done){
+ it('should delay the retry using x-ratelimit-reset header value and succeed after retry', function(done) {
var self = this;
var calledAt = [];
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
calledAt.push(new Date().getTime());
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": (new Date().getTime() + 50) / 1000 // epoch seconds + 50ms
- })
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': (new Date().getTime() + 50) / 1000 // epoch seconds + 50ms
+ }
+ )
.get('/')
- .reply(200, { success: true });;
+ .reply(200, { success: true });
- var client = new RetryRestClient(restClientSpy);
+ var client = new RetryRestClient(restClientSpy);
- client.getAll()
- .then(function(data) {
- expect(data.success).to.be.true;
- expect(calledAt.length).to.be.equal(2);
-
- var elapsedTime = calledAt[1] - calledAt[0];
- expect(elapsedTime).to.be.above(49); // Time between the requests should at least be more than 49ms
- done();
- });
- });
+ client.getAll().then(function(data) {
+ expect(data.success).to.be.true;
+ expect(calledAt.length).to.be.equal(2);
+ var elapsedTime = calledAt[1] - calledAt[0];
+ expect(elapsedTime).to.be.above(49); // Time between the requests should at least be more than 49ms
+ done();
+ });
+ });
- it('should not retry when retry functionality is disabled', function(done){
+ it('should not retry when retry functionality is disabled', function(done) {
var self = this;
var timesCalled = 0;
var restClientSpy = {
- getAll: function(){
+ getAll: function() {
timesCalled += 1;
return self.restClient.getAll(arguments);
}
- }
+ };
nock(API_URL)
.get('/')
- .reply(429, { success: false }, {
- "x-ratelimit-limit": "10",
- "x-ratelimit-remaining": "0",
- "x-ratelimit-reset": "1508253300"
- });
+ .reply(
+ 429,
+ { success: false },
+ {
+ 'x-ratelimit-limit': '10',
+ 'x-ratelimit-remaining': '0',
+ 'x-ratelimit-reset': '1508253300'
+ }
+ );
var client = new RetryRestClient(restClientSpy, { enabled: false });
- client.getAll()
- .catch(function(err) {
- expect(err).to.not.null;
- expect(err.statusCode).to.be.equal(429);
- expect(timesCalled).to.be.equal(1);
- done();
- });
+ client.getAll().catch(function(err) {
+ expect(err).to.not.null;
+ expect(err.statusCode).to.be.equal(429);
+ expect(timesCalled).to.be.equal(1);
+ done();
+ });
});
- it('should remove callback from arguments object if data is passed', function (done) {
+ it('should remove callback from arguments object if data is passed', function(done) {
var self = this;
var restClientSpy = {
- create: function(){
+ create: function() {
expect(arguments.length).to.be.equal(1);
done();
return Promise.resolve();
}
- }
+ };
var client = new RetryRestClient(restClientSpy, { enabled: false });
- client.create({data: 'foobar'}, function() { });
+ client.create({ data: 'foobar' }, function() {});
});
- it('should remove callback from arguments object if urlParams and data is passed', function (done) {
+ it('should remove callback from arguments object if urlParams and data is passed', function(done) {
var self = this;
var restClientSpy = {
- create: function(){
+ create: function() {
expect(arguments.length).to.be.equal(2);
done();
return Promise.resolve();
}
- }
+ };
var client = new RetryRestClient(restClientSpy, { enabled: false });
var urlParams = { id: '123' };
- var data = {data: 'foobar'};
- client.create('/:id', data, function() { });
+ var data = { data: 'foobar' };
+ client.create('/:id', data, function() {});
});
- it('should not remove data object when no callback is passed', function (done) {
+ it('should not remove data object when no callback is passed', function(done) {
var self = this;
var restClientSpy = {
- create: function(){
+ create: function() {
expect(arguments.length).to.be.equal(1);
done();
return Promise.resolve();
}
- }
+ };
var client = new RetryRestClient(restClientSpy, { enabled: false });
- var data = {data: 'foobar'};
+ var data = { data: 'foobar' };
client.create(data);
});
- it('should not remove data object when urlParams is passed and no callback is passed', function (done) {
+ it('should not remove data object when urlParams is passed and no callback is passed', function(done) {
var self = this;
var restClientSpy = {
- create: function(){
+ create: function() {
expect(arguments.length).to.be.equal(2);
done();
return Promise.resolve();
}
- }
+ };
var client = new RetryRestClient(restClientSpy, { enabled: false });
var urlParams = { id: '123' };
- var data = {data: 'foobar'};
+ var data = { data: 'foobar' };
client.create('/:id', data);
});
-});
\ No newline at end of file
+});
diff --git a/test/utils/ensureMethod.js b/test/utils/ensureMethod.js
index efcc71bac..1efd07cec 100644
--- a/test/utils/ensureMethod.js
+++ b/test/utils/ensureMethod.js
@@ -1,10 +1,7 @@
var expect = require('chai').expect;
-
-module.exports = function (obj, name) {
- return function () {
- expect(obj[name])
- .to.exist
- .to.be.an.instanceOf(Function);
+module.exports = function(obj, name) {
+ return function() {
+ expect(obj[name]).to.exist.to.be.an.instanceOf(Function);
};
};
diff --git a/test/utils/ensureProperty.js b/test/utils/ensureProperty.js
index 57333d7c8..bfdde1474 100644
--- a/test/utils/ensureProperty.js
+++ b/test/utils/ensureProperty.js
@@ -1,10 +1,7 @@
var expect = require('chai').expect;
-
-module.exports = function (obj, name, cls) {
- return function () {
- expect(obj[name])
- .to.exist
- .to.be.an.instanceOf(cls);
+module.exports = function(obj, name, cls) {
+ return function() {
+ expect(obj[name]).to.exist.to.be.an.instanceOf(cls);
};
};
diff --git a/test/utils/extractParts.js b/test/utils/extractParts.js
index 69ffc599b..2a09fe95f 100644
--- a/test/utils/extractParts.js
+++ b/test/utils/extractParts.js
@@ -1,21 +1,18 @@
-module.exports = function (body, boundary) {
+module.exports = function(body, boundary) {
var partRegexp = new RegExp(boundary + '[-]{2}|' + boundary, 'g');
var parts = {};
var name;
var value;
- body
- .split(partRegexp)
- .forEach(function (part) {
- // Ignore empty strings in the array.
- if (part.trim().length === 0) return;
+ body.split(partRegexp).forEach(function(part) {
+ // Ignore empty strings in the array.
+ if (part.trim().length === 0) return;
- name = part.match(/name="([^"]*)"/)[1];
- value = part.split('"' + name + '"')[1];
+ name = part.match(/name="([^"]*)"/)[1];
+ value = part.split('"' + name + '"')[1];
- parts[name] = value.trim();
- });
+ parts[name] = value.trim();
+ });
return parts;
};
-
diff --git a/yarn.lock b/yarn.lock
index 26a718131..4877e816c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -65,6 +65,12 @@ ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
+ansi-styles@^3.2.1:
+ version "3.2.1"
+ resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
+ dependencies:
+ color-convert "^1.9.0"
+
anymatch@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507"
@@ -315,6 +321,14 @@ chalk@^1.1.1:
strip-ansi "^3.0.0"
supports-color "^2.0.0"
+chalk@^2.3.0:
+ version "2.3.2"
+ resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.2.tgz#250dc96b07491bfd601e648d66ddf5f60c7a5c65"
+ dependencies:
+ ansi-styles "^3.2.1"
+ escape-string-regexp "^1.0.5"
+ supports-color "^5.3.0"
+
change-case@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/change-case/-/change-case-2.3.1.tgz#2c4fde3f063bb41d00cd68e0d5a09db61cbe894f"
@@ -355,6 +369,10 @@ chokidar@^1.0.0:
optionalDependencies:
fsevents "^1.0.0"
+ci-info@^1.0.0:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2"
+
cliui@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"
@@ -383,6 +401,16 @@ codecov@^2.2.0:
request "2.79.0"
urlgrey "0.4.4"
+color-convert@^1.9.0:
+ version "1.9.1"
+ resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed"
+ dependencies:
+ color-name "^1.1.1"
+
+color-name@^1.1.1:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
+
combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
@@ -440,6 +468,14 @@ core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
+cross-spawn@^5.0.1:
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
+ dependencies:
+ lru-cache "^4.0.1"
+ shebang-command "^1.2.0"
+ which "^1.2.9"
+
crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
@@ -618,7 +654,7 @@ escape-string-regexp@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1"
-escape-string-regexp@^1.0.2, escape-string-regexp@~1.0.5:
+escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5, escape-string-regexp@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@@ -675,6 +711,18 @@ events@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
+execa@^0.8.0:
+ version "0.8.0"
+ resolved "https://registry.yarnpkg.com/execa/-/execa-0.8.0.tgz#d8d76bbc1b55217ed190fd6dd49d3c774ecfc8da"
+ dependencies:
+ cross-spawn "^5.0.1"
+ get-stream "^3.0.0"
+ is-stream "^1.1.0"
+ npm-run-path "^2.0.0"
+ p-finally "^1.0.0"
+ signal-exit "^3.0.0"
+ strip-eof "^1.0.0"
+
expand-brackets@^0.1.4:
version "0.1.5"
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b"
@@ -733,6 +781,12 @@ fill-range@^2.1.0:
repeat-element "^1.1.2"
repeat-string "^1.5.2"
+find-up@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
+ dependencies:
+ locate-path "^2.0.0"
+
for-in@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -839,6 +893,10 @@ generate-object-property@^1.1.0:
dependencies:
is-property "^1.0.0"
+get-stream@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
+
get-uri@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-2.0.1.tgz#dbdcacacd8c608a38316869368117697a1631c59"
@@ -960,6 +1018,10 @@ has-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
+has-flag@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
+
has-unicode@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
@@ -1035,6 +1097,14 @@ https-proxy-agent@1, https-proxy-agent@^1.0.0:
debug "2"
extend "3"
+husky@^0.14.3:
+ version "0.14.3"
+ resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"
+ dependencies:
+ is-ci "^1.0.10"
+ normalize-path "^1.0.0"
+ strip-indent "^2.0.0"
+
iconv-lite@0.4.19:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@@ -1043,6 +1113,10 @@ ieee754@^1.1.4:
version "1.1.8"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
+ignore@^3.3.7:
+ version "3.3.7"
+ resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"
+
indexof@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d"
@@ -1084,6 +1158,12 @@ is-buffer@^1.1.5, is-buffer@~1.1.1:
version "1.1.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
+is-ci@^1.0.10:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
+ dependencies:
+ ci-info "^1.0.0"
+
is-dotfile@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1"
@@ -1153,6 +1233,10 @@ is-property@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84"
+is-stream@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
+
is-string@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.4.tgz#cc3a9b69857d621e963725a24caeec873b826e64"
@@ -1328,6 +1412,13 @@ loader-utils@^0.2.11, loader-utils@^0.2.5, loader-utils@~0.2.2, loader-utils@~0.
json5 "^0.5.0"
object-assign "^4.0.1"
+locate-path@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
+ dependencies:
+ p-locate "^2.0.0"
+ path-exists "^3.0.0"
+
lock@~0.1.2:
version "0.1.4"
resolved "https://registry.yarnpkg.com/lock/-/lock-0.1.4.tgz#fec7deaef17e7c3a0a55e1da042803e25d91745d"
@@ -1362,6 +1453,13 @@ lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"
+lru-cache@^4.0.1:
+ version "4.1.2"
+ resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.2.tgz#45234b2e6e2f2b33da125624c4664929a0224c3f"
+ dependencies:
+ pseudomap "^1.0.2"
+ yallist "^2.1.2"
+
lru-cache@~2.6.5:
version "2.6.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.6.5.tgz#e56d6354148ede8d7707b58d143220fd08df0fd5"
@@ -1523,6 +1621,10 @@ moment@^2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
+mri@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.0.tgz#5c0a3f29c8ccffbbb1ec941dcec09d71fa32f36a"
+
ms@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
@@ -1606,12 +1708,22 @@ nopt@^4.0.1:
abbrev "1"
osenv "^0.1.4"
+normalize-path@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379"
+
normalize-path@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
dependencies:
remove-trailing-separator "^1.0.1"
+npm-run-path@^2.0.0:
+ version "2.0.2"
+ resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
+ dependencies:
+ path-key "^2.0.0"
+
npmlog@^4.0.2:
version "4.1.0"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.0.tgz#dc59bee85f64f00ed424efb2af0783df25d1c0b5"
@@ -1695,6 +1807,26 @@ osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"
+p-finally@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
+
+p-limit@^1.1.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
+ dependencies:
+ p-try "^1.0.0"
+
+p-locate@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
+ dependencies:
+ p-limit "^1.1.0"
+
+p-try@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
+
pac-proxy-agent@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-2.0.0.tgz#beb17cd2b06a20b379d57e1b2e2c29be0dfe5f9a"
@@ -1754,10 +1886,18 @@ path-case@^1.1.0:
dependencies:
sentence-case "^1.1.2"
+path-exists@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
+
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
+path-key@^2.0.0:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
+
pbkdf2-compat@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/pbkdf2-compat/-/pbkdf2-compat-2.0.1.tgz#b6e0c8fa99494d94e0511575802a59a5c142f288"
@@ -1788,6 +1928,20 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
+prettier@^1.12.0:
+ version "1.12.0"
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.0.tgz#d26fc5894b9230de97629b39cae225b503724ce8"
+
+pretty-quick@^1.4.1:
+ version "1.4.1"
+ resolved "https://registry.yarnpkg.com/pretty-quick/-/pretty-quick-1.4.1.tgz#9d41f778d2d4d940ec603d1293a0998e84c4722c"
+ dependencies:
+ chalk "^2.3.0"
+ execa "^0.8.0"
+ find-up "^2.1.0"
+ ignore "^3.3.7"
+ mri "^1.1.0"
+
process-nextick-args@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
@@ -1817,7 +1971,7 @@ prr@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a"
-pseudomap@^1.0.1:
+pseudomap@^1.0.1, pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
@@ -2104,6 +2258,16 @@ sha.js@2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.2.6.tgz#17ddeddc5f722fb66501658895461977867315ba"
+shebang-command@^1.2.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
+ dependencies:
+ shebang-regex "^1.0.0"
+
+shebang-regex@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
+
sigmund@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
@@ -2278,6 +2442,14 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1:
dependencies:
ansi-regex "^2.0.0"
+strip-eof@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
+
+strip-indent@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68"
+
strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
@@ -2324,6 +2496,12 @@ supports-color@^3.1.0:
dependencies:
has-flag "^1.0.0"
+supports-color@^5.3.0:
+ version "5.3.0"
+ resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.3.0.tgz#5b24ac15db80fa927cf5227a4a33fd3c4c7676c0"
+ dependencies:
+ has-flag "^3.0.0"
+
swap-case@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/swap-case/-/swap-case-1.1.2.tgz#c39203a4587385fad3c850a0bd1bcafa081974e3"
@@ -2552,6 +2730,12 @@ which@^1.1.1:
dependencies:
isexe "^2.0.0"
+which@^1.2.9:
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
+ dependencies:
+ isexe "^2.0.0"
+
wide-align@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.2.tgz#571e0f1b0604636ebc0dfc21b0339bbe31341710"
@@ -2590,7 +2774,7 @@ xtend@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
-yallist@^2.0.0:
+yallist@^2.0.0, yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"