Fixing codacy issues.
Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/c9e92984 Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/c9e92984 Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/c9e92984 Branch: refs/heads/master Commit: c9e929843d8c5da80a91811547abe2951c77f6d2 Parents: aa7d107 Author: Robert Walsh <[email protected]> Authored: Thu Nov 10 18:56:07 2016 -0600 Committer: Robert Walsh <[email protected]> Committed: Thu Nov 10 18:56:07 2016 -0600 ---------------------------------------------------------------------- examples/api-proxy/app.js | 3 +-- helpers/config.js | 2 +- lib/entity.js | 8 ++++++-- lib/request.js | 3 +-- lib/user.js | 4 ++-- tests/lib/asset.test.js | 8 +++----- tests/lib/client.auth.test.js | 14 ++++++-------- tests/lib/client.connections.test.js | 6 ++---- tests/lib/client.init.test.js | 4 +--- tests/lib/client.rest.test.js | 3 +-- tests/lib/entity.test.js | 12 +++++------- tests/lib/query.test.js | 3 +-- tests/lib/response.test.js | 2 +- tests/lib/user.test.js | 23 +++++++++++------------ tests/lib/usergrid.init.test.js | 3 +-- tests/lib/usergrid.singleton.test.js | 3 +-- tests/main.test.js | 1 - 17 files changed, 44 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/examples/api-proxy/app.js ---------------------------------------------------------------------- diff --git a/examples/api-proxy/app.js b/examples/api-proxy/app.js index 76b3401..dde48f1 100644 --- a/examples/api-proxy/app.js +++ b/examples/api-proxy/app.js @@ -1,8 +1,7 @@ var express = require('express'), app = express(), Usergrid = require('usergrid'), - async = require('async'), - chance = require('chance') + async = require('async') Usergrid.init() http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/helpers/config.js ---------------------------------------------------------------------- diff --git a/helpers/config.js b/helpers/config.js index 860d9e2..ee6e0b6 100644 --- a/helpers/config.js +++ b/helpers/config.js @@ -34,7 +34,7 @@ if (/mocha$/i.test(process.argv[1])) { file.walkSync(appRoot, function(start, dirs, names) { if (_.includes(names, "config.json") || _.includes(names, "usergrid.json")) { var name = _.first(names.filter(function(name) { - return name == "config.json" || name == "usergrid.json" + return name === "config.json" || name === "usergrid.json" }).sort().reverse()) var configPath = util.format("%s/%s", start, name) module.exports = require(configPath) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/lib/entity.js ---------------------------------------------------------------------- diff --git a/lib/entity.js b/lib/entity.js index ef83770..b1452a6 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -55,6 +55,12 @@ var UsergridEntity = function() { writable: true }) + Object.defineProperty(self, 'asset', { + enumerable: false, + configurable: true, + writable: true + }) + Object.defineProperty(self, 'isUser', { get: function() { return (self.type.toLowerCase() === 'user') @@ -67,8 +73,6 @@ var UsergridEntity = function() { } }) - self.asset - helpers.setReadOnly(self, ['uuid', 'name', 'type', 'created']) return self http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/lib/request.js ---------------------------------------------------------------------- diff --git a/lib/request.js b/lib/request.js index ba3d573..77c88a5 100644 --- a/lib/request.js +++ b/lib/request.js @@ -20,7 +20,6 @@ var request = require('request'), _ = require('lodash') var UsergridRequest = function(options) { - var self = this var client = helpers.client.validate(options.client) var callback = helpers.cb(helpers.args(arguments)) @@ -36,7 +35,7 @@ var UsergridRequest = function(options) { var formData = helpers.build.formData(options) var body = ((formData !== undefined) ? undefined : options.body) - var req = request(uri, { + request(uri, { headers: helpers.build.headers(client, options), body: body, encoding: options.encoding || null, http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/lib/user.js ---------------------------------------------------------------------- diff --git a/lib/user.js b/lib/user.js index fee89a1..90506b4 100644 --- a/lib/user.js +++ b/lib/user.js @@ -117,7 +117,7 @@ UsergridUser.prototype = { qs: (!revokeAll) ? { token: self.auth.token } : undefined - }, function(error, usergridResponse, body) { + }, function(error, usergridResponse) { self.auth.destroy() callback(error, usergridResponse, usergridResponse.ok) }) @@ -147,7 +147,7 @@ UsergridUser.prototype = { path: util.format('users/%s/password', helpers.user.uniqueId(self)), method: 'PUT', body: body - }, function(error, usergridResponse, body) { + }, function(error, usergridResponse) { callback(error, usergridResponse, usergridResponse.ok) }) } http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/asset.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/asset.test.js b/tests/lib/asset.test.js index 2220d07..29cb5cd 100644 --- a/tests/lib/asset.test.js +++ b/tests/lib/asset.test.js @@ -1,14 +1,12 @@ 'use strict' -var should = require('should'), - config = require('../../helpers').config, +var config = require('../../helpers').config, UsergridEntity = require('../../lib/entity'), UsergridAsset = require('../../lib/asset'), UsergridClient = require('../../lib/client'), util = require('util'), request = require('request'), - fs = require('fs'), - _ = require('lodash') + fs = require('fs') var _slow = 6000, _timeout = 12000, @@ -103,7 +101,7 @@ describe('upload via client.PUT to a specific entity', function() { it('should upload a binary asset to an existing entity', function(done) { var entity = new UsergridEntity({ type: config.test.collection, - name: "AssetTestPUT", + name: "AssetTestPUT" }) var asset = new UsergridAsset(filename, file) client.PUT(entity, function(err, entityResponse, createdEntity) { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/client.auth.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.auth.test.js b/tests/lib/client.auth.test.js index ab9f0d0..6821184 100644 --- a/tests/lib/client.auth.test.js +++ b/tests/lib/client.auth.test.js @@ -8,11 +8,9 @@ var should = require('should'), UsergridAuth = require('../../lib/auth'), UsergridAppAuth = require('../../lib/appAuth'), UsergridUserAuth = require('../../lib/userAuth'), - UsergridUser = require('../../lib/user'), - _ = require('lodash') + UsergridUser = require('../../lib/user') -var _uuid, - _slow = 500, +var _slow = 500, _timeout = 4000 describe('authMode', function() { @@ -62,7 +60,7 @@ describe('authMode', function() { client.authMode = UsergridAuth.AUTH_MODE_NONE client.usingAuth(client.appAuth).POST('roles/guest/permissions', { permission: "get,post,put,delete:/**" - }, function(error, usergridResponse) { + }, function() { done() }) }) @@ -238,7 +236,7 @@ describe('authenticateUser()', function() { username: config.test.username, password: config.test.password, email: email - }, false, function(err, r, t) { + }, false, function() { should(noCurrentUserClient.currentUser).be.undefined() done() }) @@ -248,9 +246,9 @@ describe('authenticateUser()', function() { var newClient = new UsergridClient() var ttlInMilliseconds = 500000 var userAuth = new UsergridUserAuth(config.test.username, config.test.password, ttlInMilliseconds) - client.authenticateUser(userAuth, function(err, usergridResponse, token) { + newClient.authenticateUser(userAuth, function(err, usergridResponse, token) { usergridResponse.ok.should.be.true() - client.currentUser.auth.token.should.equal(token) + newClient.currentUser.auth.token.should.equal(token) usergridResponse.body.expires_in.should.equal(ttlInMilliseconds / 1000) done() }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/client.connections.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.connections.test.js b/tests/lib/client.connections.test.js index 98dcc68..acc19a2 100644 --- a/tests/lib/client.connections.test.js +++ b/tests/lib/client.connections.test.js @@ -5,11 +5,9 @@ var should = require('should'), config = require('../../helpers').config, UsergridClient = require('../../lib/client'), UsergridEntity = require('../../lib/entity'), - UsergridQuery = require('../../lib/query'), - _ = require('lodash') + UsergridQuery = require('../../lib/query') -var _uuid, - _slow = 500, +var _slow = 500, _timeout = 4000 describe('connect()', function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/client.init.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.init.test.js b/tests/lib/client.init.test.js index f1572d4..01702bd 100644 --- a/tests/lib/client.init.test.js +++ b/tests/lib/client.init.test.js @@ -1,10 +1,8 @@ 'use strict' var should = require('should'), - urljoin = require('url-join'), config = require('../../helpers').config, - UsergridClient = require('../../lib/client'), - _ = require('lodash') + UsergridClient = require('../../lib/client') describe('initialization', function() { it('should fail to initialize without an orgId and appId', function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/client.rest.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/client.rest.test.js b/tests/lib/client.rest.test.js index 61d796b..017073e 100644 --- a/tests/lib/client.rest.test.js +++ b/tests/lib/client.rest.test.js @@ -1,7 +1,6 @@ 'use strict' -var should = require('should'), - config = require('../../helpers').config, +var config = require('../../helpers').config, chance = new require('chance').Chance(), UsergridClient = require('../../lib/client'), UsergridEntity = require('../../lib/entity'), http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/entity.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/entity.test.js b/tests/lib/entity.test.js index c5018c8..8152f23 100644 --- a/tests/lib/entity.test.js +++ b/tests/lib/entity.test.js @@ -8,14 +8,12 @@ var should = require('should'), UsergridQuery = require('../../lib/query'), UsergridAuth = require('../../lib/auth'), UsergridAsset = require('../../lib/asset'), - fs = require('fs'), - _ = require('lodash') + fs = require('fs') var _slow = 1500, _timeout = 4000, filename = 'old_man', file = __dirname + '/image.jpg', - testFile = __dirname + '/image_test.jpg', expectedContentLength = 109055, assetEntity = new UsergridEntity({ type: config.test.collection, @@ -297,7 +295,7 @@ describe('reload()', function() { var entity = new UsergridEntity(getResponse.first) var modified = entity.modified getResponse.first.putProperty('reloadTest', now) - client.PUT(getResponse.first, function(err, putResponse) { + client.PUT(getResponse.first, function() { entity.reload(client, function() { client.isSharedInstance.should.be.false() entity.reloadTest.should.equal(now) @@ -351,7 +349,7 @@ describe('remove()', function() { }) }) -describe('attachAsset()', function(done) { +describe('attachAsset()', function() { var asset = new UsergridAsset(filename, file), entity = new UsergridEntity({ @@ -372,7 +370,7 @@ describe('attachAsset()', function(done) { }) }) -describe('uploadAsset()', function(done) { +describe('uploadAsset()', function() { this.slow(_slow) this.timeout(_timeout) @@ -398,7 +396,7 @@ describe('uploadAsset()', function(done) { }) }) -describe('downloadAsset()', function(done) { +describe('downloadAsset()', function() { this.slow(_slow) this.timeout(_timeout) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/query.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/query.test.js b/tests/lib/query.test.js index adbfab2..e92c34d 100644 --- a/tests/lib/query.test.js +++ b/tests/lib/query.test.js @@ -1,7 +1,6 @@ 'use strict' -var should = require('should'), - UsergridQuery = require('../../lib/query') +var UsergridQuery = require('../../lib/query') describe('_type', function() { it('_type should equal "cats" when passing "type" as a parameter to UsergridQuery', function() { http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/response.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/response.test.js b/tests/lib/response.test.js index 5341e5e..685d132 100644 --- a/tests/lib/response.test.js +++ b/tests/lib/response.test.js @@ -74,7 +74,7 @@ describe('users', function() { it('response.users should be an array of UsergridUser objects', function(done) { client.setAppAuth(config.clientId, config.clientSecret, config.tokenTtl) - client.authenticateApp(function(err, response) { + client.authenticateApp(function(err) { should(err).be.undefined() client.GET('users', function(err, usergridResponse) { usergridResponse.ok.should.be.true() http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/user.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/user.test.js b/tests/lib/user.test.js index 28bb2c3..ef89a20 100644 --- a/tests/lib/user.test.js +++ b/tests/lib/user.test.js @@ -6,8 +6,7 @@ var should = require('should'), config = require('../../helpers').config, UsergridClient = require('../../lib/client'), UsergridUser = require('../../lib/user'), - UsergridQuery = require('../../lib/query'), - _ = require('lodash') + UsergridQuery = require('../../lib/query') var _slow = 1500, _timeout = 4000, @@ -26,7 +25,7 @@ before(function(done) { var query = new UsergridQuery('users').not.eq('username', config.test.username).limit(20) // clean up old user entities as the UsergridResponse tests rely on this collection containing less than 10 entities client.DELETE(query, function() { - _user1.create(client, function(err, usergridResponse, user) { + _user1.create(client, function() { done() }) }) @@ -83,7 +82,7 @@ describe('create()', function() { user.should.have.property('activated').true() user.should.not.have.property('password') // cleanup - user.remove(client, function(err, response) { + user.remove(client, function() { done() }) }) @@ -112,7 +111,7 @@ describe('logout()', function() { this.timeout(_timeout) it(util.format("it should log out '%s' and destroy the saved UsergridUserAuth instance", _username1), function(done) { - _user1.logout(client, function(err, response, success) { + _user1.logout(client, function(err, response) { response.ok.should.be.true() response.body.action.should.equal("revoked user token") _user1.auth.isValid.should.be.false() @@ -121,7 +120,7 @@ describe('logout()', function() { }) it("it should return an error when attempting to log out a user that does not have a valid token", function(done) { - _user1.logout(client, function(err, response, success) { + _user1.logout(client, function(err) { err.should.containDeep({ name: 'no_valid_token' }) @@ -133,8 +132,8 @@ describe('logout()', function() { describe('logoutAllSessions()', function() { it(util.format("it should log out all tokens for the user '%s' destroy the saved UsergridUserAuth instance", _username1), function(done) { _user1.password = config.test.password - _user1.login(client, function(err, response, token) { - _user1.logoutAllSessions(client, function(err, response, success) { + _user1.login(client, function() { + _user1.logoutAllSessions(client, function(err, response) { response.ok.should.be.true() response.body.action.should.equal("revoked user tokens") _user1.auth.isValid.should.be.false() @@ -150,7 +149,7 @@ describe('resetPassword()', function() { this.timeout(_timeout) it(util.format("it should reset the password for '%s' by passing parameters", _username1), function(done) { - _user1.resetPassword(client, config.test.password, '2cool4u', function(err, response, success) { + _user1.resetPassword(client, config.test.password, '2cool4u', function(err, response) { response.ok.should.be.true() response.body.action.should.equal("set user password") done() @@ -161,7 +160,7 @@ describe('resetPassword()', function() { _user1.resetPassword(client, { oldPassword: '2cool4u', newPassword: config.test.password - }, function(err, response, success) { + }, function(err, response) { response.ok.should.be.true() response.body.action.should.equal("set user password") done() @@ -172,10 +171,10 @@ describe('resetPassword()', function() { _user1.resetPassword(client, { oldPassword: 'BADOLDPASSWORD', newPassword: config.test.password - }, function(err, response, success) { + }, function(err, response) { response.ok.should.be.false() err.name.should.equal('auth_invalid_username_or_password') - _user1.remove(client, function(err, response) { + _user1.remove(client, function() { done() }) }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/usergrid.init.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/usergrid.init.test.js b/tests/lib/usergrid.init.test.js index b8b29c2..b8a9fd9 100644 --- a/tests/lib/usergrid.init.test.js +++ b/tests/lib/usergrid.init.test.js @@ -1,7 +1,6 @@ 'use strict' -var should = require('should'), - config = require('../../helpers').config, +var config = require('../../helpers').config, Usergrid = require('../../usergrid'), UsergridClient = require('../../lib/client'), util = require('util'), http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/lib/usergrid.singleton.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/usergrid.singleton.test.js b/tests/lib/usergrid.singleton.test.js index 5a1a1ba..9f73bab 100644 --- a/tests/lib/usergrid.singleton.test.js +++ b/tests/lib/usergrid.singleton.test.js @@ -1,7 +1,6 @@ 'use strict' -var should = require('should'), - Usergrid = require('../../usergrid') +var Usergrid = require('../../usergrid') it('should be initialized when defined in another module', function(done) { Usergrid.should.have.property('isInitialized').which.is.true() http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/c9e92984/tests/main.test.js ---------------------------------------------------------------------- diff --git a/tests/main.test.js b/tests/main.test.js index 581411e..22bbedd 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -2,7 +2,6 @@ // module config var should = require('should'), - validator = require('validator'), _ = require('lodash') _.mixin(require('lodash-uuid'))
