Updates. See commit details. Tests now all work and pass. Auth Fallback changed to Auth Mode. Removed ObjectKit moving all code to use LoDash.
Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/b19a1a99 Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/b19a1a99 Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/b19a1a99 Branch: refs/heads/master Commit: b19a1a9937d9626cd9234bd3c79f687b9c14ecff Parents: bf510a6 Author: Robert Walsh <[email protected]> Authored: Wed Nov 9 13:35:08 2016 -0600 Committer: Robert Walsh <[email protected]> Committed: Wed Nov 9 13:35:08 2016 -0600 ---------------------------------------------------------------------- .gitignore | 2 + README.md | 6 +- config.sample.json | 2 +- examples/api-proxy/config/usergrid.example.json | 2 +- helpers/build.js | 72 ++++++++++---------- helpers/cb.js | 8 +-- helpers/mutability.js | 7 +- lib/asset.js | 5 +- lib/auth.js | 8 ++- lib/client.js | 11 ++- lib/entity.js | 21 +++--- lib/request.js | 3 - lib/response.js | 9 ++- lib/responseError.js | 4 +- lib/user.js | 4 +- package.json | 1 - tests/lib/asset.test.js | 1 - tests/lib/client.auth.test.js | 28 +++----- tests/lib/client.connections.test.js | 16 ++--- tests/lib/client.init.test.js | 4 -- tests/lib/client.rest.test.js | 3 - tests/lib/entity.test.js | 10 +-- tests/lib/query.test.js | 2 +- tests/lib/response.test.js | 1 - tests/lib/responseError.test.js | 2 +- tests/lib/user.test.js | 1 - 26 files changed, 107 insertions(+), 126 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 3c3629e..c727bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.idea +.DS_Store http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 55637e6..9e0f2f8 100644 --- a/README.md +++ b/README.md @@ -313,16 +313,16 @@ Usergrid.authenticateUser({ }) ``` -### authFallback +### authMode -Auth-fallback defines what the client should do when a user token is not present. By default, `Usergrid.authFallback` is set to `UsergridAuth.AUTH_FALLBACK_NONE`, whereby when a token is *not* present, an API call will be performed unauthenticated. If instead `Usergrid.authFallback` is set to `UsergridAuth.AUTH_FALLBACK_APP`, the API call will instead be performed using client credentials, _if_ they're available (i.e. `authenticateApp()` was performed at some point). +Auth-mode defines what the client should do when a user token is not present. By default, `Usergrid.authMode` is set to `UsergridAuth.AUTH_MODE_NONE`, whereby when a token is *not* present, an API call will be performed unauthenticated. If instead `Usergrid.authMode` is set to `UsergridAuth.AUTH_MODE_APP`, the API call will instead be performed using client credentials, _if_ they're available (i.e. `authenticateApp()` was performed at some point). ### usingAuth() At times it is desireable to have complete, granular control over the authentication context of an API call. To facilitate this, the passthrough function `.usingAuth()` allows you to pre-define the auth context of the next API call. ```js -// assume Usergrid.authFallback = UsergridAuth.AUTH_FALLBACK_NONE +// assume Usergrid.authMode = UsergridAuth.AUTH_MODE_NONE Usergrid.usingAuth(Usergrid.appAuth).POST('roles/guest/permissions', { permission: "get,post,put,delete:/**" http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/config.sample.json ---------------------------------------------------------------------- diff --git a/config.sample.json b/config.sample.json index a15a6a5..4e6cfa9 100644 --- a/config.sample.json +++ b/config.sample.json @@ -1,6 +1,6 @@ { "appId": "yourAppId", - "authFallback": "NONE", + "authMode": "NONE", "baseUrl": "https://api.usergrid.com", "clientId": "yourClientId", "clientSecret": "yourClientSecret", http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/examples/api-proxy/config/usergrid.example.json ---------------------------------------------------------------------- diff --git a/examples/api-proxy/config/usergrid.example.json b/examples/api-proxy/config/usergrid.example.json index 5d13860..36baab8 100644 --- a/examples/api-proxy/config/usergrid.example.json +++ b/examples/api-proxy/config/usergrid.example.json @@ -1,7 +1,7 @@ { "appId": "sandbox", "orgId": "brandon.apigee", - "authFallback": "NONE", + "authMode": "NONE", "baseUrl": "https://api.usergrid.com", "clientId": "YXA6GXSAACS2EeOYd20aP4G6Lw", "clientSecret": "YXA66BeEvgNpJBwc4PAbvZZGTVS_SSw" http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/helpers/build.js ---------------------------------------------------------------------- diff --git a/helpers/build.js b/helpers/build.js index 3697fee..ca5ed43 100644 --- a/helpers/build.js +++ b/helpers/build.js @@ -23,12 +23,11 @@ var urljoin = require('url-join'), UsergridAsset = require('../lib/asset'), util = require('util'), version = require('../package.json').version, - ok = require('objectkit'), _ = require('lodash') var assignPrefabOptions = function(args) { // if a preformatted options argument passed, assign it to options - if (_.isObject(args[0]) && !_.isFunction(args[0]) && ok(this).has("method")) { + if (_.isObject(args[0]) && !_.isFunction(args[0]) && _.has(this,"method")) { _.assign(this, args[0]) } return this @@ -45,7 +44,7 @@ var setEntity = function(args) { } var setAsset = function(args) { - this.asset = _.first([this.asset, ok(this).getIfExists('entity.asset'), args[1], args[0]].filter(function(property) { + this.asset = _.first([this.asset, _.get(this,'entity.asset'), args[1], args[0]].filter(function(property) { return (property instanceof UsergridAsset) })) return this @@ -56,12 +55,12 @@ var setUuidOrName = function(args) { this.uuidOrName, this.uuid, this.name, - ok(this).getIfExists('entity.uuid'), - ok(this).getIfExists('body.uuid'), - ok(this).getIfExists('entity.name'), - ok(this).getIfExists('body.name'), - ok(args).getIfExists('2'), - ok(args).getIfExists('1') + _.get(this,'entity.uuid'), + _.get(this,'body.uuid'), + _.get(this,'entity.name'), + _.get(this,'body.name'), + _.get(args,'2'), + _.get(args,'1') ].filter(_.isString)) return this } @@ -69,10 +68,10 @@ var setUuidOrName = function(args) { var setPathOrType = function(args) { var pathOrType = _.first([ this.type, - ok(args).getIfExists('0._type'), - ok(this).getIfExists('entity.type'), - ok(this).getIfExists('body.type'), - ok(this).getIfExists('body.0.type'), + _.get(args,'0._type'), + _.get(this,'entity.type'), + _.get(this,'body.type'), + _.get(this,'body.0.type'), _.isArray(args) ? args[0] : undefined ].filter(_.isString)) this[(/\//.test(pathOrType)) ? 'path' : 'type'] = pathOrType @@ -114,8 +113,8 @@ module.exports = { options.uuidOrName, options.uuid, options.name, - ok(options).getIfExists('entity.uuid'), - ok(options).getIfExists('entity.name'), + _.get(options,'entity.uuid'), + _.get(options,'entity.name'), "" ].filter(_.isString)) : "" ) @@ -124,28 +123,31 @@ module.exports = { var headers = { 'User-Agent': util.format("usergrid-nodejs/v%s", version) } + _.assign(headers, options.headers) + var token - if (ok(client).getIfExists('tempAuth') === UsergridAuth.NO_AUTH) { + var clientTempAuth = _.get(client,"tempAuth") + if( !_.isUndefined(clientTempAuth) ) { + if( clientTempAuth !== UsergridAuth.NO_AUTH && clientTempAuth.isValid ) { + token = client.tempAuth.token; + } client.tempAuth = undefined } else { - if (ok(client).getIfExists('tempAuth.isValid')) { - // if ad-hoc authentication was set in the client, get the token and destroy the auth - token = client.tempAuth.token - client.tempAuth = undefined - } else if (ok(client).getIfExists('currentUser.auth.isValid')) { - // defaults to using the current user's token - token = client.currentUser.auth.token - } else if (ok(client).getIfExists('authFallback') === UsergridAuth.AUTH_FALLBACK_APP && ok(client).getIfExists('appAuth.isValid')) { - // if auth-fallback is set to APP request will make a call using the application token - token = client.appAuth.token - } - if (token) { - _.assign(headers, { - authorization: util.format("Bearer %s", token) - }) + var clientAuthMode = _.get(client,"authMode"); + if( _.get(client,"currentUser.auth.isValid") && clientAuthMode === UsergridAuth.AUTH_MODE_USER ) { + token = client.currentUser.auth.token; + } else if( _.get(client,"appAuth.isValid") && clientAuthMode === UsergridAuth.AUTH_MODE_APP ) { + token = client.appAuth.token; } } + + if (token) { + _.assign(headers, { + authorization: util.format("Bearer %s", token) + }) + } + return headers }, userLoginBody: function(options) { @@ -457,16 +459,16 @@ module.exports = { } : options.qs }, formData: function(options) { - if (ok(options).getIfExists('asset.data')) { + if (_.get(options,'asset.data')) { var formData = {} formData.file = { value: options.asset.data, options: { - filename: ok(options).getIfExists('asset.filename') || UsergridAsset.DEFAULT_FILE_NAME, - contentType: ok(options).getIfExists('asset.contentType') || 'application/octet-stream' + filename: _.get(options,'asset.filename') || UsergridAsset.DEFAULT_FILE_NAME, + contentType: _.get(options,'asset.contentType') || 'application/octet-stream' } } - if (ok(options).has('asset.name')) { + if (_.has(options,'asset.name')) { formData.name = options.asset.name } return formData http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/helpers/cb.js ---------------------------------------------------------------------- diff --git a/helpers/cb.js b/helpers/cb.js index 109ef27..e26076d 100644 --- a/helpers/cb.js +++ b/helpers/cb.js @@ -14,11 +14,11 @@ limitations under the License. 'use strict' -var ok = require('objectkit'), - _ = require('lodash') +var _ = require('lodash') module.exports = function() { - var args = _.flattenDeep(Array.prototype.slice.call(arguments)) + var args = _.flattenDeep(Array.prototype.slice.call(arguments)).reverse() var emptyFunc = function() {} - return _.first(_.flattenDeep([args.reverse(), ok(args).getIfExists('0.callback'), emptyFunc]).filter(_.isFunction)) + return _.first(_.flattenDeep([args, _.get(args,'0.callback'), emptyFunc]).filter(_.isFunction)) + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/helpers/mutability.js ---------------------------------------------------------------------- diff --git a/helpers/mutability.js b/helpers/mutability.js index b948d2b..0ad058b 100644 --- a/helpers/mutability.js +++ b/helpers/mutability.js @@ -14,8 +14,7 @@ limitations under the License. 'use strict' -var ok = require('objectkit'), - _ = require('lodash') +var _ = require('lodash') module.exports = { setReadOnly: function(obj, key) { @@ -27,7 +26,7 @@ module.exports = { return Object.freeze(obj[key]) } else if (_.isPlainObject(obj) && key === undefined) { return Object.freeze(obj) - } else if (ok(obj).has(key)) { + } else if (_.has(obj,key)) { return Object.defineProperty(obj, key, { writable: false }) @@ -45,7 +44,7 @@ module.exports = { return _.clone(obj[key]) } else if (_.isPlainObject(obj) && key === undefined) { return _.clone(obj) - } else if (ok(obj).has(key)) { + } else if (_.has(obj,key)) { return Object.defineProperty(obj, key, { writable: true }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/asset.js ---------------------------------------------------------------------- diff --git a/lib/asset.js b/lib/asset.js index 681db0c..a054075 100644 --- a/lib/asset.js +++ b/lib/asset.js @@ -14,13 +14,10 @@ limitations under the License. 'use strict' -var Usergrid = require('../usergrid'), - readChunk = require('read-chunk'), - fileType = require('file-type'), +var fileType = require('file-type'), helpers = require('../helpers'), stream = require('stream'), util = require('util'), - ok = require('objectkit'), _ = require('lodash') var UsergridAsset = function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/auth.js ---------------------------------------------------------------------- diff --git a/lib/auth.js b/lib/auth.js index d3872d8..06ef684 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -61,11 +61,15 @@ UsergridAuth.prototype = { module.exports = UsergridAuth -Object.defineProperty(module.exports, 'AUTH_FALLBACK_APP', { +Object.defineProperty(module.exports, 'AUTH_MODE_APP', { enumerable: false, get: function() { return "APP" } }) -Object.defineProperty(module.exports, 'AUTH_FALLBACK_NONE', { +Object.defineProperty(module.exports, 'AUTH_MODE_USER', { + enumerable: false, + get: function() { return "USER" } +}) +Object.defineProperty(module.exports, 'AUTH_MODE_NONE', { enumerable: false, get: function() { return "NONE" } }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/client.js ---------------------------------------------------------------------- diff --git a/lib/client.js b/lib/client.js index f022793..84d6fdf 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,16 +16,13 @@ limitations under the License. var helpers = require('../helpers'), UsergridRequest = require('./request'), - UsergridResponse = require('./response'), - UsergridResponseError = require('./responseError'), UsergridAuth = require('./auth'), UsergridAppAuth = require('./appAuth'), - UsergridUserAuth = require('./userAuth'), _ = require('lodash') var defaultOptions = { baseUrl: 'https://api.usergrid.com', - authFallback: UsergridAuth.AUTH_FALLBACK_NONE + authMode: UsergridAuth.AUTH_MODE_NONE } var UsergridClient = function(options) { @@ -65,7 +62,9 @@ var UsergridClient = function(options) { set: function(options) { if (options instanceof UsergridAppAuth) { __appAuth = options - } else if (typeof options !== "undefined") { + } else if( _.isUndefined(options) ) { + __appAuth = undefined + } else { __appAuth = new UsergridAppAuth(options) } } @@ -106,7 +105,7 @@ UsergridClient.prototype = { authenticateApp: function(options) { var self = this var callback = helpers.cb(helpers.args(arguments)) - console.log(self.appAuth)//, self.appAuth, new UsergridAppAuth(options), new UsergridAppAuth(self.clientId, self.clientSecret)) + // console.log(self.appAuth)//, self.appAuth, new UsergridAppAuth(options), new UsergridAppAuth(self.clientId, self.clientSecret)) var auth = _.first([options, self.appAuth, new UsergridAppAuth(options), new UsergridAppAuth(self.clientId, self.clientSecret)].filter(function(p) { return p instanceof UsergridAppAuth })) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/entity.js ---------------------------------------------------------------------- diff --git a/lib/entity.js b/lib/entity.js index eda1086..ef83770 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -14,11 +14,9 @@ limitations under the License. 'use strict' -var Usergrid = require('../usergrid'), - UsergridRequest = require('./request'), +var UsergridRequest = require('./request'), UsergridAsset = require('./asset'), helpers = require('../helpers'), - ok = require('objectkit'), _ = require('lodash') function updateEntityFromRemote(usergridResponse) { @@ -35,11 +33,16 @@ var UsergridEntity = function() { throw new Error('A UsergridEntity object cannot be initialized without passing one or more arguments') } - if (_.isPlainObject(args[0])) { - _.assign(self, args[0]) + var firstArg = args[0] + if (_.isPlainObject(firstArg) || firstArg instanceof UsergridEntity ) { + _.assign(self, args[0]); } else { - self.type = _.isString(args[0]) ? args[0] : undefined - self.name = _.isString(args[1]) ? args[1] : undefined + if( !self.type ) { + self.type = _.isString(args[0]) ? args[0] : undefined; + } + if( !self.name ) { + self.name = _.isString(args[1]) ? args[1] : undefined; + } } if (!_.isString(self.type)) { @@ -60,7 +63,7 @@ var UsergridEntity = function() { Object.defineProperty(self, 'hasAsset', { get: function() { - return ok(self).has(['file', 'file-metadata']) + return _.has(self,'file-metadata') } }) @@ -159,7 +162,7 @@ UsergridEntity.prototype = { var callback = helpers.cb(args) var self = this - if (ok(self).has('asset.contentType')) { + if (_.has(self,'asset.contentType')) { var options = { client: client, entity: self, http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/request.js ---------------------------------------------------------------------- diff --git a/lib/request.js b/lib/request.js index 70bb851..ba3d573 100644 --- a/lib/request.js +++ b/lib/request.js @@ -17,9 +17,6 @@ limitations under the License. var request = require('request'), helpers = require('../helpers'), UsergridResponse = require('../lib/response'), - UsergridQuery = require('../lib/query'), - UsergridAsset = require('../lib/asset'), - ok = require('objectkit'), _ = require('lodash') var UsergridRequest = function(options) { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/response.js ---------------------------------------------------------------------- diff --git a/lib/response.js b/lib/response.js index b2f6fd4..9be05e0 100644 --- a/lib/response.js +++ b/lib/response.js @@ -14,8 +14,7 @@ limitations under the License. 'use strict' -var ok = require('objectkit'), - UsergridQuery = require('./query'), +var UsergridQuery = require('./query'), UsergridResponseError = require('./responseError'), helpers = require('../helpers'), _ = require('lodash') @@ -32,7 +31,7 @@ var UsergridResponse = function(response) { _.assign(self, response) - if (ok(response.body).has('entities')) { + if (_.has(response,'body.entities')) { var entities = response.body.entities.map(function(en) { var entity = new UsergridEntity(en) if (entity.isUser) { @@ -48,14 +47,14 @@ var UsergridResponse = function(response) { self.first = _.first(entities) || undefined self.entity = self.first self.last = _.last(entities) || undefined - if (ok(self).getIfExists('metadata.path') === '/users') { + if (_.get(self,'metadata.path') === '/users') { self.user = self.first self.users = self.entities } Object.defineProperty(self, 'hasNextPage', { get: function() { - return ok(self).has('metadata.cursor') + return _.has(self,'metadata.cursor') } }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/responseError.js ---------------------------------------------------------------------- diff --git a/lib/responseError.js b/lib/responseError.js index 38df35c..4471bbd 100644 --- a/lib/responseError.js +++ b/lib/responseError.js @@ -14,10 +14,10 @@ limitations under the License. 'use strict' -var ok = require('objectkit') +var _ = require('lodash') var UsergridResponseError = function(responseErrorObject) { - if (ok(responseErrorObject).has('error') === false) { + if (_.get(responseErrorObject,'error') === false) { return } this.name = responseErrorObject.error http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/lib/user.js ---------------------------------------------------------------------- diff --git a/lib/user.js b/lib/user.js index e9e6d15..fee89a1 100644 --- a/lib/user.js +++ b/lib/user.js @@ -19,15 +19,13 @@ var UsergridEntity = require('./entity'), UsergridUserAuth = require('./userAuth'), UsergridRequest = require('./request'), UsergridClient = require('../lib/client'), - UsergridResponseError = require('./responseError'), helpers = require('../helpers'), - ok = require('objectkit'), util = require('util'), _ = require('lodash') var UsergridUser = function(obj) { - if (!ok(obj).has('email') && !ok(obj).has('username')) { + if (!_.has(obj,'email') && !_.has(obj,'username')) { // This is not a user entity throw new Error('"email" or "username" property is required when initializing a UsergridUser object') } http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index a07c150..a292f36 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "lodash": "~4.0", "lodash-inflection": "latest", "lodash-uuid": "latest", - "objectkit": "latest", "read-chunk": "^1.0.1", "request": "latest", "url-join": "latest", http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/asset.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/asset.test.js b/tests/lib/asset.test.js index a25c494..2220d07 100644 --- a/tests/lib/asset.test.js +++ b/tests/lib/asset.test.js @@ -1,7 +1,6 @@ 'use strict' var should = require('should'), - urljoin = require('url-join'), config = require('../../helpers').config, UsergridEntity = require('../../lib/entity'), UsergridAsset = require('../../lib/asset'), http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/client.auth.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.auth.test.js b/tests/lib/client.auth.test.js index ad33987..ab9f0d0 100644 --- a/tests/lib/client.auth.test.js +++ b/tests/lib/client.auth.test.js @@ -2,12 +2,9 @@ var should = require('should'), chance = new require('chance').Chance(), - urljoin = require('url-join'), util = require('util'), config = require('../../helpers').config, UsergridClient = require('../../lib/client'), - UsergridEntity = require('../../lib/entity'), - UsergridQuery = require('../../lib/query'), UsergridAuth = require('../../lib/auth'), UsergridAppAuth = require('../../lib/appAuth'), UsergridUserAuth = require('../../lib/userAuth'), @@ -18,7 +15,7 @@ var _uuid, _slow = 500, _timeout = 4000 -describe('authFallback', function() { +describe('authMode', function() { this.slow(_slow) this.timeout(_timeout) @@ -38,8 +35,8 @@ describe('authFallback', function() { }) }) - it('should fall back to using no authentication when currentUser is not authenticated and authFallback is set to NONE', function(done) { - client.authFallback = UsergridAuth.AUTH_FALLBACK_NONE + it('should fall back to using no authentication when currentUser is not authenticated and authMode is set to NONE', function(done) { + client.authMode = UsergridAuth.AUTH_MODE_NONE client.GET('users', function(error, usergridResponse) { should(client.currentUser).be.undefined() usergridResponse.request.headers.should.not.have.property('authorization') @@ -49,8 +46,8 @@ describe('authFallback', function() { }) }) - it('should fall back to using the app token when currentUser is not authenticated and authFallback is set to APP', function(done) { - client.authFallback = UsergridAuth.AUTH_FALLBACK_APP + it('should fall back to using the app token when currentUser is not authenticated and authMode is set to APP', function(done) { + client.authMode = UsergridAuth.AUTH_MODE_APP client.GET('users', function(error, usergridResponse, user) { should(client.currentUser).be.undefined() usergridResponse.request.headers.should.have.property('authorization').equal(util.format('Bearer %s', token)) @@ -62,7 +59,7 @@ describe('authFallback', function() { after(function(done) { // re-add sandbox permissions - client.authFallback = UsergridAuth.AUTH_FALLBACK_NONE + client.authMode = UsergridAuth.AUTH_MODE_NONE client.usingAuth(client.appAuth).POST('roles/guest/permissions', { permission: "get,post,put,delete:/**" }, function(error, usergridResponse) { @@ -136,10 +133,8 @@ describe('authenticateApp()', function() { it('should not set client.appAuth when authenticating with a bad clientId and clientSecret in an object', function(done) { var failClient = new UsergridClient() - failClient.authenticateApp({ - clientId: 'BADCLIENTID', - clientSecret: 'BADCLIENTSECRET' - }, function(e, r, token) { + failClient.appAuth = undefined + failClient.authenticateApp(new UsergridAppAuth('BADCLIENTID', 'BADCLIENTSECRET'), function(e, r, token) { e.should.containDeep({ name: 'invalid_grant', description: 'invalid username or password' @@ -152,10 +147,8 @@ describe('authenticateApp()', function() { it('should not set client.appAuth when authenticating with a bad UsergridAppAuth instance (using an object)', function(done) { var failClient = new UsergridClient() - failClient.authenticateApp(new UsergridAppAuth({ - clientId: 'BADCLIENTID', - clientSecret: 'BADCLIENTSECRET' - }), function(e, r, token) { + failClient.appAuth = undefined + failClient.authenticateApp(new UsergridAppAuth('BADCLIENTID', 'BADCLIENTSECRET'), function(e, r, token) { e.should.containDeep({ name: 'invalid_grant', description: 'invalid username or password' @@ -169,6 +162,7 @@ describe('authenticateApp()', function() { it('should not set client.appAuth when authenticating with a bad UsergridAppAuth instance (using arguments)', function(done) { var failClient = new UsergridClient() + failClient.appAuth = undefined failClient.authenticateApp(new UsergridAppAuth('BADCLIENTID', 'BADCLIENTSECRET'), function(e, r, token) { e.should.containDeep({ name: 'invalid_grant', http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/client.connections.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.connections.test.js b/tests/lib/client.connections.test.js index a3b03e4..98dcc68 100644 --- a/tests/lib/client.connections.test.js +++ b/tests/lib/client.connections.test.js @@ -6,8 +6,6 @@ var should = require('should'), UsergridClient = require('../../lib/client'), UsergridEntity = require('../../lib/entity'), UsergridQuery = require('../../lib/query'), - UsergridAuth = require('../../lib/auth'), - UsergridAppAuth = require('../../lib/appAuth'), _ = require('lodash') var _uuid, @@ -48,7 +46,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -68,7 +66,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -88,7 +86,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -108,7 +106,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -132,7 +130,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, options.relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[options.relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, options.relationship, @@ -176,7 +174,7 @@ describe('getConnections()', function() { client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -196,7 +194,7 @@ describe('getConnections()', function() { client.getConnections(UsergridClient.Connections.DIRECTION_IN, entity2, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connections[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity2.uuid, "connecting", http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/client.init.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.init.test.js b/tests/lib/client.init.test.js index 827863f..f1572d4 100644 --- a/tests/lib/client.init.test.js +++ b/tests/lib/client.init.test.js @@ -4,10 +4,6 @@ var should = require('should'), urljoin = require('url-join'), config = require('../../helpers').config, UsergridClient = require('../../lib/client'), - UsergridEntity = require('../../lib/entity'), - UsergridQuery = require('../../lib/query'), - UsergridAuth = require('../../lib/auth'), - UsergridAppAuth = require('../../lib/appAuth'), _ = require('lodash') describe('initialization', function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/client.rest.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.rest.test.js b/tests/lib/client.rest.test.js index e67cfef..8636198 100644 --- a/tests/lib/client.rest.test.js +++ b/tests/lib/client.rest.test.js @@ -1,14 +1,11 @@ 'use strict' var should = require('should'), - urljoin = require('url-join'), config = require('../../helpers').config, chance = new require('chance').Chance(), UsergridClient = require('../../lib/client'), UsergridEntity = require('../../lib/entity'), UsergridQuery = require('../../lib/query'), - UsergridAuth = require('../../lib/auth'), - UsergridAppAuth = require('../../lib/appAuth'), _ = require('lodash') var _uuid, http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/entity.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/entity.test.js b/tests/lib/entity.test.js index 86fc63d..c5018c8 100644 --- a/tests/lib/entity.test.js +++ b/tests/lib/entity.test.js @@ -450,7 +450,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -470,7 +470,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -490,7 +490,7 @@ describe('connect()', function() { usergridResponse.ok.should.be.true() client.getConnections(UsergridClient.Connections.DIRECTION_OUT, entity1, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -534,7 +534,7 @@ describe('getConnections()', function() { entity1.getConnections(client, UsergridClient.Connections.DIRECTION_OUT, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connecting[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity1.uuid, relationship, @@ -554,7 +554,7 @@ describe('getConnections()', function() { entity2.getConnections(client, UsergridClient.Connections.DIRECTION_IN, relationship, function(err, usergridResponse) { usergridResponse.first.metadata.connections[relationship].should.equal(urljoin( - "/", + "", config.test.collection, entity2.uuid, "connecting", http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/query.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/query.test.js b/tests/lib/query.test.js index 65f9c1a..adbfab2 100644 --- a/tests/lib/query.test.js +++ b/tests/lib/query.test.js @@ -35,7 +35,7 @@ describe('_limit', function() { describe('_ql', function() { it('should equal \'select *\' if query or sort are empty or underfined', function() { var query = new UsergridQuery('cats') - query.should.have.property('_ql').equal('select * ') + query.should.have.property('_ql').equal('select *') }) it('should support complex builder pattern syntax (chained constructor methods)', function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/response.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/response.test.js b/tests/lib/response.test.js index cb680c5..f507559 100644 --- a/tests/lib/response.test.js +++ b/tests/lib/response.test.js @@ -6,7 +6,6 @@ var should = require('should'), UsergridEntity = require('../../lib/entity'), UsergridUser = require('../../lib/user'), UsergridQuery = require('../../lib/query'), - UsergridResponse = require('../../lib/response'), UsergridResponseError = require('../../lib/responseError'), _ = require('lodash') http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/responseError.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/responseError.test.js b/tests/lib/responseError.test.js index 6e0c3c9..f746279 100644 --- a/tests/lib/responseError.test.js +++ b/tests/lib/responseError.test.js @@ -30,7 +30,7 @@ describe('name, description, exception', function() { it('response.error should be a UsergridResponseError object with name, description, and exception keys', function() { _response.ok.should.be.false() - _response.error.should.be.an.instanceof(UsergridResponseError).with.keys(['name', 'description', 'exception']) + _response.error.should.be.an.instanceof(UsergridResponseError).with.properties(['name', 'description', 'exception']) }) }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/b19a1a99/tests/lib/user.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/user.test.js b/tests/lib/user.test.js index 8d96e71..28bb2c3 100644 --- a/tests/lib/user.test.js +++ b/tests/lib/user.test.js @@ -3,7 +3,6 @@ var should = require('should'), util = require('util'), chance = new require('chance').Chance(), - urljoin = require('url-join'), config = require('../../helpers').config, UsergridClient = require('../../lib/client'), UsergridUser = require('../../lib/user'),
