diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/common/models/acl.js b/common/models/acl.js index c94e29fbc..fdbdddf40 100644 --- a/common/models/acl.js +++ b/common/models/acl.js @@ -600,11 +600,13 @@ module.exports = function(ACL) { break; case ACL.USER: this.userModel.findOne( - {where: {or: [{username: id}, {email: id}, {id: id}]}}, cb); + {where: {or: [{username: id}, {email: id}, {id: id}]}}, cb + ); break; case ACL.APP: this.applicationModel.findOne( - {where: {or: [{name: id}, {email: id}, {id: id}]}}, cb); + {where: {or: [{name: id}, {email: id}, {id: id}]}}, cb + ); break; default: // try resolving a user model with a name matching the principalType @@ -612,7 +614,8 @@ module.exports = function(ACL) { if (userModel) { userModel.findOne( {where: {or: [{username: id}, {email: id}, {id: id}]}}, - cb); + cb + ); } else { process.nextTick(function() { var err = new Error(g.f('Invalid principal type: %s', type)); diff --git a/common/models/change.js b/common/models/change.js index 246a36c5e..ff926200f 100644 --- a/common/models/change.js +++ b/common/models/change.js @@ -502,7 +502,8 @@ module.exports = function(Change) { async.each( changes, function(c, next) { c.rectify(next); }, - cb); + cb + ); }); }; @@ -691,8 +692,10 @@ module.exports = function(Change) { conflict.SourceModel.updateLastChange( conflict.modelId, {prev: targetChange.rev}, - cb); - }); + cb + ); + } + ); }; /** @@ -724,7 +727,8 @@ module.exports = function(Change) { } var inst = new conflict.SourceModel( target.toObject(), - {persisted: true}); + {persisted: true} + ); inst.save(done); }); diff --git a/common/models/key-value-model.js b/common/models/key-value-model.js index 056a1cee0..dd48777cf 100644 --- a/common/models/key-value-model.js +++ b/common/models/key-value-model.js @@ -226,7 +226,8 @@ function throwNotAttached(modelName, methodName) { 'The %s method has not been setup. ' + 'The {{KeyValueModel}} has not been correctly attached ' + 'to a {{DataSource}}!', - modelName, methodName, methodName)); + modelName, methodName, methodName + )); } function convertNullToNotFoundError(ctx, cb) { diff --git a/common/models/scope.js b/common/models/scope.js index 01cb52e08..1c1194587 100644 --- a/common/models/scope.js +++ b/common/models/scope.js @@ -47,7 +47,8 @@ module.exports = function(Scope) { if (callback) callback(err); } else { aclModel.checkPermission( - aclModel.SCOPE, scope.id, model, property, accessType, callback); + aclModel.SCOPE, scope.id, model, property, accessType, callback + ); } }); }; diff --git a/common/models/user.js b/common/models/user.js index eb2b9247b..53f1ed8aa 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -744,8 +744,9 @@ module.exports = function(User) { if (!confirmMethod) { throw new Error( 'Cannot build user verification URL, ' + - 'the default confirm method is not public. ' + - 'Please provide the URL in verifyOptions.verifyHref.'); + 'the default confirm method is not public. ' + + 'Please provide the URL in verifyOptions.verifyHref.' + ); } const urlPath = joinUrlPath( @@ -1315,7 +1316,8 @@ module.exports = function(User) { // This is a programmer's error, use the default status code 500 return next(new Error( 'Invalid use of "options.setPassword". Only "password" can be ' + - 'changed when using this option.')); + 'changed when using this option.' + )); } return next(); @@ -1327,7 +1329,8 @@ module.exports = function(User) { const err = new Error( 'Changing user password via patch/replace API is not allowed. ' + - 'Use changePassword() or setPassword() instead.'); + 'Use changePassword() or setPassword() instead.' + ); err.statusCode = 401; err.code = 'PASSWORD_CHANGE_NOT_ALLOWED'; next(err); diff --git a/lib/application.js b/lib/application.js index b79bce413..d68102ea5 100644 --- a/lib/application.js +++ b/lib/application.js @@ -357,7 +357,8 @@ app.enableAuth = function(options) { var Model = app.registry.findModel(m); if (!Model) { throw new Error( - g.f('Authentication requires model %s to be defined.', m)); + g.f('Authentication requires model %s to be defined.', m) + ); } if (Model.dataSource || Model.app) return; @@ -483,7 +484,8 @@ app._verifyAuthModelRelations = function() { 'custom User subclass, but does not fix AccessToken relations ' + 'to use this new model.\n' + 'Learn more at http://ibm.biz/setup-loopback-auth', - Model.modelName, userName, userName); + Model.modelName, userName, userName + ); return; } @@ -491,7 +493,8 @@ app._verifyAuthModelRelations = function() { 'The model %j does not have "belongsTo User-like model" relation ' + 'configured.\n' + 'Learn more at http://ibm.biz/setup-loopback-auth', - Model.modelName); + Model.modelName + ); } function verifyUserRelations(Model) { @@ -504,7 +507,8 @@ app._verifyAuthModelRelations = function() { 'The app configuration follows the multiple user models setup ' + 'as described in http://ibm.biz/setup-loopback-auth', 'The built-in role resolver $owner is not currently compatible ' + - 'with this configuration and should not be used in production.'); + 'with this configuration and should not be used in production.' + ); } return; } @@ -520,7 +524,8 @@ app._verifyAuthModelRelations = function() { 'AccessToken subclass, but does not fix User relations to use this ' + 'new model.\n' + 'Learn more at http://ibm.biz/setup-loopback-auth', - Model.modelName, accessTokenName, accessTokenName); + Model.modelName, accessTokenName, accessTokenName + ); return; } @@ -528,13 +533,15 @@ app._verifyAuthModelRelations = function() { 'The model %j does not have "hasMany AccessToken-like models" relation ' + 'configured.\n' + 'Learn more at http://ibm.biz/setup-loopback-auth', - Model.modelName); + Model.modelName + ); } }; app.boot = function(options) { throw new Error( - g.f('{{`app.boot`}} was removed, use the new module {{loopback-boot}} instead')); + g.f('{{`app.boot`}} was removed, use the new module {{loopback-boot}} instead') + ); }; function dataSourcesFromConfig(name, config, connectorRegistry, registry) { diff --git a/lib/builtin-models.js b/lib/builtin-models.js index b32fbf4ad..21b82afe1 100644 --- a/lib/builtin-models.js +++ b/lib/builtin-models.js @@ -12,47 +12,58 @@ module.exports = function(registry) { registry.KeyValueModel = createModel( require('../common/models/key-value-model.json'), - require('../common/models/key-value-model.js')); + require('../common/models/key-value-model.js') + ); registry.Email = createModel( require('../common/models/email.json'), - require('../common/models/email.js')); + require('../common/models/email.js') + ); registry.Application = createModel( require('../common/models/application.json'), - require('../common/models/application.js')); + require('../common/models/application.js') + ); registry.AccessToken = createModel( require('../common/models/access-token.json'), - require('../common/models/access-token.js')); + require('../common/models/access-token.js') + ); registry.User = createModel( require('../common/models/user.json'), - require('../common/models/user.js')); + require('../common/models/user.js') + ); registry.RoleMapping = createModel( require('../common/models/role-mapping.json'), - require('../common/models/role-mapping.js')); + require('../common/models/role-mapping.js') + ); registry.Role = createModel( require('../common/models/role.json'), - require('../common/models/role.js')); + require('../common/models/role.js') + ); registry.ACL = createModel( require('../common/models/acl.json'), - require('../common/models/acl.js')); + require('../common/models/acl.js') + ); registry.Scope = createModel( require('../common/models/scope.json'), - require('../common/models/scope.js')); + require('../common/models/scope.js') + ); registry.Change = createModel( require('../common/models/change.json'), - require('../common/models/change.js')); + require('../common/models/change.js') + ); registry.Checkpoint = createModel( require('../common/models/checkpoint.json'), - require('../common/models/checkpoint.js')); + require('../common/models/checkpoint.js') + ); function createModel(definitionJson, customizeFn) { // Clone the JSON definition to allow applications diff --git a/lib/current-context.js b/lib/current-context.js index 0da89137b..4f6eb735e 100644 --- a/lib/current-context.js +++ b/lib/current-context.js @@ -15,20 +15,23 @@ module.exports = function(loopback) { throw new Error(g.f( '%s was removed in version 3.0. See %s for more details.', 'loopback.getCurrentContext()', - 'http://loopback.io/doc/en/lb2/Using-current-context.html')); + 'http://loopback.io/doc/en/lb2/Using-current-context.html' + )); }; loopback.runInContext = function(fn) { throw new Error(g.f( '%s was removed in version 3.0. See %s for more details.', 'loopback.runInContext()', - 'http://loopback.io/doc/en/lb2/Using-current-context.html')); + 'http://loopback.io/doc/en/lb2/Using-current-context.html' + )); }; loopback.createContext = function(scopeName) { throw new Error(g.f( '%s was removed in version 3.0. See %s for more details.', 'loopback.createContext()', - 'http://loopback.io/doc/en/lb2/Using-current-context.html')); + 'http://loopback.io/doc/en/lb2/Using-current-context.html' + )); }; }; diff --git a/lib/model.js b/lib/model.js index f27c04ee4..eb955619b 100644 --- a/lib/model.js +++ b/lib/model.js @@ -251,11 +251,13 @@ module.exports = function(registry) { if ('injectOptionsFromRemoteContext' in options) { console.warn(g.f( '%s is using model setting %s which is no longer available.', - typeName, 'injectOptionsFromRemoteContext')); + typeName, 'injectOptionsFromRemoteContext' + )); console.warn(g.f( 'Please rework your app to use the offical solution for injecting ' + '"options" argument from request context,\nsee %s', - 'http://loopback.io/doc/en/lb3/Using-current-context.html')); + 'http://loopback.io/doc/en/lb3/Using-current-context.html' + )); } // resolve relation functions diff --git a/lib/persisted-model.js b/lib/persisted-model.js index 367e27a9c..b63576c2b 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -1231,7 +1231,8 @@ module.exports = function(registry) { function(filter, pagingCallback) { sourceModel.changes(since.source, filter, pagingCallback); }, - debug.enabled ? log : cb); + debug.enabled ? log : cb + ); function log(err, result) { if (err) return cb(err); @@ -1248,7 +1249,8 @@ module.exports = function(registry) { function(smallArray, chunkCallback) { return targetModel.diff(since.target, smallArray, chunkCallback); }, - debug.enabled ? log : cb); + debug.enabled ? log : cb + ); function log(err, result) { if (err) return cb(err); @@ -1276,7 +1278,8 @@ module.exports = function(registry) { function(smallArray, chunkCallback) { return sourceModel.createUpdates(smallArray, chunkCallback); }, - cb); + cb + ); } else { // nothing to replicate done(); @@ -1308,7 +1311,8 @@ module.exports = function(registry) { return cb(); } cb(err); - }); + } + ); } function checkpoints() { @@ -1526,14 +1530,16 @@ module.exports = function(registry) { return cb(new Error( g.f('Cannot apply bulk updates, ' + 'the connector does not correctly report ' + - 'the number of updated records.'))); + 'the number of updated records.') + )); default: debug('%s.updateAll modified unexpected number of instances: %j', Model.modelName, count); return cb(new Error( g.f('Bulk update failed, the connector has modified unexpected ' + - 'number of records: %s', JSON.stringify(count)))); + 'number of records: %s', JSON.stringify(count)) + )); } }); } @@ -1608,14 +1614,16 @@ module.exports = function(registry) { return cb(new Error( g.f('Cannot apply bulk updates, ' + 'the connector does not correctly report ' + - 'the number of deleted records.'))); + 'the number of deleted records.') + )); default: debug('%s.deleteAll modified unexpected number of instances: %j', Model.modelName, count); return cb(new Error( g.f('Bulk update failed, the connector has deleted unexpected ' + - 'number of records: %s', JSON.stringify(count)))); + 'number of records: %s', JSON.stringify(count)) + )); } }); } @@ -1770,7 +1778,8 @@ module.exports = function(registry) { const additionalChangeModelProperties = this.settings.additionalChangeModelProperties || {}; - this.Change = BaseChangeModel.extend(this.modelName + '-change', + this.Change = BaseChangeModel.extend( + this.modelName + '-change', additionalChangeModelProperties, {trackModel: this} ); diff --git a/lib/registry.js b/lib/registry.js index a95df9dd6..c566cdbd4 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -244,7 +244,8 @@ Registry.prototype.configureModel = function(ModelCtor, config) { g.warn( 'The configuration of `%s` is missing {{`dataSource`}} property.\n' + 'Use `null` or `false` to mark models not attached to any data source.', - modelName); + modelName + ); } var newMethodNames = config.methods && Object.keys(config.methods); @@ -253,7 +254,8 @@ Registry.prototype.configureModel = function(ModelCtor, config) { if (hasNewMethods && hasDescendants) { g.warn( 'Child models of `%s` will not inherit newly defined remote methods %s.', - modelName, newMethodNames); + modelName, newMethodNames + ); } // Remote methods diff --git a/lib/utils.js b/lib/utils.js index 828087324..29075a31a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -28,7 +28,8 @@ function createPromiseCallback() { function throwPromiseNotDefined() { throw new Error( 'Your Node runtime does support ES6 Promises. ' + - 'Set "global.Promise" to your preferred implementation of promises.'); + 'Set "global.Promise" to your preferred implementation of promises.' + ); } /** diff --git a/package.json b/package.json index f239d07c8..b6f545b84 100644 --- a/package.json +++ b/package.json @@ -68,20 +68,20 @@ "browserify": "^13.1.0", "chai": "^3.5.0", "cookie-parser": "^1.3.4", - "coveralls": "^2.11.15", + "coveralls": "^3.0.2", "dirty-chai": "^1.2.2", - "eslint": "^4.18.2", - "eslint-config-loopback": "^10.0.0", - "eslint-plugin-mocha": "^4.11.0", + "eslint": "^5.3.0", + "eslint-config-loopback": "^11.0.0", + "eslint-plugin-mocha": "^5.1.0", "express-session": "^1.14.0", "grunt": "^1.0.1", "grunt-browserify": "^5.0.0", "grunt-cli": "^1.2.0", - "grunt-contrib-uglify": "^2.0.0", + "grunt-contrib-uglify": "^3.4.0", "grunt-contrib-watch": "^1.0.0", - "grunt-eslint": "^20.1.0", + "grunt-eslint": "^21.0.0", "grunt-karma": "^2.0.0", - "grunt-mocha-test": "^0.12.7", + "grunt-mocha-test": "^0.13.3", "karma": "^1.1.2", "karma-browserify": "^5.1.1", "karma-chrome-launcher": "^1.0.1", @@ -94,13 +94,13 @@ "karma-script-launcher": "^1.0.0", "loopback-boot": "^2.7.0", "loopback-context": "^1.0.0", - "mocha": "^3.0.0", + "mocha": "^5.2.0", "nyc": "^10.1.2", "phantomjs-prebuilt": "^2.1.7", - "sinon": "^1.13.0", - "sinon-chai": "^2.8.0", + "sinon": "^6.1.4", + "sinon-chai": "^3.2.0", "strong-error-handler": "^3.0.0", - "strong-task-emitter": "^0.0.6", + "strong-task-emitter": "^0.0.8", "supertest": "^3.0.0" }, "repository": { diff --git a/server/middleware/context.js b/server/middleware/context.js index 2bb466f78..0086c9ba3 100644 --- a/server/middleware/context.js +++ b/server/middleware/context.js @@ -10,5 +10,6 @@ module.exports = function() { throw new Error(g.f( '%s middleware was removed in version 3.0. See %s for more details.', 'loopback#context', - 'http://loopback.io/doc/en/lb2/Using-current-context.html')); + 'http://loopback.io/doc/en/lb2/Using-current-context.html' + )); }; diff --git a/server/middleware/rest.js b/server/middleware/rest.js index d92c1c36f..413ef5b3d 100644 --- a/server/middleware/rest.js +++ b/server/middleware/rest.js @@ -45,7 +45,8 @@ function rest() { throw new Error(g.f( '%s was removed in version 3.0. See %s for more details.', 'remoting.context option', - 'http://loopback.io/doc/en/lb2/Using-current-context.html')); + 'http://loopback.io/doc/en/lb2/Using-current-context.html' + )); } if (app.isAuthEnabled) { diff --git a/server/middleware/token.js b/server/middleware/token.js index 1f5a17b97..167a13862 100644 --- a/server/middleware/token.js +++ b/server/middleware/token.js @@ -40,7 +40,8 @@ function rewriteUserLiteral(req, currentUserLiteral, next) { debug( 'URL %s matches current-user literal %s,' + ' but no (valid) access token was provided.', - req.url, currentUserLiteral); + req.url, currentUserLiteral + ); var e = new Error(g.f('Authorization Required')); e.status = e.statusCode = 401; diff --git a/test/access-control.integration.js b/test/access-control.integration.js index ca552556b..7dcbea146 100644 --- a/test/access-control.integration.js +++ b/test/access-control.integration.js @@ -75,10 +75,12 @@ describe('access control - integration', function() { lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', urlForUser); lt.it.shouldBeAllowedWhenCalledAnonymously( - 'POST', '/api/users', newUserData()); + 'POST', '/api/users', newUserData() + ); lt.it.shouldBeAllowedWhenCalledByUser( - CURRENT_USER, 'POST', '/api/users', newUserData()); + CURRENT_USER, 'POST', '/api/users', newUserData() + ); lt.it.shouldBeAllowedWhenCalledByUser(CURRENT_USER, 'POST', '/api/users/logout'); diff --git a/test/access-token.test.js b/test/access-token.test.js index 522b43859..1f5930981 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -144,7 +144,8 @@ describe('loopback.token(options)', function() { var app = createTestApp( this.token, {token: {searchDefaultTokenKeys: false}}, - done); + done + ); var agent = request.agent(app); // Set the token cookie @@ -604,7 +605,8 @@ describe('AccessToken', function() { param: function(name) { return this._params[name]; }, header: function(name) { return this.headers[name]; }, }, - opts); + opts + ); } }); }); diff --git a/test/app.test.js b/test/app.test.js index 26c36b895..3f5ad4d65 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -223,7 +223,8 @@ describe('app', function() { expect(steps).to.eql(['/scope', '/scope/item']); done(); - }); + } + ); }); it('scopes middleware to a regex path', function(done) { @@ -238,7 +239,8 @@ describe('app', function() { expect(steps).to.eql(['/a', '/b']); done(); - }); + } + ); }); it('scopes middleware to a list of scopes', function(done) { @@ -253,7 +255,8 @@ describe('app', function() { expect(steps).to.eql(['/a', '/b', '/scope']); done(); - }); + } + ); }); it('sets req.url to a sub-path', function(done) { @@ -537,7 +540,8 @@ describe('app', function() { { phase: 'initial', paths: ['/scope', /^\/(a|b)/], - }); + } + ); async.eachSeries( ['/', '/a', '/b', '/c', '/scope', '/other'], @@ -548,7 +552,8 @@ describe('app', function() { expect(steps).to.eql(['/a', '/b', '/scope']); done(); - }); + } + ); }); }); @@ -918,17 +923,15 @@ describe('app', function() { }); }); - it('forwards to http.Server.listen when the single arg is not a function', - function(done) { - var app = loopback(); - app.set('port', 1); - app.listen(0).on('listening', function() { - expect(app.get('port'), 'port') .to.not.equal(0).and.not.equal(1); + it('forwards to http.Server.listen when the single arg is not a function', function(done) { + var app = loopback(); + app.set('port', 1); + app.listen(0).on('listening', function() { + expect(app.get('port'), 'port') .to.not.equal(0).and.not.equal(1); - done(); - }); - } - ); + done(); + }); + }); it('uses app config when no parameter is supplied', function(done) { var app = loopback(); diff --git a/test/change.test.js b/test/change.test.js index 861aa051b..58556297b 100644 --- a/test/change.test.js +++ b/test/change.test.js @@ -222,7 +222,8 @@ describe('Change', function() { change = ch; done(err); - }); + } + ); }); it('should create a new change with the correct revision', function(done) { diff --git a/test/context-options.test.js b/test/context-options.test.js index 511856b18..82930b2d9 100644 --- a/test/context-options.test.js +++ b/test/context-options.test.js @@ -215,7 +215,8 @@ describe('OptionsFromRemotingContext', function() { Category = app.registry.createModel( 'Category', {name: String}, - {forceId: false, replaceOnPUT: true}); + {forceId: false, replaceOnPUT: true} + ); app.model(Category, {dataSource: 'db'}); // This is a shortcut for creating CategoryProduct "through" model @@ -287,7 +288,8 @@ describe('OptionsFromRemotingContext', function() { Category = app.registry.createModel( 'Category', {name: String}, - {forceId: false, replaceOnPUT: true}); + {forceId: false, replaceOnPUT: true} + ); app.model(Category, {dataSource: 'db'}); Category.hasOne(Product); @@ -331,7 +333,8 @@ describe('OptionsFromRemotingContext', function() { Category = app.registry.createModel( 'Category', {name: String}, - {forceId: false, replaceOnPUT: true}); + {forceId: false, replaceOnPUT: true} + ); app.model(Category, {dataSource: 'db'}); Category.belongsTo(Product); @@ -361,7 +364,8 @@ describe('OptionsFromRemotingContext', function() { Product = app.registry.createModel( 'Product', {name: String}, - {forceId: false, replaceOnPUT: true}); + {forceId: false, replaceOnPUT: true} + ); Product.createOptionsFromRemotingContext = function(ctx) { return {injectedFrom: 'Product'}; diff --git a/test/hidden-properties.test.js b/test/hidden-properties.test.js index b6ded4ab4..9d35ef2ca 100644 --- a/test/hidden-properties.test.js +++ b/test/hidden-properties.test.js @@ -11,7 +11,8 @@ var request = require('supertest'); describe('hidden properties', function() { beforeEach(function(done) { var app = this.app = loopback(); - var Product = this.Product = loopback.PersistedModel.extend('product', + var Product = this.Product = loopback.PersistedModel.extend( + 'product', {}, {hidden: ['secret']} ); diff --git a/test/integration.test.js b/test/integration.test.js index b8a531a32..9b3966974 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -29,7 +29,8 @@ describe('loopback application', function() { expect(res).to.match(/\nX$/); done(); - }); + } + ); }); function setupAppWithStreamingMethod() { diff --git a/test/multiple-user-principal-types.test.js b/test/multiple-user-principal-types.test.js index bedf5f682..c49de9eb5 100644 --- a/test/multiple-user-principal-types.test.js +++ b/test/multiple-user-principal-types.test.js @@ -285,7 +285,8 @@ describe('Multiple users with custom principalType', function() { describe('role.users()', function() { it('returns users when using custom user principalType', function() { return userRole.principals.create( - {principalType: OneUser.modelName, principalId: userFromOneModel.id}) + {principalType: OneUser.modelName, principalId: userFromOneModel.id} + ) .then(function() { return userRole.users({where: {principalType: OneUser.modelName}}); }) @@ -297,7 +298,8 @@ describe('Multiple users with custom principalType', function() { it('returns empty array when using invalid principalType', function() { return userRole.principals.create( - {principalType: 'invalidModelName', principalId: userFromOneModel.id}) + {principalType: 'invalidModelName', principalId: userFromOneModel.id} + ) .then(function() { return userRole.users({where: {principalType: 'invalidModelName'}}); }) @@ -310,24 +312,22 @@ describe('Multiple users with custom principalType', function() { describe('principal.user()', function() { it('returns the correct user instance', function() { return userRole.principals.create( - {principalType: OneUser.modelName, principalId: userFromOneModel.id}) - .then(function(principal) { - return principal.user(); - }) - .then(function(user) { - expect(user).to.have.property('id', userFromOneModel.id); - }); + {principalType: OneUser.modelName, principalId: userFromOneModel.id} + ).then(function(principal) { + return principal.user(); + }).then(function(user) { + expect(user).to.have.property('id', userFromOneModel.id); + }); }); it('returns null when created with invalid principalType', function() { return userRole.principals.create( - {principalType: 'invalidModelName', principalId: userFromOneModel.id}) - .then(function(principal) { - return principal.user(); - }) - .then(function(user) { - expect(user).to.not.exist(); - }); + {principalType: 'invalidModelName', principalId: userFromOneModel.id} + ).then(function(principal) { + return principal.user(); + }).then(function(user) { + expect(user).to.not.exist(); + }); }); }); @@ -346,14 +346,14 @@ describe('Multiple users with custom principalType', function() { it('supports getRoles()', function() { return Role.getRoles( - userOneBaseContext) - .then(function(roles) { - expect(roles).to.eql([ - Role.AUTHENTICATED, - Role.EVERYONE, - userRole.id, - ]); - }); + userOneBaseContext + ).then(function(roles) { + expect(roles).to.eql([ + Role.AUTHENTICATED, + Role.EVERYONE, + userRole.id, + ]); + }); }); }); diff --git a/test/relations.integration.js b/test/relations.integration.js index 0d9432b29..b8b77f874 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -72,8 +72,7 @@ describe('relations - integration', function() { reader.team(test.team); reader.save(done); }); - } - ); + }); }); after(function(done) { @@ -784,7 +783,8 @@ describe('relations - integration', function() { describe('embedsOne', function() { before(function defineGroupAndPosterModels() { - var group = app.registry.createModel('group', + var group = app.registry.createModel( + 'group', {name: 'string'}, {plural: 'groups'} ); diff --git a/test/remoting-coercion.test.js b/test/remoting-coercion.test.js index 3909085e9..e0656ff62 100644 --- a/test/remoting-coercion.test.js +++ b/test/remoting-coercion.test.js @@ -16,8 +16,7 @@ describe('remoting coercion', function() { var TestModel = app.registry.createModel('TestModel', {}, - {base: 'Model'} - ); + {base: 'Model'}); app.model(TestModel, {public: true}); TestModel.test = function(inst, cb) { diff --git a/test/replication.rest.test.js b/test/replication.rest.test.js index 72f94e31b..f8f0ab4cb 100644 --- a/test/replication.rest.test.js +++ b/test/replication.rest.test.js @@ -192,7 +192,8 @@ describe('Replication over REST', function() { var conflict = new LocalConflict( conflictedCarId, LocalCar, - RemoteCar); + RemoteCar + ); conflict.resolveUsingSource(expectHttpError(401, done)); }); @@ -201,7 +202,8 @@ describe('Replication over REST', function() { var conflict = new RemoteConflict( conflictedCarId, RemoteCar, - LocalCar); + LocalCar + ); conflict.resolveUsingSource(expectHttpError(401, done)); }); }); @@ -216,7 +218,8 @@ describe('Replication over REST', function() { var conflict = new LocalConflict( conflictedCarId, LocalCar, - RemoteCar); + RemoteCar + ); conflict.resolveUsingSource(done); }); @@ -225,7 +228,8 @@ describe('Replication over REST', function() { var conflict = new RemoteConflict( conflictedCarId, RemoteCar, - LocalCar); + LocalCar + ); conflict.resolveUsingSource(expectHttpError(401, done)); }); }); @@ -403,7 +407,8 @@ describe('Replication over REST', function() { LocalUser.updateAll( {id: aliceId}, {fullname: 'Alice Smith'}, - done); + done + ); }); } }); @@ -606,7 +611,8 @@ describe('Replication over REST', function() { serverCars = cars.map(carToString); next(); - }); + } + ); }, ], done); } @@ -625,7 +631,8 @@ describe('Replication over REST', function() { clientCars = cars.map(carToString); next(); - }); + } + ); }, ], done); } diff --git a/test/replication.test.js b/test/replication.test.js index 120ef8d07..e97aeb40e 100644 --- a/test/replication.test.js +++ b/test/replication.test.js @@ -30,14 +30,16 @@ describe('Replication / Change APIs', function() { SourceModel = this.SourceModel = PersistedModel.extend( 'SourceModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); SourceModel.attachTo(dataSource); TargetModel = this.TargetModel = PersistedModel.extend( 'TargetModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); // NOTE(bajtos) At the moment, all models share the same Checkpoint // model. This causes the in-process replication to work differently @@ -83,7 +85,8 @@ describe('Replication / Change APIs', function() { Model = this.Model = PersistedModel.extend( 'Model-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true, changeCleanupInterval: -1}); + {trackChanges: true, changeCleanupInterval: -1} + ); Model.attachTo(dataSource); }); @@ -102,7 +105,8 @@ describe('Replication / Change APIs', function() { Model = this.Model = PersistedModel.extend( 'Model-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true, changeCleanupInterval: 10000}); + {trackChanges: true, changeCleanupInterval: 10000} + ); Model.attachTo(dataSource); }); @@ -538,7 +542,8 @@ describe('Replication / Change APIs', function() { }); cb(); - }); + } + ); }, ], done); @@ -581,7 +586,8 @@ describe('Replication / Change APIs', function() { expect(changes).to.have.length(0); done(); - }); + } + ); }); }, ], done); @@ -603,7 +609,8 @@ describe('Replication / Change APIs', function() { TargetModel.modelName, '1', {name: '3rd-party'}, - cb); + cb + ); } else { // 2.x connectors require `options` connector.updateAttributes( @@ -611,7 +618,8 @@ describe('Replication / Change APIs', function() { '1', {name: '3rd-party'}, {}, // options - cb); + cb + ); } }); @@ -625,7 +633,8 @@ describe('Replication / Change APIs', function() { // resolve the conflict using ours conflicts[0].resolve(next); - }); + } + ); }, replicateExpectingSuccess(), @@ -645,14 +654,16 @@ describe('Replication / Change APIs', function() { connector.create( TargetModel.modelName, {id: '1', name: '3rd-party'}, - cb); + cb + ); } else { // 2.x connectors require `options` connector.create( TargetModel.modelName, {id: '1', name: '3rd-party'}, {}, // options - cb); + cb + ); } }); @@ -666,7 +677,8 @@ describe('Replication / Change APIs', function() { // resolve the conflict using ours conflicts[0].resolve(next); - }); + } + ); }, replicateExpectingSuccess(), @@ -689,7 +701,8 @@ describe('Replication / Change APIs', function() { TargetModel.modelName, '1', {name: '3rd-party'}, - cb); + cb + ); } else { // 2.x connectors require `options` connector.updateAttributes( @@ -697,7 +710,8 @@ describe('Replication / Change APIs', function() { '1', {name: '3rd-party'}, {}, // options - cb); + cb + ); } }); @@ -711,7 +725,8 @@ describe('Replication / Change APIs', function() { // resolve the conflict using ours conflicts[0].resolve(next); - }); + } + ); }, replicateExpectingSuccess(), @@ -733,14 +748,16 @@ describe('Replication / Change APIs', function() { connector.destroy( TargetModel.modelName, '1', - cb); + cb + ); } else { // 2.x connectors require `options` connector.destroy( TargetModel.modelName, '1', {}, // options - cb); + cb + ); } }); @@ -1061,7 +1078,8 @@ describe('Replication / Change APIs', function() { function(err) { if (err) return done(err); assertChangeRecordedForId(inst.id, done); - }); + } + ); }); }); @@ -1098,7 +1116,8 @@ describe('Replication / Change APIs', function() { if (err) return done(err); assertChangeRecordedForId(inst.id, done); - }); + } + ); }); it('detects "deleteById"', function(done) { @@ -1134,7 +1153,8 @@ describe('Replication / Change APIs', function() { if (err) return done(err); assertChangeRecordedForId(inst.id, done); - }); + } + ); }); }); @@ -1229,7 +1249,8 @@ describe('Replication / Change APIs', function() { AnotherModel = this.AnotherModel = PersistedModel.extend( 'AnotherModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); // NOTE(bajtos) At the moment, all models share the same Checkpoint // model. This causes the in-process replication to work differently @@ -1388,7 +1409,8 @@ describe('Replication / Change APIs', function() { function resolveUsingOurs(conflict, cb) { conflict.resolveUsingSource(cb); }, - done); + done + ); }); it('handles UPDATE conflict resolved using "theirs"', function(done) { @@ -1399,7 +1421,8 @@ describe('Replication / Change APIs', function() { .to.equal(ClientB.modelName); conflict.resolveUsingTarget(cb); }, - done); + done + ); }); it('handles UPDATE conflict resolved manually', function(done) { @@ -1407,7 +1430,8 @@ describe('Replication / Change APIs', function() { function resolveManually(conflict, cb) { conflict.resolveManually({name: 'manual'}, cb); }, - done); + done + ); }); it('handles DELETE conflict resolved using "ours"', function(done) { @@ -1415,7 +1439,8 @@ describe('Replication / Change APIs', function() { function resolveUsingOurs(conflict, cb) { conflict.resolveUsingSource(cb); }, - done); + done + ); }); it('handles DELETE conflict resolved using "theirs"', function(done) { @@ -1426,7 +1451,8 @@ describe('Replication / Change APIs', function() { .to.equal(ClientB.modelName); conflict.resolveUsingTarget(cb); }, - done); + done + ); }); it('handles DELETE conflict resolved as manual delete', function(done) { @@ -1434,7 +1460,8 @@ describe('Replication / Change APIs', function() { function resolveManually(conflict, cb) { conflict.resolveManually(null, cb); }, - done); + done + ); }); it('handles DELETE conflict resolved manually', function(done) { @@ -1442,7 +1469,8 @@ describe('Replication / Change APIs', function() { function resolveManually(conflict, cb) { conflict.resolveManually({name: 'manual'}, cb); }, - done); + done + ); }); }); @@ -1585,7 +1613,8 @@ describe('Replication / Change APIs', function() { OptionsSourceModel = PersistedModel.extend( 'OptionsSourceModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); OptionsSourceModel.attachTo(dataSource); @@ -1631,8 +1660,7 @@ describe('Replication / Change APIs', function() { expect(syncPropertyExists).to.eql(true); done(); - } - ); + }); }); }); @@ -1670,14 +1698,16 @@ describe('Replication / Change APIs', function() { SourceModel = this.SourceModel = PersistedModel.extend( 'SourceModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true, replicationChunkSize: 1}); + {trackChanges: true, replicationChunkSize: 1} + ); SourceModel.attachTo(dataSource); TargetModel = this.TargetModel = PersistedModel.extend( 'TargetModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true, replicationChunkSize: 1}); + {trackChanges: true, replicationChunkSize: 1} + ); var TargetChange = TargetModel.Change; TargetChange.Checkpoint = loopback.Checkpoint.extend('TargetCheckpoint'); @@ -1716,14 +1746,16 @@ describe('Replication / Change APIs', function() { SourceModel = this.SourceModel = PersistedModel.extend( 'SourceModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); SourceModel.attachTo(dataSource); TargetModel = this.TargetModel = PersistedModel.extend( 'TargetModel-' + tid, {id: {id: true, type: String, defaultFn: 'guid'}}, - {trackChanges: true}); + {trackChanges: true} + ); var TargetChange = TargetModel.Change; TargetChange.Checkpoint = loopback.Checkpoint.extend('TargetCheckpoint'); @@ -1928,7 +1960,8 @@ describe('Replication / Change APIs with custom change properties', function() { { trackChanges: true, additionalChangeModelProperties: {customProperty: {type: 'string'}}, - }); + } + ); SourceModel.createChangeFilter = function(since, modelFilter) { const filter = this.base.createChangeFilter.apply(this, arguments); @@ -1958,7 +1991,8 @@ describe('Replication / Change APIs with custom change properties', function() { { trackChanges: true, additionalChangeModelProperties: {customProperty: {type: 'string'}}, - }); + } + ); var ChangeModelForTarget = TargetModel.Change; ChangeModelForTarget.Checkpoint = loopback.Checkpoint.extend('TargetCheckpoint'); @@ -1997,7 +2031,8 @@ describe('Replication / Change APIs with custom change properties', function() { }, }); done(); - }); + } + ); }); it('query returns the matching changes', function(done) { @@ -2008,7 +2043,8 @@ describe('Replication / Change APIs with custom change properties', function() { expect(changes).to.have.length(1); expect(changes[0]).to.have.property('customProperty', '123'); done(); - }); + } + ); }); function givenSomeSourceModelInstances(done) { diff --git a/test/role-mapping.test.js b/test/role-mapping.test.js index 39189055f..a2d043d2e 100644 --- a/test/role-mapping.test.js +++ b/test/role-mapping.test.js @@ -55,7 +55,8 @@ describe('role-mapping model', function() { expect(user.id).to.equal(oneUser.id); done(); }); - }); + } + ); }); it('supports .user() returning a promise', function() { @@ -78,7 +79,8 @@ describe('role-mapping model', function() { expect(app.id).to.equal(anApp.id); done(); }); - }); + } + ); }); it('supports .application() returning a promise', function() { @@ -101,7 +103,8 @@ describe('role-mapping model', function() { expect(role.id).to.equal(aRole.id); done(); }); - }); + } + ); }); it('supports .childRole() returning a promise', function() { diff --git a/test/role.test.js b/test/role.test.js index 097743dfa..ba3e5024d 100644 --- a/test/role.test.js +++ b/test/role.test.js @@ -92,7 +92,8 @@ describe('role model', function() { }); }, ], done); - }); + } + ); }); }); }); @@ -223,7 +224,8 @@ describe('role model', function() { // but the matchin role object instead assert(!!inRole); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -233,7 +235,8 @@ describe('role model', function() { if (err) return next(err); assert(!inRole); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -243,7 +246,8 @@ describe('role model', function() { if (err) return next(err); assert(!inRole); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -256,7 +260,8 @@ describe('role model', function() { role.id, ]); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -270,7 +275,8 @@ describe('role model', function() { role.name, ]); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -282,7 +288,8 @@ describe('role model', function() { Role.EVERYONE, ]); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -294,7 +301,8 @@ describe('role model', function() { Role.EVERYONE, ]); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -306,7 +314,8 @@ describe('role model', function() { Role.EVERYONE, ]); next(); - }); + } + ); }, ], done); }); @@ -391,7 +400,8 @@ describe('role model', function() { if (err) return next(err); assert(!!inRole); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -401,7 +411,8 @@ describe('role model', function() { if (err) return next(err); assert(!inRole); next(); - }); + } + ); }, function(next) { Role.getRoles( @@ -414,7 +425,8 @@ describe('role model', function() { role.id, ]); next(); - }); + } + ); }, ], done); }); @@ -457,7 +469,8 @@ describe('role model', function() { if (err) return next(err); assert(yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -467,7 +480,8 @@ describe('role model', function() { if (err) next(err); assert(yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -477,7 +491,8 @@ describe('role model', function() { if (err) next(err); assert(!yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -487,7 +502,8 @@ describe('role model', function() { if (err) return next(err); assert(!yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -497,7 +513,8 @@ describe('role model', function() { if (err) return next(err); assert(yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -507,7 +524,8 @@ describe('role model', function() { if (err) return next(err); assert(yes); next(); - }); + } + ); }, function(next) { Role.isInRole( @@ -517,7 +535,8 @@ describe('role model', function() { if (err) return next(err); assert(yes); next(); - }); + } + ); }, function(next) { Album.create({name: 'Album 1', userId: user.id}, function(err, album1) { @@ -1073,7 +1092,8 @@ describe('role model', function() { function(err, p) { if (err) return callback(err); callback(p); - }); + } + ); }, function(callback) { roles[1].principals.create( @@ -1081,7 +1101,8 @@ describe('role model', function() { function(err, p) { if (err) return callback(err); callback(p); - }); + } + ); }], function(err, principles) { next(null, models, roles, principles); diff --git a/test/user-password.test.js b/test/user-password.test.js index 87e56951b..6559c023b 100644 --- a/test/user-password.test.js +++ b/test/user-password.test.js @@ -88,7 +88,8 @@ describe('User.password', () => { }, function onError(err) { expect(err.message).to.match(/Invalid use.*options.setPassword/); - }); + } + ); }); function givenAppWithRejectionEnabled() { @@ -237,6 +238,7 @@ describe('User.password', () => { function patchNameAndPasswordDirectly() { return testUser.patchAttributes( {password: 'new-pass', name: 'New Name'}, - {setPassword: true}); + {setPassword: true} + ); } }); diff --git a/test/user.test.js b/test/user.test.js index de7841bc5..c5fe0b0d9 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -147,7 +147,8 @@ describe('User', function() { expect(err.statusCode).to.equal(422); expect(err.details.context).to.equal(User.modelName); expect(err.details.codes.email).to.deep.equal(['presence']); - }); + } + ); }); it('fails when the required email is missing (case-sensitivity off)', () => { @@ -160,7 +161,8 @@ describe('User', function() { expect(err.statusCode).to.equal(422); expect(err.details.context).to.equal(User.modelName); expect(err.details.codes.email).to.deep.equal(['presence']); - }); + } + ); }); // will change in future versions where password will be optional by default @@ -547,7 +549,8 @@ describe('User', function() { code: 'PASSWORD_TOO_LONG', statusCode: 422, }); - }); + } + ); }); it('rejects setPassword when new password is longer than 72 chars', function() { @@ -566,7 +569,8 @@ describe('User', function() { code: 'PASSWORD_TOO_LONG', statusCode: 422, }); - }); + } + ); }); }); @@ -1463,7 +1467,8 @@ describe('User', function() { code: 'INVALID_PASSWORD', statusCode: 400, }); - }); + } + ); }); it('fails with 401 for unknown user id', () => { @@ -1478,7 +1483,8 @@ describe('User', function() { code: 'USER_NOT_FOUND', statusCode: 401, }); - }); + } + ); }); it('forwards the "options" argument', () => { @@ -1565,7 +1571,8 @@ describe('User', function() { code: 'USER_NOT_FOUND', statusCode: 401, }); - }); + } + ); }); it('forwards the "options" argument', () => { @@ -2601,7 +2608,8 @@ describe('User', function() { function(err, userInstance) { if (err) return done(err); assertNoAccessTokens(done); - }); + } + ); }); it('invalidates sessions after `replaceAttributes`', function(done) { @@ -2718,7 +2726,8 @@ describe('User', function() { if (err) return next(err); userPartial = partialInstance; next(); - }); + } + ); }, function loginPartiallUser(next) { User.login({email: 'partial@example.com', password: 'pass1'}, function(err, ats) { @@ -2733,7 +2742,8 @@ describe('User', function() { function(err, info) { if (err) return next(err); next(); - }); + } + ); }, function verifyTokensOfPartialUser(next) { AccessToken.find({where: {userId: userPartial.pk}}, function(err, tokens1) { @@ -2777,8 +2787,10 @@ describe('User', function() { if (err) return next(err); next(); }); - }); - }); + } + ); + } + ); }, function(next) { user2.updateAttribute('email', 'user2Update@b.com', function(err, userInstance) { @@ -2816,7 +2828,8 @@ describe('User', function() { if (err) return next(err); userSpecial = specialInstance; next(); - }); + } + ); }, function loginSpecialUser(next) { User.login({email: 'special@example.com', password: 'pass1'}, function(err, ats) { @@ -2830,7 +2843,8 @@ describe('User', function() { {email: 'superspecial@example.com'}, function(err, info) { if (err) return next(err); next(); - }); + } + ); }, function verifyTokensOfSpecialUser(next) { AccessToken.find({where: {userId: userSpecial.pk}}, function(err, tokens1) {