From 918497c365aff1829ebbc0338a4bb221c23ae347 Mon Sep 17 00:00:00 2001 From: Rob Halff Date: Fri, 21 Nov 2014 02:46:21 +0100 Subject: [PATCH] singlequote, semicolon & /*jshint -W030 */ --- test/access-control.integration.js | 8 +- test/access-token.test.js | 4 +- test/acl.test.js | 51 +++--- test/app.test.js | 18 ++- test/data-source.test.js | 20 +-- test/geo-point.test.js | 12 +- test/hidden-properties.test.js | 8 +- test/loopback.test.js | 4 +- test/model.test.js | 76 ++++----- test/relations.integration.js | 252 +++++++++++++++-------------- test/remote-connector.test.js | 2 +- test/remoting-coercion.test.js | 4 +- test/remoting.integration.js | 22 +-- test/role.test.js | 10 +- test/support.js | 6 +- test/user.test.js | 86 +++++----- test/util/model-tests.js | 41 +++-- 17 files changed, 313 insertions(+), 311 deletions(-) diff --git a/test/access-control.integration.js b/test/access-control.integration.js index 28e48031..ab663c03 100644 --- a/test/access-control.integration.js +++ b/test/access-control.integration.js @@ -1,3 +1,5 @@ +/*jshint -W030 */ + var loopback = require('../'); var lt = require('loopback-testing'); var path = require('path'); @@ -20,7 +22,7 @@ describe('access control - integration', function () { it('should have a validate method', function () { var token = new app.models.accessToken; - assert.equal(typeof token.validate, 'function'); + assert.equal(typeof token.validate, 'function'); }); }); @@ -65,7 +67,7 @@ describe('access control - integration', function () { lt.it.shouldBeDeniedWhenCalledAnonymously('GET', '/api/users'); lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', '/api/users'); lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', '/api/users'); - + lt.it.shouldBeDeniedWhenCalledAnonymously('GET', urlForUser); lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', urlForUser); lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER,'GET', urlForUser); @@ -224,5 +226,5 @@ describe('access control - integration', function () { return '/api/accounts/' + this.account.id; } }); - + }); diff --git a/test/access-token.test.js b/test/access-token.test.js index 14905b75..7d8d75e0 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -257,8 +257,8 @@ function createTestApp(testToken, settings, done) { var modelOptions = { acls: [ { - principalType: "ROLE", - principalId: "$everyone", + principalType: 'ROLE', + principalId: '$everyone', accessType: ACL.ALL, permission: ACL.DENY, property: 'deleteById' diff --git a/test/acl.test.js b/test/acl.test.js index 1c159f25..7be89aa9 100644 --- a/test/acl.test.js +++ b/test/acl.test.js @@ -29,7 +29,7 @@ describe('security scopes', function () { testModel.attachTo(ds); }); - it("should allow access to models for the given scope by wildcard", function () { + it('should allow access to models for the given scope by wildcard', function () { Scope.create({name: 'userScope', description: 'access user information'}, function (err, scope) { ACL.create({principalType: ACL.SCOPE, principalId: scope.id, model: 'User', property: ACL.ALL, accessType: ACL.ALL, permission: ACL.ALLOW}, @@ -42,7 +42,7 @@ describe('security scopes', function () { }); - it("should allow access to models for the given scope", function () { + it('should allow access to models for the given scope', function () { Scope.create({name: 'testModelScope', description: 'access testModel information'}, function (err, scope) { ACL.create({principalType: ACL.SCOPE, principalId: scope.id, model: 'testModel', property: 'name', accessType: ACL.READ, permission: ACL.ALLOW}, @@ -75,25 +75,25 @@ describe('security ACLs', function () { it('should order ACL entries based on the matching score', function() { var acls = [ { - "model": "account", - "accessType": "*", - "permission": "DENY", - "principalType": "ROLE", - "principalId": "$everyone" + 'model': 'account', + 'accessType': '*', + 'permission': 'DENY', + 'principalType': 'ROLE', + 'principalId': '$everyone' }, { - "model": "account", - "accessType": "*", - "permission": "ALLOW", - "principalType": "ROLE", - "principalId": "$owner" + 'model': 'account', + 'accessType': '*', + 'permission': 'ALLOW', + 'principalType': 'ROLE', + 'principalId': '$owner' }, { - "model": "account", - "accessType": "READ", - "permission": "ALLOW", - "principalType": "ROLE", - "principalId": "$everyone" + 'model': 'account', + 'accessType': 'READ', + 'permission': 'ALLOW', + 'principalType': 'ROLE', + 'principalId': '$everyone' }]; var req = { model: 'account', @@ -101,7 +101,7 @@ describe('security ACLs', function () { accessType: 'WRITE' }; - acls = acls.map(function(a) { return new ACL(a)}); + acls = acls.map(function(a) { return new ACL(a); }); var perm = ACL.resolvePermission(acls, req); assert.deepEqual(perm, { model: 'account', @@ -111,7 +111,7 @@ describe('security ACLs', function () { methodNames: []}); }); - it("should allow access to models for the given principal by wildcard", function () { + it('should allow access to models for the given principal by wildcard', function () { ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'User', property: ACL.ALL, accessType: ACL.ALL, permission: ACL.ALLOW}, function (err, acl) { @@ -132,7 +132,7 @@ describe('security ACLs', function () { }); - it("should allow access to models by exception", function () { + it('should allow access to models by exception', function () { ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'testModel', property: ACL.ALL, accessType: ACL.ALL, permission: ACL.DENY}, function (err, acl) { @@ -161,7 +161,7 @@ describe('security ACLs', function () { }); - it("should honor defaultPermission from the model", function () { + it('should honor defaultPermission from the model', function () { var Customer = ds.createModel('Customer', { name: { type: String, @@ -192,7 +192,7 @@ describe('security ACLs', function () { }); - it("should honor static ACLs from the model", function () { + it('should honor static ACLs from the model', function () { var Customer = ds.createModel('Customer', { name: { type: String, @@ -227,7 +227,7 @@ describe('security ACLs', function () { }); - it("should filter static ACLs by model/property", function() { + it('should filter static ACLs by model/property', function() { var Model1 = ds.createModel('Model1', { name: { type: String, @@ -254,7 +254,7 @@ describe('security ACLs', function () { assert(staticACLs.length === 1); }); - it("should check access against LDL, ACL, and Role", function () { + it('should check access against LDL, ACL, and Role', function () { // var log = console.log; var log = function() {}; @@ -327,6 +327,3 @@ describe('security ACLs', function () { }); }); }); - - - diff --git a/test/app.test.js b/test/app.test.js index 073bf149..550cf59a 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,3 +1,5 @@ +/*jshint -W030 */ + var async = require('async'); var path = require('path'); @@ -39,7 +41,7 @@ describe('app', function() { }); }); - it('supports "before:" and "after:" prefixes', function(done) { + it('supports `before:` and `after:` prefixes', function(done) { app.middleware('routes:before', namedHandler('routes:before')); app.middleware('routes:after', namedHandler('routes:after')); app.use(namedHandler('main')); @@ -247,7 +249,7 @@ describe('app', function() { app = loopback(); }); - it('adds the phase just before "routes" by default', function(done) { + it('adds the phase just before `routes` by default', function(done) { app.defineMiddlewarePhases('custom'); verifyMiddlewarePhases(['custom', 'routes'], done); }); @@ -311,7 +313,7 @@ describe('app', function() { db = loopback.createDataSource({connector: loopback.Memory}); }); - it("Expose a `Model` to remote clients", function() { + it('Expose a `Model` to remote clients', function() { var Color = PersistedModel.extend('color', {name: String}); app.model(Color); Color.attachTo(db); @@ -330,7 +332,7 @@ describe('app', function() { var Color = PersistedModel.extend('color', {name: String}); app.model(Color); Color.attachTo(db); - var classes = app.remotes().classes().map(function(c) {return c.name}); + var classes = app.remotes().classes().map(function(c) {return c.name;}); expect(classes).to.contain('color'); }); @@ -343,7 +345,7 @@ describe('app', function() { expect(app.models.Color).to.equal(Color); }); - it("emits a `modelRemoted` event", function() { + it('emits a `modelRemoted` event', function() { var Color = PersistedModel.extend('color', {name: String}); Color.shared = true; var remotedClass; @@ -493,7 +495,7 @@ describe('app', function() { .expect(200, done); }); - it('updates port on "listening" event', function(done) { + it('updates port on `listening` event', function(done) { var app = loopback(); app.set('port', 0); @@ -503,7 +505,7 @@ describe('app', function() { }); }); - it('updates "url" on "listening" event', function(done) { + it('updates `url` on `listening` event', function(done) { var app = loopback(); app.set('port', 0); app.set('host', undefined); @@ -559,7 +561,7 @@ describe('app', function() { }); }); - describe.onServer('app.get("/", loopback.status())', function () { + describe.onServer('app.get('/', loopback.status())', function () { it('should return the status of the application', function (done) { var app = loopback(); app.get('/', loopback.status()); diff --git a/test/data-source.test.js b/test/data-source.test.js index 113c3025..438f1fde 100644 --- a/test/data-source.test.js +++ b/test/data-source.test.js @@ -1,16 +1,16 @@ describe('DataSource', function() { var memory; - + beforeEach(function(){ memory = loopback.createDataSource({ connector: loopback.Memory }); - + assertValidDataSource(memory); }); describe('dataSource.createModel(name, properties, settings)', function() { - it("Define a model and attach it to a `DataSource`", function() { + it('Define a model and attach it to a `DataSource`', function() { var Color = memory.createModel('color', {name: String}); assert.isFunc(Color, 'find'); assert.isFunc(Color, 'findById'); @@ -31,23 +31,23 @@ describe('DataSource', function() { assert.isFunc(Color.prototype, 'destroy'); assert.isFunc(Color.prototype, 'updateAttribute'); assert.isFunc(Color.prototype, 'updateAttributes'); - assert.isFunc(Color.prototype, 'reload'); + assert.isFunc(Color.prototype, 'reload'); }); - it("should honor settings.base", function() { + it('should honor settings.base', function() { var Base = memory.createModel('base'); var Color = memory.createModel('color', {name: String}, {base: Base}); assert(Color.prototype instanceof Base); assert.equal(Color.base, Base); }); - it("should use loopback.PersistedModel as the base for DBs", function() { + it('should use loopback.PersistedModel as the base for DBs', function() { var Color = memory.createModel('color', {name: String}); assert(Color.prototype instanceof loopback.PersistedModel); assert.equal(Color.base, loopback.PersistedModel); }); - it("should use loopback.Model as the base for non DBs", function() { + it('should use loopback.Model as the base for non DBs', function() { // Mock up a non-DB connector var Connector = function() { }; @@ -67,10 +67,10 @@ describe('DataSource', function() { }); describe.skip('PersistedModel Methods', function() { - it("List the enabled and disabled methods", function() { + it('List the enabled and disabled methods', function() { var TestModel = loopback.PersistedModel.extend('TestPersistedModel'); TestModel.attachTo(loopback.memory()); - + // assert the defaults // - true: the method should be remote enabled // - false: the method should not be remote enabled @@ -97,7 +97,7 @@ describe('DataSource', function() { existsAndShared('updateAttributes', true); existsAndShared('updateAll', true); existsAndShared('reload', false); - + function existsAndShared(Model, name, isRemoteEnabled, isProto) { var scope = isProto ? Model.prototype : Model; var fn = scope[name]; diff --git a/test/geo-point.test.js b/test/geo-point.test.js index bc84f717..7a87b243 100644 --- a/test/geo-point.test.js +++ b/test/geo-point.test.js @@ -1,6 +1,6 @@ describe('GeoPoint', function() { describe('geoPoint.distanceTo(geoPoint, options)', function() { - it("Get the distance to another `GeoPoint`", function() { + it('Get the distance to another `GeoPoint`', function() { var here = new GeoPoint({lat: 10, lng: 10}); var there = new GeoPoint({lat: 5, lng: 5}); var distance = here.distanceTo(there, {type: 'meters'}); @@ -10,15 +10,15 @@ describe('GeoPoint', function() { }); describe('GeoPoint.distanceBetween(a, b, options)', function() { - it("Get the distance between two points", function() { + it('Get the distance between two points', function() { var here = new GeoPoint({lat: 10, lng: 10}); var there = new GeoPoint({lat: 5, lng: 5}); var distance = GeoPoint.distanceBetween(here, there, {type: 'feet'}); - + assert.equal(Math.floor(distance), 2568169); }); }); - + describe('GeoPoint()', function(){ it('Create from string', function() { var point = new GeoPoint('1.234,5.678'); @@ -45,11 +45,11 @@ describe('GeoPoint', function() { var Model = loopback.createModel('geo-model', { geo: {type: 'GeoPoint'} }); - + var m = new Model({ geo: '1.222,3.444' }); - + assert(m.geo instanceof GeoPoint); assert.equal(m.geo.lng, 1.222); assert.equal(m.geo.lat, 3.444); diff --git a/test/hidden-properties.test.js b/test/hidden-properties.test.js index d30d32f7..a13a466a 100644 --- a/test/hidden-properties.test.js +++ b/test/hidden-properties.test.js @@ -8,15 +8,15 @@ describe('hidden properties', function () { {hidden: ['secret']} ); Product.attachTo(loopback.memory()); - + var Category = this.Category = loopback.PersistedModel.extend('category'); Category.attachTo(loopback.memory()); Category.hasMany(Product); - + app.model(Product); app.model(Category); app.use(loopback.rest()); - + Category.create({ name: 'my category' }, function(err, category) { @@ -32,7 +32,7 @@ describe('hidden properties', function () { this.Category.destroyAll(function() { Product.destroyAll(done); }); - }) + }); it('should hide a property remotely', function (done) { request(this.app) diff --git a/test/loopback.test.js b/test/loopback.test.js index 1bd996ed..fd8c5bf3 100644 --- a/test/loopback.test.js +++ b/test/loopback.test.js @@ -79,12 +79,12 @@ describe('loopback', function() { }); describe('loopback.remoteMethod(Model, fn, [options]);', function() { - it("Setup a remote method.", function() { + it('Setup a remote method.', function() { var Product = loopback.createModel('product', {price: Number}); Product.stats = function(fn) { // ... - } + }; loopback.remoteMethod( Product.stats, diff --git a/test/model.test.js b/test/model.test.js index d0fceb5a..3e698889 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -15,7 +15,7 @@ describe('Model / PersistedModel', function() { }); describe('Model.validatesUniquenessOf(property, options)', function() { - it("Ensure the value for `property` is unique", function(done) { + it('Ensure the value for `property` is unique', function(done) { var User = PersistedModel.extend('user', { 'first': String, 'last': String, @@ -31,9 +31,9 @@ describe('Model / PersistedModel', function() { }); User.attachTo(dataSource); - + User.validatesUniquenessOf('email', {message: 'email is not unique'}); - + var joe = new User({email: 'joe@joe.com'}); var joe2 = new User({email: 'joe@joe.com'}); @@ -41,7 +41,7 @@ describe('Model / PersistedModel', function() { joe2.save(function (err) { assert(err, 'should get a validation error'); assert(joe2.errors.email, 'model should have email error'); - + done(); }); }); @@ -49,14 +49,14 @@ describe('Model / PersistedModel', function() { }); describe('Model.attachTo(dataSource)', function() { - it("Attach a model to a [DataSource](#data-source)", function() { + it('Attach a model to a [DataSource](#data-source)', function() { var MyModel = loopback.createModel('my-model', {name: String}); var dataSource = loopback.createDataSource({ connector: loopback.Memory }); - + MyModel.attachTo(dataSource); - + MyModel.find(function(err, results) { assert(results.length === 0, 'should have data access methods after attaching to a data source'); }); @@ -95,7 +95,7 @@ describe.onServer('Remote Methods', function(){ } else { throw new Error('bad username and password!'); } - } + }; loopback.remoteMethod( User.login, @@ -113,9 +113,9 @@ describe.onServer('Remote Methods', function(){ app.use(loopback.rest()); app.model(User); }); - + describe('Model.destroyAll(callback)', function() { - it("Delete all Model instances from data source", function(done) { + it('Delete all Model instances from data source', function(done) { (new TaskEmitter()) .task(User, 'create', {first: 'jill'}) .task(User, 'create', {first: 'bob'}) @@ -159,12 +159,12 @@ describe.onServer('Remote Methods', function(){ describe('Model.beforeRemote(name, fn)', function(){ it('Run a function before a remote method is called by a client', function(done) { var hookCalled = false; - + User.beforeRemote('create', function(ctx, user, next) { hookCalled = true; next(); }); - + // invoke save request(app) .post('/users') @@ -183,7 +183,7 @@ describe.onServer('Remote Methods', function(){ it('Run a function after a remote method is called by a client', function(done) { var beforeCalled = false; var afterCalled = false; - + User.beforeRemote('create', function(ctx, user, next) { assert(!afterCalled); beforeCalled = true; @@ -194,7 +194,7 @@ describe.onServer('Remote Methods', function(){ afterCalled = true; next(); }); - + // invoke save request(app) .post('/users') @@ -212,9 +212,9 @@ describe.onServer('Remote Methods', function(){ describe('Remote Method invoking context', function () { describe('ctx.req', function() { - it("The express ServerRequest object", function(done) { + it('The express ServerRequest object', function(done) { var hookCalled = false; - + User.beforeRemote('create', function(ctx, user, next) { hookCalled = true; assert(ctx.req); @@ -225,7 +225,7 @@ describe.onServer('Remote Methods', function(){ assert(ctx.res.end); next(); }); - + // invoke save request(app) .post('/users') @@ -241,9 +241,9 @@ describe.onServer('Remote Methods', function(){ }); describe('ctx.res', function() { - it("The express ServerResponse object", function(done) { + it('The express ServerResponse object', function(done) { var hookCalled = false; - + User.beforeRemote('create', function(ctx, user, next) { hookCalled = true; assert(ctx.req); @@ -254,7 +254,7 @@ describe.onServer('Remote Methods', function(){ assert(ctx.res.end); next(); }); - + // invoke save request(app) .post('/users') @@ -268,16 +268,16 @@ describe.onServer('Remote Methods', function(){ }); }); }); - }) + }); describe('Model.hasMany(Model)', function() { - it("Define a one to many relationship", function(done) { + it('Define a one to many relationship', function(done) { var Book = dataSource.createModel('book', {title: String, author: String}); var Chapter = dataSource.createModel('chapter', {title: String}); - + // by referencing model Book.hasMany(Chapter); - + Book.create({title: 'Into the Wild', author: 'Jon Krakauer'}, function(err, book) { // using 'chapters' scope for build: var c = book.chapters.build({title: 'Chapter 1'}); @@ -296,7 +296,7 @@ describe.onServer('Remote Methods', function(){ }); }); }); - + describe('Model.properties', function(){ it('Normalized properties passed in originally by loopback.createModel()', function() { var props = { @@ -306,16 +306,16 @@ describe.onServer('Remote Methods', function(){ d: Date, g: loopback.GeoPoint }; - + var MyModel = loopback.createModel('foo', props); - + Object.keys(MyModel.definition.properties).forEach(function (key) { var p = MyModel.definition.properties[key]; var o = MyModel.definition.properties[key]; assert(p); assert(o); assert(typeof p.type === 'function'); - + if(typeof o === 'function') { // the normalized property // should match the given property @@ -323,40 +323,40 @@ describe.onServer('Remote Methods', function(){ p.type.name === o.name || p.type.name === o - ) + ); } }); }); }); - + describe('Model.extend()', function(){ it('Create a new model by extending an existing model', function() { var User = loopback.PersistedModel.extend('test-user', { email: String }); - + User.foo = function () { return 'bar'; - } - + }; + User.prototype.bar = function () { return 'foo'; - } - + }; + var MyUser = User.extend('my-user', { a: String, b: String }); - + assert.equal(MyUser.prototype.bar, User.prototype.bar); assert.equal(MyUser.foo, User.foo); - + var user = new MyUser({ email: 'foo@bar.com', a: 'foo', b: 'bar' }); - + assert.equal(user.email, 'foo@bar.com'); assert.equal(user.a, 'foo'); assert.equal(user.b, 'bar'); diff --git a/test/relations.integration.js b/test/relations.integration.js index 04460223..ec08b3cc 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -1,3 +1,5 @@ +/*jshint -W030 */ + var loopback = require('../'); var lt = require('loopback-testing'); var path = require('path'); @@ -53,7 +55,7 @@ describe('relations - integration', function () { this.res.text); this.widgets = this.res.body; this.widget = this.res.body && this.res.body[0]; - }); + }); it('should be an array', function() { assert(Array.isArray(this.widgets)); }); @@ -91,7 +93,7 @@ describe('relations - integration', function () { describe('widget (response.body)', function() { beforeEach(function() { this.widget = this.res.body; - }); + }); it('should be an object', function() { assert(typeof this.widget === 'object'); assert(!Array.isArray(this.widget)); @@ -113,7 +115,7 @@ describe('relations - integration', function () { }); }); }); - + describe('/stores/:id/widgets/:fk - 200', function () { beforeEach(function (done) { var self = this; @@ -144,7 +146,7 @@ describe('relations - integration', function () { }); }); }); - + describe('/store/:id/widgets/count', function () { beforeEach(function() { this.url = '/api/stores/' + this.store.id + '/widgets/count'; @@ -158,7 +160,7 @@ describe('relations - integration', function () { }); }); }); - + describe('/store/:id/widgets/count - filtered (matches)', function () { beforeEach(function() { this.url = '/api/stores/' + this.store.id + '/widgets/count?where[name]=foo'; @@ -172,7 +174,7 @@ describe('relations - integration', function () { }); }); }); - + describe('/store/:id/widgets/count - filtered (no matches)', function () { beforeEach(function() { this.url = '/api/stores/' + this.store.id + '/widgets/count?where[name]=bar'; @@ -612,13 +614,13 @@ describe('relations - integration', function () { }); describe('embedsOne', function() { - + before(function defineGroupAndPosterModels() { var group = app.model( 'group', - { properties: { name: 'string' }, + { properties: { name: 'string' }, dataSource: 'db', - plural: 'groups' + plural: 'groups' } ); var poster = app.model( @@ -627,7 +629,7 @@ describe('relations - integration', function () { ); group.embedsOne(poster, { as: 'cover' }); }); - + before(function createImage(done) { var test = this; app.models.group.create({ name: 'Group 1' }, @@ -638,46 +640,46 @@ describe('relations - integration', function () { group.save(done); }); }); - + after(function(done) { this.app.models.group.destroyAll(done); }); - + it('includes the embedded models', function(done) { var url = '/api/groups/' + this.group.id; - + this.get(url) .expect(200, function(err, res) { expect(res.body.name).to.be.equal('Group 1'); - expect(res.body.poster).to.be.eql( + expect(res.body.poster).to.be.eql( { url: 'http://image.url' } ); done(); }); }); - + it('returns the embedded model', function(done) { var url = '/api/groups/' + this.group.id + '/cover'; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql( + expect(res.body).to.be.eql( { url: 'http://image.url' } ); done(); }); }); - + }); - + describe('embedsMany', function() { - + before(function defineProductAndCategoryModels() { var todoList = app.model( 'todoList', - { properties: { name: 'string' }, + { properties: { name: 'string' }, dataSource: 'db', - plural: 'todo-lists' + plural: 'todo-lists' } ); var todoItem = app.model( @@ -702,52 +704,52 @@ describe('relations - integration', function () { after(function(done) { this.app.models.todoList.destroyAll(done); }); - + it('includes the embedded models', function(done) { var url = '/api/todo-lists/' + this.todoList.id; this.get(url) .expect(200, function(err, res) { expect(res.body.name).to.be.equal('List A'); - expect(res.body.todoItems).to.be.eql([ + expect(res.body.todoItems).to.be.eql([ { content: 'Todo 1', id: 1 }, { content: 'Todo 2', id: 2 } ]); done(); }); }); - + it('returns the embedded models', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items'; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { content: 'Todo 1', id: 1 }, { content: 'Todo 2', id: 2 } ]); done(); }); }); - + it('filters the embedded models', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items'; url += '?filter[where][id]=2'; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { content: 'Todo 2', id: 2 } ]); done(); }); }); - + it('creates embedded models', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items'; - + var expected = { content: 'Todo 3', id: 3 }; - + this.post(url) .send({ content: 'Todo 3' }) .expect(200, function(err, res) { @@ -755,13 +757,13 @@ describe('relations - integration', function () { done(); }); }); - + it('returns the embedded models', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items'; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { content: 'Todo 1', id: 1 }, { content: 'Todo 2', id: 2 }, { content: 'Todo 3', id: 3 } @@ -769,10 +771,10 @@ describe('relations - integration', function () { done(); }); }); - + it('returns an embedded model by (internal) id', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items/3'; - + this.get(url) .expect(200, function(err, res) { expect(res.body).to.be.eql( @@ -781,30 +783,30 @@ describe('relations - integration', function () { done(); }); }); - + it('removes an embedded model', function(done) { var expectedProduct = this.product; var url = '/api/todo-lists/' + this.todoList.id + '/items/2'; - + this.del(url) .expect(200, function(err, res) { done(); }); }); - + it('returns the embedded models - verify', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items'; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { content: 'Todo 1', id: 1 }, { content: 'Todo 3', id: 3 } ]); done(); }); }); - + it('returns a 404 response when embedded model is not found', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items/2'; this.get(url).expect(404, function(err, res) { @@ -813,29 +815,29 @@ describe('relations - integration', function () { done(); }); }); - + it.skip('checks if an embedded model exists - ok', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items/3'; - + this.head(url) .expect(200, function(err, res) { done(); }); }); - + it.skip('checks if an embedded model exists - fail', function(done) { var url = '/api/todo-lists/' + this.todoList.id + '/items/2'; - + this.head(url) .expect(404, function(err, res) { done(); }); }); - + }); - + describe('referencesMany', function() { - + before(function defineProductAndCategoryModels() { var recipe = app.model( 'recipe', @@ -851,8 +853,8 @@ describe('relations - integration', function () { ); recipe.referencesMany(ingredient); // contrived example for test: - recipe.hasOne(photo, { as: 'picture', options: { - http: { path: 'image' } + recipe.hasOne(photo, { as: 'picture', options: { + http: { path: 'image' } } }); }); @@ -862,15 +864,15 @@ describe('relations - integration', function () { function(err, recipe) { if (err) return done(err); test.recipe = recipe; - recipe.ingredients.create({ - name: 'Chocolate' }, + recipe.ingredients.create({ + name: 'Chocolate' }, function(err, ing) { test.ingredient1 = ing.id; recipe.picture.create({ name: 'Photo 1' }, done); }); }); }); - + before(function createIngredient(done) { var test = this; app.models.ingredient.create({ name: 'Sugar' }, function(err, ing) { @@ -887,11 +889,11 @@ describe('relations - integration', function () { }); }); }); - + it('keeps an array of ids', function(done) { var url = '/api/recipes/' + this.recipe.id; var test = this; - + this.get(url) .expect(200, function(err, res) { expect(res.body.ingredientIds).to.eql([test.ingredient1]); @@ -899,11 +901,11 @@ describe('relations - integration', function () { done(); }); }); - + it('creates referenced models', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; var test = this; - + this.post(url) .send({ name: 'Butter' }) .expect(200, function(err, res) { @@ -912,14 +914,14 @@ describe('relations - integration', function () { done(); }); }); - + it('has created models', function(done) { var url = '/api/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 }, { name: 'Sugar', id: test.ingredient2 }, { name: 'Butter', id: test.ingredient3 } @@ -927,40 +929,40 @@ describe('relations - integration', function () { done(); }); }); - + it('returns the referenced models', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 }, { name: 'Butter', id: test.ingredient3 } ]); done(); }); }); - + it('filters the referenced models', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; url += '?filter[where][name]=Butter'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Butter', id: test.ingredient3 } ]); done(); }); }); - + it('includes the referenced models', function(done) { var url = '/api/recipes/findOne?filter[where][id]=' + this.recipe.id; url += '&filter[include]=ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { expect(res.body.ingredientIds).to.eql([ @@ -978,7 +980,7 @@ describe('relations - integration', function () { var url = '/api/recipes/' + this.recipe.id + '/ingredients/'; url += this.ingredient3; var test = this; - + this.get(url) .expect(200, function(err, res) { expect(res.body).to.be.eql( @@ -987,13 +989,13 @@ describe('relations - integration', function () { done(); }); }); - + it('keeps an array of ids - verify', function(done) { var url = '/api/recipes/' + this.recipe.id; var test = this; - + var expected = [test.ingredient1, test.ingredient3]; - + this.get(url) .expect(200, function(err, res) { expect(res.body.ingredientIds).to.eql(expected); @@ -1001,50 +1003,50 @@ describe('relations - integration', function () { done(); }); }); - + it('destroys a referenced model', function(done) { var expectedProduct = this.product; var url = '/api/recipes/' + this.recipe.id + '/ingredients/'; url += this.ingredient3; - + this.del(url) .expect(200, function(err, res) { done(); }); }); - + it('has destroyed a referenced model', function(done) { var url = '/api/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 }, { name: 'Sugar', id: test.ingredient2 } ]); done(); }); }); - + it('returns the referenced models - verify', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 } ]); done(); }); }); - + it('creates/links a reference by id', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; url += '/rel/' + this.ingredient2; var test = this; - + this.put(url) .expect(200, function(err, res) { expect(res.body).to.be.eql( @@ -1053,62 +1055,62 @@ describe('relations - integration', function () { done(); }); }); - + it('returns the referenced models - verify', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 }, { name: 'Sugar', id: test.ingredient2 } ]); done(); }); }); - + it('removes/unlinks a reference by id', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; url += '/rel/' + this.ingredient1; var test = this; - + this.del(url) .expect(200, function(err, res) { done(); }); }); - + it('returns the referenced models - verify', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Sugar', id: test.ingredient2 } ]); done(); }); }); - + it('has not destroyed an unlinked model', function(done) { var url = '/api/ingredients'; var test = this; - + this.get(url) .expect(200, function(err, res) { - expect(res.body).to.be.eql([ + expect(res.body).to.be.eql([ { name: 'Chocolate', id: test.ingredient1 }, { name: 'Sugar', id: test.ingredient2 } ]); done(); }); }); - + it('uses a custom relation path', function(done) { var url = '/api/recipes/' + this.recipe.id + '/image'; - + this.get(url) .expect(200, function(err, res) { expect(err).to.not.exist; @@ -1116,31 +1118,31 @@ describe('relations - integration', function () { done(); }); }); - + it.skip('checks if a referenced model exists - ok', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients/'; url += this.ingredient1; - + this.head(url) .expect(200, function(err, res) { done(); }); }); - + it.skip('checks if an referenced model exists - fail', function(done) { var url = '/api/recipes/' + this.recipe.id + '/ingredients/'; url += this.ingredient3; - + this.head(url) .expect(404, function(err, res) { done(); }); }); - + }); - + describe('nested relations', function() { - + before(function defineModels() { var Book = app.model( 'Book', @@ -1165,36 +1167,36 @@ describe('relations - integration', function () { Book.hasMany(Page); Page.hasMany(Note); Image.belongsTo(Book); - + Book.nestRemoting('pages'); Image.nestRemoting('book'); - + expect(Book.prototype['__findById__pages__notes']).to.be.a.function; expect(Image.prototype['__findById__book__pages']).to.be.a.function; - + Page.beforeRemote('prototype.__findById__notes', function(ctx, result, next) { ctx.res.set('x-before', 'before'); next(); }); - + Page.afterRemote('prototype.__findById__notes', function(ctx, result, next) { ctx.res.set('x-after', 'after'); next(); }); - + }); - + before(function createBook(done) { var test = this; - app.models.Book.create({ name: 'Book 1' }, + app.models.Book.create({ name: 'Book 1' }, function(err, book) { if (err) return done(err); test.book = book; - book.pages.create({ name: 'Page 1' }, + book.pages.create({ name: 'Page 1' }, function(err, page) { if (err) return done(err); test.page = page; - page.notes.create({ text: 'Page Note 1' }, + page.notes.create({ text: 'Page Note 1' }, function(err, note) { test.note = note; done(); @@ -1202,17 +1204,17 @@ describe('relations - integration', function () { }); }); }); - + before(function createCover(done) { var test = this; - app.models.Image.create({ name: 'Cover 1', book: test.book }, + app.models.Image.create({ name: 'Cover 1', book: test.book }, function(err, image) { if (err) return done(err); test.image = image; done(); }); }); - + it('has regular relationship routes - pages', function(done) { var test = this; this.get('/api/books/' + test.book.id + '/pages') @@ -1223,7 +1225,7 @@ describe('relations - integration', function () { done(); }); }); - + it('has regular relationship routes - notes', function(done) { var test = this; this.get('/api/pages/' + test.page.id + '/notes/' + test.note.id) @@ -1235,7 +1237,7 @@ describe('relations - integration', function () { done(); }); }); - + it('has a basic error handler', function(done) { var test = this; this.get('/api/books/unknown/pages/' + test.page.id + '/notes') @@ -1246,7 +1248,7 @@ describe('relations - integration', function () { done(); }); }); - + it('enables nested relationship routes - belongsTo find', function(done) { var test = this; this.get('/api/images/' + test.image.id + '/book/pages') @@ -1257,7 +1259,7 @@ describe('relations - integration', function () { done(); }); }); - + it('enables nested relationship routes - belongsTo findById', function(done) { var test = this; this.get('/api/images/' + test.image.id + '/book/pages/' + test.page.id) @@ -1267,7 +1269,7 @@ describe('relations - integration', function () { done(); }); }); - + it('enables nested relationship routes - hasMany find', function(done) { var test = this; this.get('/api/books/' + test.book.id + '/pages/' + test.page.id + '/notes') @@ -1278,7 +1280,7 @@ describe('relations - integration', function () { done(); }); }); - + it('enables nested relationship routes - hasMany findById', function(done) { var test = this; this.get('/api/books/' + test.book.id + '/pages/' + test.page.id + '/notes/' + test.note.id) @@ -1290,7 +1292,7 @@ describe('relations - integration', function () { done(); }); }); - + }); - + }); diff --git a/test/remote-connector.test.js b/test/remote-connector.test.js index b99c8f74..921a8230 100644 --- a/test/remote-connector.test.js +++ b/test/remote-connector.test.js @@ -57,7 +57,7 @@ describe('RemoteConnector', function() { calledServerCreate = true; data.id = 1; cb(null, data); - } + }; ServerModel.setupRemoting(); diff --git a/test/remoting-coercion.test.js b/test/remoting-coercion.test.js index 5c667673..22124d5d 100644 --- a/test/remoting-coercion.test.js +++ b/test/remoting-coercion.test.js @@ -13,7 +13,7 @@ describe('remoting coercion', function() { assert(inst instanceof TestModel); assert(inst.foo === 'bar'); cb(); - } + }; TestModel.remoteMethod('test', { accepts: {arg: 'inst', type: 'TestModel', http: {source: 'body'}}, http: {path: '/test', verb: 'post'} @@ -31,4 +31,4 @@ describe('remoting coercion', function() { done(); }); }); -}) +}); diff --git a/test/remoting.integration.js b/test/remoting.integration.js index 0ba0e90f..394b341c 100644 --- a/test/remoting.integration.js +++ b/test/remoting.integration.js @@ -15,26 +15,26 @@ describe('remoting - integration', function () { }); describe('app.remotes.options', function () { - it("should load remoting options", function () { + it('should load remoting options', function () { var remotes = app.remotes(); - assert.deepEqual(remotes.options, {"json": {"limit": "1kb", "strict": false}, - "urlencoded": {"limit": "8kb", "extended": true}}); + assert.deepEqual(remotes.options, {'json': {'limit': '1kb', 'strict': false}, + 'urlencoded': {'limit': '8kb', 'extended': true}}); }); - it("rest handler", function () { + it('rest handler', function () { var handler = app.handler('rest'); assert(handler); }); it('should accept request that has entity below 1kb', function (done) { // Build an object that is smaller than 1kb - var name = ""; + var name = ''; for (var i = 0; i < 256; i++) { - name += "11"; + name += '11'; } this.http = this.post('/api/stores'); this.http.send({ - "name": name + 'name': name }); this.http.end(function (err) { if (err) return done(err); @@ -47,13 +47,13 @@ describe('remoting - integration', function () { it('should reject request that has entity beyond 1kb', function (done) { // Build an object that is larger than 1kb - var name = ""; + var name = ''; for (var i = 0; i < 2048; i++) { - name += "11111111111"; + name += '11111111111'; } this.http = this.post('/api/stores'); this.http.send({ - "name": name + 'name': name }); this.http.end(function (err) { if (err) return done(err); @@ -81,7 +81,7 @@ describe('remoting - integration', function () { m.name, '(', m.accepts.map(function(a) { - return a.arg + ':' + a.type + return a.arg + ':' + a.type; }).join(','), ')', formatReturns(m), diff --git a/test/role.test.js b/test/role.test.js index 7e02f7ab..28dae1b4 100644 --- a/test/role.test.js +++ b/test/role.test.js @@ -22,7 +22,7 @@ describe('role model', function () { RoleMapping.attachTo(ds); }); - it("should define role/role relations", function () { + it('should define role/role relations', function () { Role.create({name: 'user'}, function (err, userRole) { Role.create({name: 'admin'}, function (err, adminRole) { userRole.principals.create({principalType: RoleMapping.ROLE, principalId: adminRole.id}, function (err, mapping) { @@ -46,7 +46,7 @@ describe('role model', function () { }); - it("should define role/user relations", function () { + it('should define role/user relations', function () { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { // console.log('User: ', user.id); @@ -77,7 +77,7 @@ describe('role model', function () { }); - it("should automatically generate role id", function () { + it('should automatically generate role id', function () { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { // console.log('User: ', user.id); @@ -110,7 +110,7 @@ describe('role model', function () { }); - it("should support getRoles() and isInRole()", function () { + it('should support getRoles() and isInRole()', function () { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { // console.log('User: ', user.id); Role.create({name: 'userRole'}, function (err, role) { @@ -156,7 +156,7 @@ describe('role model', function () { }); - it("should support owner role resolver", function () { + it('should support owner role resolver', function () { var Album = ds.createModel('Album', { name: String, diff --git a/test/support.js b/test/support.js index 81d420e1..bd51552c 100644 --- a/test/support.js +++ b/test/support.js @@ -1,7 +1,7 @@ /** * loopback test setup and support. */ - + assert = require('assert'); expect = require('chai').expect; loopback = require('../'); @@ -44,9 +44,9 @@ assertValidDataSource = function (dataSource) { assert.isFunc(dataSource, 'disableRemote'); assert.isFunc(dataSource, 'defineOperation'); assert.isFunc(dataSource, 'operations'); -} +}; assert.isFunc = function (obj, name) { assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist'); assert(typeof obj[name] === 'function', name + ' is not a function'); -} +}; diff --git a/test/user.test.js b/test/user.test.js index 710cc5ca..ea75e027 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -21,29 +21,29 @@ describe('User', function(){ // Update the AccessToken relation to use the subclass of User AccessToken.belongsTo(User); - + // allow many User.afterRemote's to be called User.setMaxListeners(0); }); - + beforeEach(function (done) { app.enableAuth(); app.use(loopback.token()); app.use(loopback.rest()); app.model(User); - + User.create(validCredentials, function(err, user) { User.create(validCredentialsEmailVerified, done); }); }); - + afterEach(function (done) { User.destroyAll(function (err) { User.accessToken.destroyAll(done); }); }); - + describe('User.create', function(){ it('Create a new user', function(done) { User.create({email: 'f@b.com', password: 'bar'}, function (err, user) { @@ -73,9 +73,9 @@ describe('User', function(){ it('Email is required', function (done) { User.create({password: '123'}, function (err) { assert(err); - assert.equal(err.name, "ValidationError"); + assert.equal(err.name, 'ValidationError'); assert.equal(err.statusCode, 422); - assert.equal(err.details.context, "user"); + assert.equal(err.details.context, 'user'); assert.deepEqual(err.details.codes.email, [ 'presence', 'format.blank' @@ -84,24 +84,24 @@ describe('User', function(){ done(); }); }); - + // will change in future versions where password will be optional by default it('Password is required', function(done) { - var u = new User({email: "123@456.com"}); - + var u = new User({email: '123@456.com'}); + User.create({email: 'c@d.com'}, function (err) { assert(err); done(); }); }); - + it('Requires a valid email', function(done) { User.create({email: 'foo@', password: '123'}, function (err) { assert(err); done(); }); }); - + it('Requires a unique email', function(done) { User.create({email: 'a@b.com', password: 'foobar'}, function () { User.create({email: 'a@b.com', password: 'batbaz'}, function (err) { @@ -118,8 +118,8 @@ describe('User', function(){ done(); }); }); - }); - + }); + it('Requires a password to login with basic auth', function(done) { User.create({email: 'b@c.com'}, function (err) { User.login({email: 'b@c.com'}, function (err, accessToken) { @@ -129,7 +129,7 @@ describe('User', function(){ }); }); }); - + it('Hashes the given password', function() { var u = new User({username: 'foo', password: 'bar'}); assert(u.password !== 'bar'); @@ -147,14 +147,14 @@ describe('User', function(){ }); }); }); - + describe('User.login', function() { it('Login a user by providing credentials', function(done) { User.login(validCredentials, function (err, accessToken) { assert(accessToken.userId); assert(accessToken.id); assert.equal(accessToken.id.length, 64); - + done(); }); }); @@ -206,12 +206,12 @@ describe('User', function(){ .end(function(err, res){ if(err) return done(err); var accessToken = res.body; - + assert(accessToken.userId); assert(accessToken.id); assert.equal(accessToken.id.length, 64); assert(accessToken.user === undefined); - + done(); }); }); @@ -284,7 +284,7 @@ describe('User', function(){ it('Login should only allow correct credentials', function(done) { User.create({email: 'foo22@bar.com', password: 'bar'}, function(user, err) { - User.login({email: 'foo44@bar.com', password: 'bar'}, function(err, accessToken) { + User.login({email: 'foo44@bar.com', password: 'bar'}, function(err, accessToken) { assert(err); assert(!accessToken); done(); @@ -511,20 +511,20 @@ describe('User', function(){ }); }); }); - + describe('User.logout', function() { it('Logout a user by providing the current accessToken id (using node)', function(done) { login(logout); - + function login(fn) { User.login({email: 'foo@bar.com', password: 'bar'}, fn); } - + function logout(err, accessToken) { User.logout(accessToken.id, verify(accessToken.id, done)); } }); - + it('Logout a user by providing the current accessToken id (over rest)', function(done) { login(logout); function login(fn) { @@ -536,14 +536,14 @@ describe('User', function(){ .end(function(err, res){ if(err) return done(err); var accessToken = res.body; - + assert(accessToken.userId); assert(accessToken.id); - + fn(null, accessToken.id); }); } - + function logout(err, token) { request(app) .post('/users/logout') @@ -552,33 +552,33 @@ describe('User', function(){ .end(verify(token, done)); } }); - + function verify(token, done) { assert(token); - + return function (err) { if(err) return done(err); - + AccessToken.findById(token, function (err, accessToken) { assert(!accessToken, 'accessToken should not exist after logging out'); done(err); }); - } + }; } }); - + describe('user.hasPassword(plain, fn)', function(){ it('Determine if the password matches the stored password', function(done) { var u = new User({username: 'foo', password: 'bar'}); u.hasPassword('bar', function (err, isMatch) { assert(isMatch, 'password doesnt match'); done(); - }); + }); }); - + it('should match a password when saved', function(done) { var u = new User({username: 'a', password: 'b', email: 'z@z.net'}); - + u.save(function (err, user) { User.findById(user.id, function (err, uu) { uu.hasPassword('b', function (err, isMatch) { @@ -588,7 +588,7 @@ describe('User', function(){ }); }); }); - + it('should match a password after it is changed', function(done) { User.create({email: 'foo@baz.net', username: 'bat', password: 'baz'}, function (err, user) { User.findById(user.id, function (err, foundUser) { @@ -612,14 +612,14 @@ describe('User', function(){ }); }); }); - + describe('Verification', function(){ describe('user.verify(options, fn)', function(){ it('Verify a user\'s email address', function(done) { User.afterRemote('create', function(ctx, user, next) { assert(user, 'afterRemote should include result'); - + var options = { type: 'email', to: user.email, @@ -628,7 +628,7 @@ describe('User', function(){ protocol: ctx.req.protocol, host: ctx.req.get('host') }; - + user.verify(options, function (err, result) { assert(result.email); assert(result.email.response); @@ -639,7 +639,7 @@ describe('User', function(){ done(); }); }); - + request(app) .post('/users') .expect('Content-Type', /json/) @@ -653,7 +653,7 @@ describe('User', function(){ it('Verify a user\'s email address with custom header', function(done) { User.afterRemote('create', function(ctx, user, next) { assert(user, 'afterRemote should include result'); - + var options = { type: 'email', to: user.email, @@ -663,14 +663,14 @@ describe('User', function(){ host: ctx.req.get('host'), headers: {'message-id':'custom-header-value'} }; - + user.verify(options, function (err, result) { assert(result.email); assert.equal(result.email.messageId, 'custom-header-value'); done(); }); }); - + request(app) .post('/users') .expect('Content-Type', /json/) diff --git a/test/util/model-tests.js b/test/util/model-tests.js index 58a5c0c2..616b227c 100644 --- a/test/util/model-tests.js +++ b/test/util/model-tests.js @@ -33,7 +33,7 @@ describe('Model Tests', function() { } return extendedModel; - } + }; User = PersistedModel.extend('user', { 'first': String, @@ -53,7 +53,7 @@ describe('Model Tests', function() { }); describe('Model.validatesPresenceOf(properties...)', function() { - it("Require a model to include a property to be considered valid", function() { + it('Require a model to include a property to be considered valid', function() { User.validatesPresenceOf('first', 'last', 'age'); var joe = new User({first: 'joe'}); assert(joe.isValid() === false, 'model should not validate'); @@ -63,7 +63,7 @@ describe('Model Tests', function() { }); describe('Model.validatesLengthOf(property, options)', function() { - it("Require a property length to be within a specified range", function() { + it('Require a property length to be within a specified range', function() { User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}}); var joe = new User({password: '1234'}); assert(joe.isValid() === false, 'model should not be valid'); @@ -72,7 +72,7 @@ describe('Model Tests', function() { }); describe('Model.validatesInclusionOf(property, options)', function() { - it("Require a value for `property` to be in the specified array", function() { + it('Require a value for `property` to be in the specified array', function() { User.validatesInclusionOf('gender', {in: ['male', 'female']}); var foo = new User({gender: 'bar'}); assert(foo.isValid() === false, 'model should not be valid'); @@ -81,7 +81,7 @@ describe('Model Tests', function() { }); describe('Model.validatesExclusionOf(property, options)', function() { - it("Require a value for `property` to not exist in the specified array", function() { + it('Require a value for `property` to not exist in the specified array', function() { User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']}); var foo = new User({domain: 'www'}); var bar = new User({domain: 'billing'}); @@ -96,7 +96,7 @@ describe('Model Tests', function() { }); describe('Model.validatesNumericalityOf(property, options)', function() { - it("Require a value for `property` to be a specific type of `Number`", function() { + it('Require a value for `property` to be a specific type of `Number`', function() { User.validatesNumericalityOf('age', {int: true}); var joe = new User({age: 10.2}); assert(joe.isValid() === false); @@ -107,14 +107,14 @@ describe('Model Tests', function() { }); describe('myModel.isValid()', function() { - it("Validate the model instance", function() { + it('Validate the model instance', function() { User.validatesNumericalityOf('age', {int: true}); - var user = new User({first: 'joe', age: 'flarg'}) + var user = new User({first: 'joe', age: 'flarg'}); var valid = user.isValid(); assert(valid === false); assert(user.errors.age, 'model should have age error'); }); - + it('Asynchronously validate the model', function(done) { User.validatesNumericalityOf('age', {int: true}); var user = new User({first: 'joe', age: 'flarg'}); @@ -127,7 +127,7 @@ describe('Model Tests', function() { }); describe('Model.create([data], [callback])', function() { - it("Create an instance of Model with given data and save to the attached data source", function(done) { + it('Create an instance of Model with given data and save to the attached data source', function(done) { User.create({first: 'Joe', last: 'Bob'}, function(err, user) { assert(user instanceof User); done(); @@ -136,7 +136,7 @@ describe('Model Tests', function() { }); describe('model.save([options], [callback])', function() { - it("Save an instance of a Model to the attached data source", function(done) { + it('Save an instance of a Model to the attached data source', function(done) { var joe = new User({first: 'Joe', last: 'Bob'}); joe.save(function(err, user) { assert(user.id); @@ -148,11 +148,11 @@ describe('Model Tests', function() { }); describe('model.updateAttributes(data, [callback])', function() { - it("Save specified attributes to the attached data source", function(done) { + it('Save specified attributes to the attached data source', function(done) { User.create({first: 'joe', age: 100}, function (err, user) { assert(!err); assert.equal(user.first, 'joe'); - + user.updateAttributes({ first: 'updatedFirst', last: 'updatedLast' @@ -168,11 +168,11 @@ describe('Model Tests', function() { }); describe('Model.upsert(data, callback)', function() { - it("Update when record with id=data.id found, insert otherwise", function(done) { + it('Update when record with id=data.id found, insert otherwise', function(done) { User.upsert({first: 'joe', id: 7}, function (err, user) { assert(!err); assert.equal(user.first, 'joe'); - + User.upsert({first: 'bob', id: 7}, function (err, updatedUser) { assert(!err); assert.equal(updatedUser.first, 'bob'); @@ -183,7 +183,7 @@ describe('Model Tests', function() { }); describe('model.destroy([callback])', function() { - it("Remove a model from the attached data source", function(done) { + it('Remove a model from the attached data source', function(done) { User.create({first: 'joe', last: 'bob'}, function (err, user) { User.findById(user.id, function (err, foundUser) { assert.equal(user.id, foundUser.id); @@ -199,7 +199,7 @@ describe('Model Tests', function() { }); describe('Model.deleteById(id, [callback])', function () { - it("Delete a model instance from the attached data source", function (done) { + it('Delete a model instance from the attached data source', function (done) { User.create({first: 'joe', last: 'bob'}, function (err, user) { User.deleteById(user.id, function (err) { User.findById(user.id, function (err, notFound) { @@ -212,7 +212,7 @@ describe('Model Tests', function() { }); describe('Model.findById(id, callback)', function() { - it("Find an instance by id", function(done) { + it('Find an instance by id', function(done) { User.create({first: 'michael', last: 'jordan', id: 23}, function () { User.findById(23, function (err, user) { assert.equal(user.id, 23); @@ -225,7 +225,7 @@ describe('Model Tests', function() { }); describe('Model.count([query], callback)', function() { - it("Query count of Model instances in data source", function(done) { + it('Query count of Model instances in data source', function(done) { (new TaskEmitter()) .task(User, 'create', {first: 'jill', age: 100}) .task(User, 'create', {first: 'bob', age: 200}) @@ -243,5 +243,4 @@ describe('Model Tests', function() { }); - -} +};