From cf9839c71d22c38dbfe026cef43fc90a9c558d89 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe <erisds@gmail.com> Date: Mon, 21 Jul 2014 10:29:03 +0100 Subject: [PATCH] Integration tests use consistent teardown methods --- Gruntfile.js | 2 +- .../api/api_authentication_spec.js | 72 +++---- core/test/integration/api/api_db_spec.js | 41 ++-- core/test/integration/api/api_mail_spec.js | 37 ++-- .../integration/api/api_notifications_spec.js | 26 +-- core/test/integration/api/api_posts_spec.js | 20 +- .../test/integration/api/api_settings_spec.js | 95 ++++----- core/test/integration/api/api_slugs_spec.js | 33 ++- core/test/integration/api/api_tags_spec.js | 33 ++- core/test/integration/api/api_themes_spec.js | 15 +- core/test/integration/api/api_upload_spec.js | 196 +++++++++--------- core/test/integration/api/api_users_spec.js | 54 +---- .../model/model_app_fields_spec.js | 34 +-- .../model/model_app_settings_spec.js | 34 +-- .../test/integration/model/model_apps_spec.js | 39 ++-- .../model/model_permissions_spec.js | 28 +-- .../integration/model/model_posts_spec.js | 32 ++- .../integration/model/model_roles_spec.js | 28 +-- .../integration/model/model_settings_spec.js | 36 +--- .../test/integration/model/model_tags_spec.js | 36 ++-- .../integration/model/model_users_spec.js | 49 ++--- core/test/integration/update_check_spec.js | 16 +- core/test/utils/index.js | 14 +- 23 files changed, 405 insertions(+), 565 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d81365e0fe..baaf752771 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -628,7 +628,7 @@ var path = require('path'), // globally, by using a command in the form (replace path to api_tags_spec.js with the test file you want to // run): // - // NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/integration/api/api_tags_spec.js` + // `NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/integration/api/api_tags_spec.js` // // Their purpose is to test that both the api and models behave as expected when the database layer is involved. // These tests are run against sqlite3, mysql and pg on travis and ensure that differences between the databases diff --git a/core/test/integration/api/api_authentication_spec.js b/core/test/integration/api/api_authentication_spec.js index 97946230cc..b98192de2d 100644 --- a/core/test/integration/api/api_authentication_spec.js +++ b/core/test/integration/api/api_authentication_spec.js @@ -1,31 +1,31 @@ -var testUtils = require('../../utils'), - should = require('should'), - when = require('when'), - rewire = require('rewire'), - mail = rewire('../../../server/api/mail'), - permissions = require('../../../server/permissions'), - settings = require('../../../server/api/settings'), +/*globals describe, before, beforeEach, afterEach, it */ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + when = require('when'), + rewire = require('rewire'), - authentication = require('../../../server/api/authentication'); + // Stuff we are testing + mail = rewire('../../../server/api/mail'), + settings = require('../../../server/api/settings'), + permissions = require('../../../server/permissions'), + AuthAPI = require('../../../server/api/authentication'); describe('Authentication API', function () { + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(AuthAPI); describe('Setup', function () { describe('Not completed', function () { beforeEach(function (done) { - testUtils.clearData().then(function () { - return testUtils.initData().then(function () { - return permissions.init().then(function () { - return settings.updateSettingsCache(); - }); + testUtils.initData().then(function () { + return permissions.init().then(function () { + return settings.updateSettingsCache(); }); }).then(function () { done(); @@ -33,7 +33,7 @@ describe('Authentication API', function () { }); it('should report that setup has not been completed', function (done) { - authentication.isSetup().then(function (result) { + AuthAPI.isSetup().then(function (result) { should.exist(result); result.setup[0].status.should.be.false; @@ -55,8 +55,12 @@ describe('Authentication API', function () { return when.resolve(); }); - authentication.setup({ setup: [setupData] }).then(function (result) { + AuthAPI.setup({ setup: [setupData] }).then(function (result) { should.exist(result); + should.exist(result.users); + result.users.should.have.length(1); + testUtils.API.checkResponse(result, 'users'); + testUtils.API.checkResponse(result.users[0], 'user', ['roles']); var newUser = result.users[0]; @@ -74,12 +78,10 @@ describe('Authentication API', function () { describe('Completed', function () { beforeEach(function (done) { - testUtils.clearData().then(function () { - return testUtils.initData().then(function () { - return testUtils.insertDefaultFixtures().then(function () { - return permissions.init().then(function () { - return settings.updateSettingsCache(); - }); + testUtils.initData().then(function () { + return testUtils.insertDefaultFixtures().then(function () { + return permissions.init().then(function () { + return settings.updateSettingsCache(); }); }); }).then(function () { @@ -88,7 +90,7 @@ describe('Authentication API', function () { }); it('should report that setup has been completed', function (done) { - authentication.isSetup().then(function (result) { + AuthAPI.isSetup().then(function (result) { should.exist(result); result.setup[0].status.should.be.true; @@ -104,7 +106,7 @@ describe('Authentication API', function () { title: 'a test blog' }; - authentication.setup({ setup: [setupData] }).then(function (result) { + AuthAPI.setup({ setup: [setupData] }).then(function () { done(new Error('Setup was able to be run')); }).catch(function (err) { should.exist(err); @@ -123,11 +125,9 @@ describe('Authentication API', function () { describe('Setup not completed', function () { beforeEach(function (done) { - testUtils.clearData().then(function () { - return testUtils.initData().then(function () { - return permissions.init().then(function () { - return settings.updateSettingsCache(); - }); + return testUtils.initData().then(function () { + return permissions.init().then(function () { + return settings.updateSettingsCache(); }); }).then(function () { done(); @@ -135,7 +135,7 @@ describe('Authentication API', function () { }); it('should not allow an invitation to be accepted', function (done) { - authentication.acceptInvitation().then(function () { + AuthAPI.acceptInvitation().then(function () { done(new Error('Invitation was allowed to be accepted')); }).catch(function (err) { should.exist(err); @@ -148,7 +148,7 @@ describe('Authentication API', function () { }); it('should not generate a password reset token', function (done) { - authentication.generateResetToken().then(function () { + AuthAPI.generateResetToken().then(function () { done(new Error('Reset token was generated')); }).catch(function (err) { should.exist(err); @@ -161,7 +161,7 @@ describe('Authentication API', function () { }); it('should not allow a password reset', function (done) { - authentication.resetPassword().then(function () { + AuthAPI.resetPassword().then(function () { done(new Error('Password was reset')); }).catch(function (err) { should.exist(err); diff --git a/core/test/integration/api/api_db_spec.js b/core/test/integration/api/api_db_spec.js index 43d2ee72b2..6d7eb554bb 100644 --- a/core/test/integration/api/api_db_spec.js +++ b/core/test/integration/api/api_db_spec.js @@ -1,21 +1,18 @@ /*globals describe, before, beforeEach, afterEach, it */ +/*jshint expr:true*/ var testUtils = require('../../utils'), should = require('should'), // Stuff we are testing permissions = require('../../../server/permissions'), - DataGenerator = require('../../utils/fixtures/data-generator'), dbAPI = require('../../../server/api/db'), TagsAPI = require('../../../server/api/tags'), PostAPI = require('../../../server/api/posts'); describe('DB API', function () { - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData().then(function () { @@ -29,11 +26,7 @@ describe('DB API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(dbAPI); it('delete all content', function (done) { var options = {context: {user: 1}}; @@ -62,17 +55,17 @@ describe('DB API', function () { permissions.init().then(function () { return dbAPI.deleteAllContent({context: {user: 2}}); }).then(function (){ - done(new Error("Delete all content is not denied for editor.")); + done(new Error('Delete all content is not denied for editor.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.deleteAllContent({context: {user: 3}}); }).then(function (){ - done(new Error("Delete all content is not denied for author.")); + done(new Error('Delete all content is not denied for author.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.deleteAllContent(); }).then(function (){ - done(new Error("Delete all content is not denied without authentication.")); + done(new Error('Delete all content is not denied without authentication.')); }).catch(function (error) { error.type.should.eql('NoPermissionError'); done(); @@ -83,17 +76,17 @@ describe('DB API', function () { permissions.init().then(function () { return dbAPI.exportContent({context: {user: 2}}); }).then(function (){ - done(new Error("Export content is not denied for editor.")); + done(new Error('Export content is not denied for editor.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.exportContent({context: {user: 3}}); }).then(function (){ - done(new Error("Export content is not denied for author.")); + done(new Error('Export content is not denied for author.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.exportContent(); }).then(function (){ - done(new Error("Export content is not denied without authentication.")); + done(new Error('Export content is not denied without authentication.')); }).catch(function (error) { error.type.should.eql('NoPermissionError'); done(); @@ -103,18 +96,18 @@ describe('DB API', function () { it('import content is denied', function (done) { permissions.init().then(function () { return dbAPI.importContent({context: {user: 2}}); - }).then(function (result) { - done(new Error("Import content is not denied for editor.")); + }).then(function () { + done(new Error('Import content is not denied for editor.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.importContent({context: {user: 3}}); - }).then(function (result) { - done(new Error("Import content is not denied for author.")); + }).then(function () { + done(new Error('Import content is not denied for author.')); }, function (error) { error.type.should.eql('NoPermissionError'); return dbAPI.importContent(); - }).then(function (result) { - done(new Error("Import content is not denied without authentication.")); + }).then(function () { + done(new Error('Import content is not denied without authentication.')); }).catch(function (error) { error.type.should.eql('NoPermissionError'); done(); diff --git a/core/test/integration/api/api_mail_spec.js b/core/test/integration/api/api_mail_spec.js index 238e114160..7107a4af29 100644 --- a/core/test/integration/api/api_mail_spec.js +++ b/core/test/integration/api/api_mail_spec.js @@ -1,25 +1,28 @@ /*globals describe, before, beforeEach, afterEach, it */ +/*jshint expr:true*/ var testUtils = require('../../utils'), should = require('should'), // Stuff we are testing permissions = require('../../../server/permissions'), - MailAPI = require('../../../server/api/mail'); - + MailAPI = require('../../../server/api/mail'), + mailData = { + mail: [{ + message: { + to: 'joe@example.com', + subject: 'testemail', + html: '<p>This</p>' + }, + options: {} + }] + }; describe('Mail API', function () { - var mailData = { - mail: [{ - message: { - to: 'joe@example.com', - subject: 'testemail', - html: '<p>This</p>' - }, - options: {} - }] - }; + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); - before(function (done) { + beforeEach(function (done) { testUtils.clearData() .then(function () { return testUtils.initData(); @@ -32,13 +35,7 @@ describe('Mail API', function () { }).catch(done); }); - - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - + should.exist(MailAPI); it('return correct failure message', function (done) { MailAPI.send(mailData, {context: {internal: true}}).then(function (response) { diff --git a/core/test/integration/api/api_notifications_spec.js b/core/test/integration/api/api_notifications_spec.js index afa93ac9e2..0eb8db45fb 100644 --- a/core/test/integration/api/api_notifications_spec.js +++ b/core/test/integration/api/api_notifications_spec.js @@ -1,19 +1,17 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - permissions = require('../../../server/permissions'), - DataGenerator = require('../../utils/fixtures/data-generator'), + permissions = require('../../../server/permissions'), NotificationsAPI = require('../../../server/api/notifications'); describe('Notifications API', function () { - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -26,11 +24,7 @@ describe('Notifications API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(NotificationsAPI); it('can add, adds defaults (internal)', function (done) { var msg = { @@ -102,7 +96,7 @@ describe('Notifications API', function () { type: 'error', // this can be 'error', 'success', 'warn' and 'info' message: 'This is an error' // A string. Should fit in one line. }; - NotificationsAPI.add({ notifications: [msg] }, {context: {internal: true}}).then(function (notification) { + NotificationsAPI.add({ notifications: [msg] }, {context: {internal: true}}).then(function () { NotificationsAPI.browse({context: {internal: true}}).then(function (results) { should.exist(results); should.exist(results.notifications); @@ -118,7 +112,7 @@ describe('Notifications API', function () { type: 'error', // this can be 'error', 'success', 'warn' and 'info' message: 'This is an error' // A string. Should fit in one line. }; - NotificationsAPI.add({ notifications: [msg] }, {context: {internal: true}}).then(function (notification) { + NotificationsAPI.add({ notifications: [msg] }, {context: {internal: true}}).then(function () { NotificationsAPI.browse({context: {user: 1}}).then(function (results) { should.exist(results); should.exist(results.notifications); diff --git a/core/test/integration/api/api_posts_spec.js b/core/test/integration/api/api_posts_spec.js index a5e4871375..4956dd1766 100644 --- a/core/test/integration/api/api_posts_spec.js +++ b/core/test/integration/api/api_posts_spec.js @@ -1,18 +1,16 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), + /*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - DataGenerator = require('../../utils/fixtures/data-generator'), PostAPI = require('../../../server/api/posts'); describe('Post API', function () { - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -24,11 +22,7 @@ describe('Post API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(PostAPI); it('can browse', function (done) { PostAPI.browse().then(function (results) { diff --git a/core/test/integration/api/api_settings_spec.js b/core/test/integration/api/api_settings_spec.js index 19751fac0e..1ee6a6ea4a 100644 --- a/core/test/integration/api/api_settings_spec.js +++ b/core/test/integration/api/api_settings_spec.js @@ -1,46 +1,22 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), - _ = require('lodash'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + _ = require('lodash'), // Stuff we are testing - permissions = require('../../../server/permissions'), - DataGenerator = require('../../utils/fixtures/data-generator'), - SettingsAPI = require('../../../server/api/settings'); + permissions = require('../../../server/permissions'), + SettingsAPI = require('../../../server/api/settings'), + defaultContext = {user: 1}, + internalContext = {internal: true}, + callApiWithContext, + getErrorDetails; describe('Settings API', function () { - var defaultContext = { - user: 1 - }, - internalContext = { - internal: true - }, - callApiWithContext = function (context, method) { - var args = _.toArray(arguments), - options = args[args.length - 1]; - - if (_.isObject(options)) { - options.context = _.clone(context); - } - - return SettingsAPI[method].apply({}, args.slice(2)); - }, - getErrorDetails = function (done) { - return function (err) { - if (err instanceof Error) { - return done(err); - } - - done(new Error(err.message)); - }; - }; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -58,11 +34,27 @@ describe('Settings API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(getErrorDetails(done)); - }); + should.exist(SettingsAPI); + + callApiWithContext = function (context, method) { + var args = _.toArray(arguments), + options = args[args.length - 1]; + + if (_.isObject(options)) { + options.context = _.clone(context); + } + + return SettingsAPI[method].apply({}, args.slice(2)); + }; + getErrorDetails = function (done) { + return function (err) { + if (err instanceof Error) { + return done(err); + } + + done(new Error(err.message)); + }; + }; it('uses Date objects for dateTime fields', function (done) { return callApiWithContext(defaultContext, 'browse', {}).then(function (results) { @@ -129,7 +121,7 @@ describe('Settings API', function () { }); it('cannot read core settings if not an internal request', function (done) { - return callApiWithContext(defaultContext, 'read', {key: 'databaseVersion'}).then(function (response) { + return callApiWithContext(defaultContext, 'read', {key: 'databaseVersion'}).then(function () { done(new Error('Allowed to read databaseVersion with external request')); }).catch(function (error) { should.exist(error); @@ -210,15 +202,16 @@ describe('Settings API', function () { }); it('does not allow an active theme which is not installed', function (done) { - return callApiWithContext(defaultContext, 'edit', 'activeTheme', { settings: [{ key: 'activeTheme', value: 'rasper' }] }) - .then(function (response) { - done(new Error('Allowed to set an active theme which is not installed')); - }).catch(function (err) { - should.exist(err); + return callApiWithContext(defaultContext, 'edit', 'activeTheme', { + settings: [{ key: 'activeTheme', value: 'rasper' }] + }).then(function () { + done(new Error('Allowed to set an active theme which is not installed')); + }).catch(function (err) { + should.exist(err); - err.type.should.eql('ValidationError'); + err.type.should.eql('ValidationError'); - done(); - }).catch(done); + done(); + }).catch(done); }); }); diff --git a/core/test/integration/api/api_slugs_spec.js b/core/test/integration/api/api_slugs_spec.js index bb1df2c6d7..35c433d4f8 100644 --- a/core/test/integration/api/api_slugs_spec.js +++ b/core/test/integration/api/api_slugs_spec.js @@ -1,16 +1,15 @@ -var testUtils = require('../../utils'), - should = require('should'), +/*globals describe, before, beforeEach, afterEach, it */ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), permissions = require('../../../server/permissions'), - slugAPI = require('../../../server/api/slugs'); + SlugAPI = require('../../../server/api/slugs'); describe('Slug API', function () { - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData().then(function () { @@ -22,14 +21,10 @@ describe('Slug API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(SlugAPI); it('can generate post slug', function (done) { - slugAPI.generate({ context: { user: 1 }, type: 'post', name: 'A fancy Title' }) + SlugAPI.generate({ context: { user: 1 }, type: 'post', name: 'A fancy Title' }) .then(function (results) { should.exist(results); testUtils.API.checkResponse(results, 'slugs'); @@ -41,7 +36,7 @@ describe('Slug API', function () { }); it('can generate tag slug', function (done) { - slugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'A fancy Title' }) + SlugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'A fancy Title' }) .then(function (results) { should.exist(results); testUtils.API.checkResponse(results, 'slugs'); @@ -53,7 +48,7 @@ describe('Slug API', function () { }); it('can generate user slug', function (done) { - slugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'user name' }) + SlugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'user name' }) .then(function (results) { should.exist(results); testUtils.API.checkResponse(results, 'slugs'); @@ -65,7 +60,7 @@ describe('Slug API', function () { }); it('can generate app slug', function (done) { - slugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'app name' }) + SlugAPI.generate({ context: { user: 1 }, type: 'tag', name: 'app name' }) .then(function (results) { should.exist(results); testUtils.API.checkResponse(results, 'slugs'); @@ -77,7 +72,7 @@ describe('Slug API', function () { }); it('rejects unknown types', function (done) { - slugAPI.generate({ context: { user: 1 }, type: 'unknown type', name: 'A fancy Title' }) + SlugAPI.generate({ context: { user: 1 }, type: 'unknown type', name: 'A fancy Title' }) .then(function () { done(new Error('Generate a slug for an unknown type is not rejected.')); }).catch(function (error) { diff --git a/core/test/integration/api/api_tags_spec.js b/core/test/integration/api/api_tags_spec.js index 2a12d381de..cbda057b3d 100644 --- a/core/test/integration/api/api_tags_spec.js +++ b/core/test/integration/api/api_tags_spec.js @@ -1,19 +1,16 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - permissions = require('../../../server/permissions'), - DataGenerator = require('../../utils/fixtures/data-generator'), - TagsAPI = require('../../../server/api/tags'); + permissions = require('../../../server/permissions'), + TagAPI = require('../../../server/api/tags'); describe('Tags API', function () { - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -30,14 +27,10 @@ describe('Tags API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(TagAPI); it('can browse (internal)', function (done) { - TagsAPI.browse({context: {internal: true}}).then(function (results) { + TagAPI.browse({context: {internal: true}}).then(function (results) { should.exist(results); should.exist(results.tags); results.tags.length.should.be.above(0); @@ -49,7 +42,7 @@ describe('Tags API', function () { }); it('can browse (admin)', function (done) { - TagsAPI.browse({context: {user: 1}}).then(function (results) { + TagAPI.browse({context: {user: 1}}).then(function (results) { should.exist(results); should.exist(results.tags); results.tags.length.should.be.above(0); @@ -61,7 +54,7 @@ describe('Tags API', function () { }); it('can browse (editor)', function (done) { - TagsAPI.browse({context: {user: 2}}).then(function (results) { + TagAPI.browse({context: {user: 2}}).then(function (results) { should.exist(results); should.exist(results.tags); results.tags.length.should.be.above(0); @@ -73,7 +66,7 @@ describe('Tags API', function () { }); it('can browse (author)', function (done) { - TagsAPI.browse({context: {user: 3}}).then(function (results) { + TagAPI.browse({context: {user: 3}}).then(function (results) { should.exist(results); should.exist(results.tags); results.tags.length.should.be.above(0); diff --git a/core/test/integration/api/api_themes_spec.js b/core/test/integration/api/api_themes_spec.js index 9fdb859c1e..15e86404cc 100644 --- a/core/test/integration/api/api_themes_spec.js +++ b/core/test/integration/api/api_themes_spec.js @@ -1,4 +1,5 @@ /*globals describe, before, beforeEach, afterEach, it */ +/*jshint expr:true*/ var _ = require('lodash'), testUtils = require('../../utils'), rewire = require('rewire'), @@ -8,7 +9,7 @@ var _ = require('lodash'), // Stuff we are testing permissions = require('../../../server/permissions'), - SettingsAPI = require('../../../server/api/settings'), + SettingsAPI = require('../../../server/api/settings'), ThemeAPI = rewire('../../../server/api/themes'); describe('Themes API', function () { @@ -16,8 +17,11 @@ describe('Themes API', function () { sandbox, settingsReadStub; - before(function (done) { + // Keep the DB clean + before(testUtils.teardown); + afterEach(function (done) { testUtils.clearData().then(function () { + sandbox.restore(); done(); }).catch(done); }); @@ -56,12 +60,7 @@ describe('Themes API', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - sandbox.restore(); - done(); - }).catch(done); - }); + should.exist(ThemeAPI); it('can browse', function (done) { var config; diff --git a/core/test/integration/api/api_upload_spec.js b/core/test/integration/api/api_upload_spec.js index 4bc797be29..43986a735e 100644 --- a/core/test/integration/api/api_upload_spec.js +++ b/core/test/integration/api/api_upload_spec.js @@ -1,121 +1,121 @@ /*globals describe, beforeEach, afterEach, it*/ /*jshint expr:true*/ -var fs = require('fs-extra'), - should = require('should'), - sinon = require('sinon'), - when = require('when'), - storage = require('../../../server/storage'), +var fs = require('fs-extra'), + should = require('should'), + sinon = require('sinon'), + when = require('when'), + storage = require('../../../server/storage'), // Stuff we are testing - UploadAPI = require('../../../server/api/upload'); + UploadAPI = require('../../../server/api/upload'), + store; // To stop jshint complaining should.equal(true, true); describe('Upload API', function () { - describe('upload', function () { + // Doesn't test the DB - var req, res, store; + afterEach(function () { + storage.get_storage.restore(); + fs.unlink.restore(); + }); - beforeEach(function () { - store = sinon.stub(); - store.save = sinon.stub().returns(when('URL')); - store.exists = sinon.stub().returns(when(true)); - store.destroy = sinon.stub().returns(when()); - sinon.stub(storage, 'get_storage').returns(store); - sinon.stub(fs, 'unlink').yields(); - }); + beforeEach(function () { + store = sinon.stub(); + store.save = sinon.stub().returns(when('URL')); + store.exists = sinon.stub().returns(when(true)); + store.destroy = sinon.stub().returns(when()); + sinon.stub(storage, 'get_storage').returns(store); + sinon.stub(fs, 'unlink').yields(); + }); - afterEach(function () { - storage.get_storage.restore(); - fs.unlink.restore(); - }); + should.exist(UploadAPI); - describe('can not upload invalid file', function () { - it('should return 415 for invalid file type', function (done) { - var uploadimage = { - name: 'INVALID.FILE', - type: 'application/octet-stream', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function () { - done(new Error('Upload suceeded with invalid file.')); - }, function (result) { - result.code.should.equal(415); - result.type.should.equal('UnsupportedMediaTypeError'); - done(); - }); - }); - }); - - describe('can not upload file with valid extension but invalid type', function () { - it('should return 415 for invalid file type', function (done) { - var uploadimage = { - name: 'INVALID.jpg', - type: 'application/octet-stream', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function () { - done(new Error('Upload suceeded with invalid file.')); - }, function (result) { - result.code.should.equal(415); - result.type.should.equal('UnsupportedMediaTypeError'); - done(); - }); - }); - }); - - describe('valid file', function () { - it('can upload jpg', function (done) { - var uploadimage = { - name: 'INVALID.jpg', - type: 'image/jpeg', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function (result) { - result.should.equal('URL'); + describe('invalid file', function () { + it('should return 415 for invalid file type', function (done) { + var uploadimage = { + name: 'INVALID.FILE', + type: 'application/octet-stream', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function () { + done(new Error('Upload suceeded with invalid file.')); + }, function (result) { + result.code.should.equal(415); + result.type.should.equal('UnsupportedMediaTypeError'); done(); - }); - }); + }); + }); - it('cannot upload jpg with incorrect extension', function (done) { - var uploadimage = { - name: 'INVALID.xjpg', - type: 'image/jpeg', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function (result) { - done(new Error('Upload suceeded with invalid file.')); - }, function (result) { - result.code.should.equal(415); - result.type.should.equal('UnsupportedMediaTypeError'); - done(); - }); - }); - - it('can upload png', function (done) { - var uploadimage = { - name: 'INVALID.png', - type: 'image/png', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function (result) { - result.should.equal('URL'); + describe('valid extension but invalid type', function () { + it('should return 415 for invalid file type', function (done) { + var uploadimage = { + name: 'INVALID.jpg', + type: 'application/octet-stream', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function () { + done(new Error('Upload suceeded with invalid file.')); + }, function (result) { + result.code.should.equal(415); + result.type.should.equal('UnsupportedMediaTypeError'); done(); - }); + }); + }); + }); + + describe('valid file', function () { + it('can upload jpg', function (done) { + var uploadimage = { + name: 'INVALID.jpg', + type: 'image/jpeg', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function (result) { + result.should.equal('URL'); + done(); }); - it('can upload gif', function (done) { - var uploadimage = { - name: 'INVALID.gif', - type: 'image/gif', - path: '/tmp/TMPFILEID' - }; - UploadAPI.add({uploadimage: uploadimage}).then(function (result) { - result.should.equal('URL'); + }); + + it('cannot upload jpg with incorrect extension', function (done) { + var uploadimage = { + name: 'INVALID.xjpg', + type: 'image/jpeg', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function () { + done(new Error('Upload suceeded with invalid file.')); + }, function (result) { + result.code.should.equal(415); + result.type.should.equal('UnsupportedMediaTypeError'); done(); - }); + }); + }); + + it('can upload png', function (done) { + var uploadimage = { + name: 'INVALID.png', + type: 'image/png', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function (result) { + result.should.equal('URL'); + done(); + }); + }); + + it('can upload gif', function (done) { + var uploadimage = { + name: 'INVALID.gif', + type: 'image/gif', + path: '/tmp/TMPFILEID' + }; + UploadAPI.add({uploadimage: uploadimage}).then(function (result) { + result.should.equal('URL'); + done(); }); }); }); diff --git a/core/test/integration/api/api_users_spec.js b/core/test/integration/api/api_users_spec.js index 1cb1a050a4..311ac35d14 100644 --- a/core/test/integration/api/api_users_spec.js +++ b/core/test/integration/api/api_users_spec.js @@ -1,53 +1,19 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), - - permissions = require('../../../server/permissions'), - UserModel = require('../../../server/models').User; +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - UsersAPI = require('../../../server/api/users'); - AuthAPI = require('../../../server/api/authentication'); + permissions = require('../../../server/permissions'), + UserModel = require('../../../server/models').User, + UsersAPI = require('../../../server/api/users'); describe('Users API', function () { + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - describe('No User', function () { - beforeEach(function (done) { - testUtils.initData().then(function () { - return permissions.init(); - }).then(function () { - done(); - }).catch(done); - }); - - it('can add with internal user', function (done) { - AuthAPI.setup({ setup: [{ - 'name': 'Hello World', - 'email': 'hello@world.com', - 'password': 'password' - }]}).then(function (results) { - should.exist(results); - testUtils.API.checkResponse(results, 'users'); - should.exist(results.users); - results.users.should.have.length(1); - testUtils.API.checkResponse(results.users[0], 'user', ['roles']); - results.users[0].name.should.equal('Hello World'); - done(); - }).catch(done); - }); - }); + should.exist(UsersAPI); describe('With Users', function () { beforeEach(function (done) { diff --git a/core/test/integration/model/model_app_fields_spec.js b/core/test/integration/model/model_app_fields_spec.js index a390d575b1..94162e4ed3 100644 --- a/core/test/integration/model/model_app_fields_spec.js +++ b/core/test/integration/model/model_app_fields_spec.js @@ -1,20 +1,16 @@ -/*globals describe, before, beforeEach, afterEach, after, it*/ -var testUtils = require('../../utils'), - should = require('should'), +/*globals describe, before, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + AppFieldsModel = require('../../../server/models').AppField, + context = {context: {user: 1}}; describe('App Fields Model', function () { - - var AppFieldsModel = Models.AppField; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -26,17 +22,7 @@ describe('App Fields Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - after(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(AppFieldsModel); it('can findAll', function (done) { AppFieldsModel.findAll().then(function (results) { diff --git a/core/test/integration/model/model_app_settings_spec.js b/core/test/integration/model/model_app_settings_spec.js index 765558ce1a..c9d7ab18d5 100644 --- a/core/test/integration/model/model_app_settings_spec.js +++ b/core/test/integration/model/model_app_settings_spec.js @@ -1,20 +1,16 @@ -/*globals describe, before, beforeEach, afterEach, after, it*/ -var testUtils = require('../../utils'), - should = require('should'), +/*globals describe, before, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + AppSettingModel = require('../../../server/models').AppSetting, + context = {context: {user: 1}}; describe('App Setting Model', function () { - - var AppSettingModel = Models.AppSetting; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -26,17 +22,7 @@ describe('App Setting Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - after(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(AppSettingModel); it('can findAll', function (done) { AppSettingModel.findAll().then(function (results) { diff --git a/core/test/integration/model/model_apps_spec.js b/core/test/integration/model/model_apps_spec.js index 0ce9cd1b27..6cbb2777a9 100644 --- a/core/test/integration/model/model_apps_spec.js +++ b/core/test/integration/model/model_apps_spec.js @@ -1,22 +1,19 @@ -/*globals describe, before, beforeEach, afterEach, after, it*/ -var testUtils = require('../../utils'), - sequence = require('when/sequence'), - should = require('should'), - _ = require('lodash'), +/*globals describe, before, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + sequence = require('when/sequence'), + _ = require('lodash'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + Models = require('../../../server/models'), + context = {context: {user: 1}}, + AppModel = Models.App; describe('App Model', function () { - - var AppModel = Models.App; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -28,17 +25,7 @@ describe('App Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - after(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(AppModel); it('can findAll', function (done) { AppModel.findAll().then(function (results) { diff --git a/core/test/integration/model/model_permissions_spec.js b/core/test/integration/model/model_permissions_spec.js index 8a33e11d0c..d353fa36a1 100644 --- a/core/test/integration/model/model_permissions_spec.js +++ b/core/test/integration/model/model_permissions_spec.js @@ -1,22 +1,16 @@ /*globals describe, it, before, beforeEach, afterEach */ -var testUtils = require('../../utils'), - should = require('should'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + PermissionModel = require('../../../server/models').Permission, + context = {context: {user: 1}}; describe('Permission Model', function () { - - var PermissionModel = Models.Permission; - - should.exist(PermissionModel); - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData().then(function () { @@ -24,11 +18,7 @@ describe('Permission Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(PermissionModel); it('can findAll', function (done) { PermissionModel.findAll().then(function (foundPermissions) { diff --git a/core/test/integration/model/model_posts_spec.js b/core/test/integration/model/model_posts_spec.js index b7a2bc83f0..6ed8cd59f7 100644 --- a/core/test/integration/model/model_posts_spec.js +++ b/core/test/integration/model/model_posts_spec.js @@ -1,23 +1,19 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - should = require('should'), - _ = require('lodash'), - sequence = require('when/sequence'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + sequence = require('when/sequence'), + _ = require('lodash'), // Stuff we are testing - Models = require('../../../server/models'), - DataGenerator = testUtils.DataGenerator, - context = {context: {user: 1}}; + PostModel = require('../../../server/models').Post, + DataGenerator = testUtils.DataGenerator, + context = {context: {user: 1}}; describe('Post Model', function () { - - var PostModel = Models.Post; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -29,11 +25,7 @@ describe('Post Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(PostModel); function checkFirstPostData(firstPost) { should.not.exist(firstPost.author_id); diff --git a/core/test/integration/model/model_roles_spec.js b/core/test/integration/model/model_roles_spec.js index d3596deb79..8f6704b448 100644 --- a/core/test/integration/model/model_roles_spec.js +++ b/core/test/integration/model/model_roles_spec.js @@ -1,22 +1,16 @@ /*globals describe, it, before, beforeEach, afterEach */ -var testUtils = require('../../utils'), - should = require('should'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + RoleModel = require('../../../server/models').Role, + context = {context: {user: 1}}; describe('Role Model', function () { - - var RoleModel = Models.Role; - - should.exist(RoleModel); - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData().then(function () { @@ -24,11 +18,7 @@ describe('Role Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(RoleModel); it('can findAll', function (done) { RoleModel.findAll().then(function (foundRoles) { diff --git a/core/test/integration/model/model_settings_spec.js b/core/test/integration/model/model_settings_spec.js index c08f352e66..30a98aeaeb 100644 --- a/core/test/integration/model/model_settings_spec.js +++ b/core/test/integration/model/model_settings_spec.js @@ -1,21 +1,17 @@ -/*globals describe, before, beforeEach, afterEach, after, it*/ -var testUtils = require('../../utils'), - should = require('should'), +/*globals describe, before, beforeEach, afterEach, it*/ +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), // Stuff we are testing - Models = require('../../../server/models'), - config = require('../../../server/config'), - context = {context: {user: 1}}; + SettingsModel = require('../../../server/models').Settings, + config = require('../../../server/config'), + context = {context: {user: 1}}; describe('Settings Model', function () { - - var SettingsModel = Models.Settings; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData().then(function () { @@ -23,17 +19,7 @@ describe('Settings Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - after(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(SettingsModel); describe('API', function () { diff --git a/core/test/integration/model/model_tags_spec.js b/core/test/integration/model/model_tags_spec.js index a8fb21c2a5..43dea23828 100644 --- a/core/test/integration/model/model_tags_spec.js +++ b/core/test/integration/model/model_tags_spec.js @@ -1,23 +1,20 @@ /*globals describe, before, beforeEach, afterEach, it */ -var testUtils = require('../../utils'), - _ = require("lodash"), - when = require('when'), - sequence = require('when/sequence'), - should = require('should'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + when = require('when'), + _ = require('lodash'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + Models = require('../../../server/models'), + TagModel = Models.Tag, + PostModel = Models.Post, + context = {context: {user: 1}}; describe('Tag Model', function () { - - var TagModel = Models.Tag; - - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); beforeEach(function (done) { testUtils.initData() @@ -26,11 +23,7 @@ describe('Tag Model', function () { }).catch(done); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(TagModel); it('uses Date objects for dateTime fields', function (done) { TagModel.add(testUtils.DataGenerator.forModel.tags[0], context).then(function (tag) { @@ -44,7 +37,6 @@ describe('Tag Model', function () { }); describe('a Post', function () { - var PostModel = Models.Post; it('can add a tag', function (done) { var newPost = testUtils.DataGenerator.forModel.posts[0], @@ -118,7 +110,7 @@ describe('Tag Model', function () { attachOperations; attachOperations = []; - for (var i = 1; i < models.length; i++) { + for (var i = 1; i < models.length; i += 1) { attachOperations.push(postModel.tags().attach(models[i])); } diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index c4d9ce5dbe..803bdf57b4 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -1,29 +1,22 @@ /*globals describe, before, beforeEach, afterEach, it*/ -var testUtils = require('../../utils'), - should = require('should'), - when = require('when'), - sinon = require('sinon'), - uuid = require('node-uuid'), +/*jshint expr:true*/ +var testUtils = require('../../utils'), + should = require('should'), + when = require('when'), + sinon = require('sinon'), + uuid = require('node-uuid'), // Stuff we are testing - Models = require('../../../server/models'), - context = {context: {user: 1}}; + UserModel = require('../../../server/models').User, + context = {context: {user: 1}}; describe('User Model', function run() { - var UserModel = Models.User; + // Keep the DB clean + before(testUtils.teardown); + afterEach(testUtils.teardown); - before(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); - - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + should.exist(UserModel); describe('Registration', function runRegistration() { beforeEach(function (done) { @@ -41,8 +34,8 @@ describe('User Model', function run() { UserModel.add(userData, context).then(function (createdUser) { should.exist(createdUser); createdUser.has('uuid').should.equal(true); - createdUser.attributes.password.should.not.equal(userData.password, "password was hashed"); - createdUser.attributes.email.should.eql(userData.email, "email address correct"); + createdUser.attributes.password.should.not.equal(userData.password, 'password was hashed'); + createdUser.attributes.email.should.eql(userData.email, 'email address correct'); gravatarStub.restore(); done(); }).catch(done); @@ -57,7 +50,7 @@ describe('User Model', function run() { UserModel.add(userData, context).then(function (createdUser) { should.exist(createdUser); createdUser.has('uuid').should.equal(true); - createdUser.attributes.email.should.eql(userData.email, "email address correct"); + createdUser.attributes.email.should.eql(userData.email, 'email address correct'); gravatarStub.restore(); done(); }).catch(done); @@ -73,7 +66,9 @@ describe('User Model', function run() { UserModel.add(userData, context).then(function (createdUser) { should.exist(createdUser); createdUser.has('uuid').should.equal(true); - createdUser.attributes.image.should.eql('http://www.gravatar.com/avatar/2fab21a4c4ed88e76add10650c73bae1?d=404', 'Gravatar found'); + createdUser.attributes.image.should.eql( + 'http://www.gravatar.com/avatar/2fab21a4c4ed88e76add10650c73bae1?d=404', 'Gravatar found' + ); gravatarStub.restore(); done(); }).catch(done); @@ -346,12 +341,12 @@ describe('User Model', function run() { }).then(function (token) { return UserModel.validateToken(token, dbHash); }).then(function () { - throw new Error("Allowed expired token"); + throw new Error('Allowed expired token'); }).catch(function (err) { should.exist(err); - err.message.should.equal("Expired token"); + err.message.should.equal('Expired token'); done(); }); @@ -381,12 +376,12 @@ describe('User Model', function run() { return UserModel.validateToken(fakeToken, dbHash); }).then(function () { - throw new Error("allowed invalid token"); + throw new Error('allowed invalid token'); }).catch(function (err) { should.exist(err); - err.message.should.equal("Invalid token"); + err.message.should.equal('Invalid token'); done(); }); diff --git a/core/test/integration/update_check_spec.js b/core/test/integration/update_check_spec.js index 9e45a19336..43eae81fa9 100644 --- a/core/test/integration/update_check_spec.js +++ b/core/test/integration/update_check_spec.js @@ -18,7 +18,10 @@ describe('Update Check', function () { return testUtils.clearData(); }).then(function () { done(); - }).catch(done); + }).catch(function (err) { + console.log('Update Check before error', err); + throw new Error(err); + }); }); after(function () { @@ -36,14 +39,13 @@ describe('Update Check', function () { return permissions.init(); }).then(function () { done(); - }).catch(done); + }).catch(function (err) { + console.log('Update Check beforeEach error', err); + throw new Error(err); + }); }); - afterEach(function (done) { - testUtils.clearData().then(function () { - done(); - }).catch(done); - }); + afterEach(testUtils.teardown); it('should report the correct data', function (done) { var updateCheckData = updateCheck.__get__('updateCheckData'); diff --git a/core/test/utils/index.js b/core/test/utils/index.js index d05ab311b9..c8ae2af860 100644 --- a/core/test/utils/index.js +++ b/core/test/utils/index.js @@ -8,7 +8,9 @@ var knex = require('../../server/models/base').knex, migration = require('../../server/data/migration/'), DataGenerator = require('./fixtures/data-generator'), API = require('./api'), - fork = require('./fork'); + fork = require('./fork'), + + teardown; function initData() { return migration.init(); @@ -49,7 +51,7 @@ function insertMorePosts(max) { return sequence(_.times(posts.length, function(index) { return function() { return knex('posts').insert(posts[index]); - } + }; })); } @@ -218,7 +220,15 @@ function loadExportFixture(filename) { }); } +teardown = function (done) { + migration.reset().then(function () { + done(); + }).catch(done); +}; + module.exports = { + teardown: teardown, + initData: initData, clearData: clearData, insertDefaultFixtures: insertDefaultFixtures,