Refactored tests to destructure common lib import (#11838)

This commit is contained in:
Vikas Potluri 2020-05-25 03:49:38 -05:00 committed by GitHub
parent 9254f94407
commit a9cb8adacc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 389 additions and 398 deletions

View File

@ -10,11 +10,11 @@ const testUtils = require('../../utils/index');
const configUtils = require('../../utils/configUtils'); const configUtils = require('../../utils/configUtils');
const urlUtils = require('../../utils/urlUtils'); const urlUtils = require('../../utils/urlUtils');
const ghost = testUtils.startGhost; const ghost = testUtils.startGhost;
const common = require('../../../core/server/lib/common/index'); const {i18n} = require('../../../core/server/lib/common/index');
const config = require('../../../core/server/config/index'); const config = require('../../../core/server/config/index');
let request; let request;
common.i18n.init(); i18n.init();
describe('Admin Routing', function () { describe('Admin Routing', function () {
function doEnd(done) { function doEnd(done) {

View File

@ -4,7 +4,7 @@ const Promise = require('bluebird');
const moment = require('moment-timezone'); const moment = require('moment-timezone');
const rewire = require('rewire'); const rewire = require('rewire');
const _ = require('lodash'); const _ = require('lodash');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const models = require('../../../../core/server/models'); const models = require('../../../../core/server/models');
const testUtils = require('../../../utils'); const testUtils = require('../../../utils');
const sequence = require('../../../../core/server/lib/promise/sequence'); const sequence = require('../../../../core/server/lib/promise/sequence');
@ -26,7 +26,7 @@ describe('Models: listeners', function () {
beforeEach(testUtils.setup('owner', 'settings')); beforeEach(testUtils.setup('owner', 'settings'));
beforeEach(function () { beforeEach(function () {
sinon.stub(common.events, 'on').callsFake(function (eventName, callback) { sinon.stub(events, 'on').callsFake(function (eventName, callback) {
eventsToRemember[eventName] = callback; eventsToRemember[eventName] = callback;
}); });
@ -34,7 +34,7 @@ describe('Models: listeners', function () {
}); });
afterEach(function () { afterEach(function () {
common.events.on.restore(); events.on.restore();
sinon.restore(); sinon.restore();
scope.posts = []; scope.posts = [];
return testUtils.teardownDb(); return testUtils.teardownDb();

View File

@ -1,3 +1,4 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
@ -9,9 +10,8 @@ const urlService = require('../../../core/frontend/services/url');
const ghostBookshelf = require('../../../core/server/models/base'); const ghostBookshelf = require('../../../core/server/models/base');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const settingsCache = require('../../../core/server/services/settings/cache'); const settingsCache = require('../../../core/server/services/settings/cache');
const common = require('../../../core/server/lib/common'); const {events} = require('../../../core/server/lib/common');
const configUtils = require('../../utils/configUtils'); const configUtils = require('../../utils/configUtils');
const DataGenerator = testUtils.DataGenerator;
const context = testUtils.context.owner; const context = testUtils.context.owner;
const markdownToMobiledoc = testUtils.DataGenerator.markdownToMobiledoc; const markdownToMobiledoc = testUtils.DataGenerator.markdownToMobiledoc;
@ -185,7 +185,7 @@ describe('Post Model', function () {
beforeEach(function () { beforeEach(function () {
eventsTriggered = {}; eventsTriggered = {};
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) { sinon.stub(events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) { if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = []; eventsTriggered[eventName] = [];
} }
@ -276,7 +276,7 @@ describe('Post Model', function () {
}).then(function () { }).then(function () {
done(new Error('expected validation error')); done(new Error('expected validation error'));
}).catch(function (err) { }).catch(function (err) {
(err[0] instanceof common.errors.ValidationError).should.eql(true); (err[0] instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -347,7 +347,7 @@ describe('Post Model', function () {
done(new Error('expected error')); done(new Error('expected error'));
}).catch(function (err) { }).catch(function (err) {
should.exist(err); should.exist(err);
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -500,7 +500,7 @@ describe('Post Model', function () {
done(new Error('change status from published to scheduled is not allowed right now!')); done(new Error('change status from published to scheduled is not allowed right now!'));
}).catch(function (err) { }).catch(function (err) {
should.exist(err); should.exist(err);
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -703,7 +703,7 @@ describe('Post Model', function () {
beforeEach(function () { beforeEach(function () {
eventsTriggered = {}; eventsTriggered = {};
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) { sinon.stub(events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) { if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = []; eventsTriggered[eventName] = [];
} }
@ -927,7 +927,7 @@ describe('Post Model', function () {
mobiledoc: markdownToMobiledoc('This is some content') mobiledoc: markdownToMobiledoc('This is some content')
}, context).catch(function (err) { }, context).catch(function (err) {
should.exist(err); should.exist(err);
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
Object.keys(eventsTriggered).length.should.eql(0); Object.keys(eventsTriggered).length.should.eql(0);
done(); done();
}); });
@ -941,7 +941,7 @@ describe('Post Model', function () {
mobiledoc: markdownToMobiledoc('This is some content') mobiledoc: markdownToMobiledoc('This is some content')
}, context).catch(function (err) { }, context).catch(function (err) {
should.exist(err); should.exist(err);
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
Object.keys(eventsTriggered).length.should.eql(0); Object.keys(eventsTriggered).length.should.eql(0);
done(); done();
}); });
@ -954,7 +954,7 @@ describe('Post Model', function () {
title: 'scheduled 1', title: 'scheduled 1',
mobiledoc: markdownToMobiledoc('This is some content') mobiledoc: markdownToMobiledoc('This is some content')
}, context).catch(function (err) { }, context).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
Object.keys(eventsTriggered).length.should.eql(0); Object.keys(eventsTriggered).length.should.eql(0);
done(); done();
}); });
@ -1177,7 +1177,7 @@ describe('Post Model', function () {
beforeEach(function () { beforeEach(function () {
eventsTriggered = {}; eventsTriggered = {};
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) { sinon.stub(events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) { if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = []; eventsTriggered[eventName] = [];
} }

View File

@ -1,3 +1,4 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
@ -5,7 +6,7 @@ const Promise = require('bluebird');
const _ = require('lodash'); const _ = require('lodash');
// Stuff we are testing // Stuff we are testing
const common = require('../../../core/server/lib/common'); const {events} = require('../../../core/server/lib/common');
const imageLib = require('../../../core/server/lib/image'); const imageLib = require('../../../core/server/lib/image');
const UserModel = require('../../../core/server/models/user').User; const UserModel = require('../../../core/server/models/user').User;
@ -156,7 +157,7 @@ describe('User Model', function run() {
beforeEach(function () { beforeEach(function () {
eventsTriggered = {}; eventsTriggered = {};
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) { sinon.stub(events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) { if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = []; eventsTriggered[eventName] = [];
} }
@ -326,7 +327,7 @@ describe('User Model', function run() {
done(new Error('Already existing email address was accepted')); done(new Error('Already existing email address was accepted'));
}) })
.catch(function (err) { .catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -430,7 +431,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -444,7 +445,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -458,7 +459,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -472,7 +473,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -486,7 +487,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -500,7 +501,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -514,7 +515,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });
@ -528,7 +529,7 @@ describe('User Model', function run() {
}, testUtils.context.owner).then(function () { }, testUtils.context.owner).then(function () {
done(new Error('expected error!')); done(new Error('expected error!'));
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.ValidationError).should.eql(true); (err instanceof errors.ValidationError).should.eql(true);
done(); done();
}); });
}); });

View File

@ -5,7 +5,7 @@ const rewire = require('rewire');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
const configUtils = require('../../utils/configUtils'); const configUtils = require('../../utils/configUtils');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const common = require('../../../core/server/lib/common'); const {events} = require('../../../core/server/lib/common');
const themes = require('../../../core/frontend/services/themes'); const themes = require('../../../core/frontend/services/themes');
const UrlService = rewire('../../../core/frontend/services/url/UrlService'); const UrlService = rewire('../../../core/frontend/services/url/UrlService');
@ -109,12 +109,12 @@ describe('Integration: services/url/UrlService', function () {
} }
}); });
common.events.emit('router.created', router1); events.emit('router.created', router1);
common.events.emit('router.created', router2); events.emit('router.created', router2);
common.events.emit('router.created', router3); events.emit('router.created', router3);
common.events.emit('router.created', router4); events.emit('router.created', router4);
common.events.emit('db.ready'); events.emit('db.ready');
let timeout; let timeout;
(function retry() { (function retry() {
@ -312,13 +312,13 @@ describe('Integration: services/url/UrlService', function () {
} }
}); });
common.events.emit('router.created', router1); events.emit('router.created', router1);
common.events.emit('router.created', router2); events.emit('router.created', router2);
common.events.emit('router.created', router3); events.emit('router.created', router3);
common.events.emit('router.created', router4); events.emit('router.created', router4);
common.events.emit('router.created', router5); events.emit('router.created', router5);
common.events.emit('db.ready'); events.emit('db.ready');
let timeout; let timeout;
(function retry() { (function retry() {
@ -509,13 +509,13 @@ describe('Integration: services/url/UrlService', function () {
} }
}); });
common.events.emit('router.created', router1); events.emit('router.created', router1);
common.events.emit('router.created', router2); events.emit('router.created', router2);
common.events.emit('router.created', router3); events.emit('router.created', router3);
common.events.emit('router.created', router4); events.emit('router.created', router4);
common.events.emit('router.created', router5); events.emit('router.created', router5);
common.events.emit('db.ready'); events.emit('db.ready');
let timeout; let timeout;
(function retry() { (function retry() {

View File

@ -1,10 +1,11 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const moment = require('moment'); const moment = require('moment');
const testUtils = require('../../../../utils'); const testUtils = require('../../../../utils');
const common = require('../../../../../core/server/lib/common');
const models = require('../../../../../core/server/models'); const models = require('../../../../../core/server/models');
const {events} = require('../../../../../core/server/lib/common');
const api = require('../../../../../core/server/api'); const api = require('../../../../../core/server/api');
const schedulingUtils = require('../../../../../core/server/adapters/scheduling/utils'); const schedulingUtils = require('../../../../../core/server/adapters/scheduling/utils');
const SchedulingDefault = require('../../../../../core/server/adapters/scheduling/SchedulingDefault'); const SchedulingDefault = require('../../../../../core/server/adapters/scheduling/SchedulingDefault');
@ -38,7 +39,7 @@ describe.skip('Scheduling: Post Scheduling', function () {
return Promise.resolve({posts: scope.scheduledPosts}); return Promise.resolve({posts: scope.scheduledPosts});
}); });
sinon.stub(common.events, 'onMany').callsFake(function (events, stubDone) { sinon.stub(events, 'onMany').callsFake(function (events, stubDone) {
events.forEach(function (event) { events.forEach(function (event) {
scope.events[event] = stubDone; scope.events[event] = stubDone;
}); });
@ -100,7 +101,7 @@ describe.skip('Scheduling: Post Scheduling', function () {
postScheduling.init() postScheduling.init()
.catch(function (err) { .catch(function (err) {
should.exist(err); should.exist(err);
(err instanceof common.errors.IncorrectUsageError).should.eql(true); (err instanceof errors.IncorrectUsageError).should.eql(true);
done(); done();
}); });
}); });

View File

@ -1,10 +1,10 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const fs = require('fs-extra'); const fs = require('fs-extra');
const moment = require('moment'); const moment = require('moment');
const Promise = require('bluebird'); const Promise = require('bluebird');
const path = require('path'); const path = require('path');
const common = require('../../../../core/server/lib/common');
const LocalFileStore = require('../../../../core/server/adapters/storage/LocalFileStorage'); const LocalFileStore = require('../../../../core/server/adapters/storage/LocalFileStorage');
let localFileStore; let localFileStore;
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
@ -168,7 +168,7 @@ describe('Local File System Storage', function () {
done(new Error('image should not exist')); done(new Error('image should not exist'));
}) })
.catch(function (err) { .catch(function (err) {
(err instanceof common.errors.NotFoundError).should.eql(true); (err instanceof errors.NotFoundError).should.eql(true);
err.code.should.eql('ENOENT'); err.code.should.eql('ENOENT');
done(); done();
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: canary/utils/validators/input/pages', function () { describe('Unit: canary/utils/validators/input/pages', function () {
@ -25,7 +25,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: canary/utils/validators/input/posts', function () { describe('Unit: canary/utils/validators/input/posts', function () {
@ -25,7 +25,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: canary/utils/validators/input/tags', function () { describe('Unit: canary/utils/validators/input/tags', function () {
@ -25,7 +25,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -166,7 +166,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -191,7 +191,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -206,7 +206,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -222,7 +222,7 @@ describe('Unit: canary/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,7 +1,7 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../core/server/lib/common');
const shared = require('../../../../core/server/api/shared'); const shared = require('../../../../core/server/api/shared');
describe('Unit: api/shared/pipeline', function () { describe('Unit: api/shared/pipeline', function () {
@ -100,7 +100,7 @@ describe('Unit: api/shared/pipeline', function () {
return shared.pipeline.STAGES.permissions(apiUtils, apiConfig, apiImpl, frame) return shared.pipeline.STAGES.permissions(apiUtils, apiConfig, apiImpl, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
apiUtils.permissions.handle.called.should.be.false(); apiUtils.permissions.handle.called.should.be.false();
}); });
}); });

View File

@ -1,7 +1,7 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const Promise = require('bluebird'); const Promise = require('bluebird');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common');
const shared = require('../../../../../core/server/api/shared'); const shared = require('../../../../../core/server/api/shared');
describe('Unit: api/shared/serializers/handle', function () { describe('Unit: api/shared/serializers/handle', function () {
@ -14,7 +14,7 @@ describe('Unit: api/shared/serializers/handle', function () {
return shared.serializers.handle.input() return shared.serializers.handle.input()
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });
@ -22,7 +22,7 @@ describe('Unit: api/shared/serializers/handle', function () {
return shared.serializers.handle.input({}) return shared.serializers.handle.input({})
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });
@ -68,7 +68,7 @@ describe('Unit: api/shared/serializers/handle', function () {
return shared.serializers.handle.output([]) return shared.serializers.handle.output([])
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });
@ -76,7 +76,7 @@ describe('Unit: api/shared/serializers/handle', function () {
return shared.serializers.handle.output([], {}) return shared.serializers.handle.output([], {})
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });

View File

@ -1,7 +1,6 @@
const should = require('should'); const errors = require('@tryghost/errors');
const Promise = require('bluebird'); const Promise = require('bluebird');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common');
const shared = require('../../../../../core/server/api/shared'); const shared = require('../../../../../core/server/api/shared');
describe('Unit: api/shared/validators/handle', function () { describe('Unit: api/shared/validators/handle', function () {
@ -14,7 +13,7 @@ describe('Unit: api/shared/validators/handle', function () {
return shared.validators.handle.input() return shared.validators.handle.input()
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });
@ -22,7 +21,7 @@ describe('Unit: api/shared/validators/handle', function () {
return shared.validators.handle.input({}) return shared.validators.handle.input({})
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.IncorrectUsageError).should.be.true(); (err instanceof errors.IncorrectUsageError).should.be.true();
}); });
}); });

View File

@ -1,7 +1,7 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../core/server/lib/common');
const shared = require('../../../../../../core/server/api/shared'); const shared = require('../../../../../../core/server/api/shared');
describe('Unit: api/shared/validators/input/all', function () { describe('Unit: api/shared/validators/input/all', function () {
@ -398,7 +398,7 @@ describe('Unit: api/shared/validators/input/all', function () {
return shared.validators.input.all.edit(apiConfig, frame) return shared.validators.input.all.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.BadRequestError).should.be.true(); (err instanceof errors.BadRequestError).should.be.true();
}); });
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/v2/utils/validators'); const validators = require('../../../../../../../core/server/api/v2/utils/validators');
describe('Unit: v2/utils/validators/input/pages', function () { describe('Unit: v2/utils/validators/input/pages', function () {
@ -25,7 +25,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/v2/utils/validators'); const validators = require('../../../../../../../core/server/api/v2/utils/validators');
describe('Unit: v2/utils/validators/input/posts', function () { describe('Unit: v2/utils/validators/input/posts', function () {
@ -25,7 +25,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/v2/utils/validators'); const validators = require('../../../../../../../core/server/api/v2/utils/validators');
describe('Unit: v2/utils/validators/input/tags', function () { describe('Unit: v2/utils/validators/input/tags', function () {
@ -25,7 +25,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -166,7 +166,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -191,7 +191,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -206,7 +206,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -222,7 +222,7 @@ describe('Unit: v2/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: v3/utils/validators/input/pages', function () { describe('Unit: v3/utils/validators/input/pages', function () {
@ -25,7 +25,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.add(apiConfig, frame) return validators.input.pages.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
return validators.input.pages.edit(apiConfig, frame) return validators.input.pages.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: v3/utils/validators/input/posts', function () { describe('Unit: v3/utils/validators/input/posts', function () {
@ -25,7 +25,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -172,7 +172,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -198,7 +198,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -220,7 +220,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.add(apiConfig, frame) return validators.input.posts.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -260,7 +260,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -275,7 +275,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -291,7 +291,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -327,7 +327,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -349,7 +349,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
return validators.input.posts.edit(apiConfig, frame) return validators.input.posts.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,8 +1,8 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../../../../../core/server/lib/common');
const validators = require('../../../../../../../core/server/api/canary/utils/validators'); const validators = require('../../../../../../../core/server/api/canary/utils/validators');
describe('Unit: v3/utils/validators/input/tags', function () { describe('Unit: v3/utils/validators/input/tags', function () {
@ -25,7 +25,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -40,7 +40,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -55,7 +55,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -71,7 +71,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -88,7 +88,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -166,7 +166,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.add(apiConfig, frame) return validators.input.tags.add(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -191,7 +191,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -206,7 +206,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });
@ -222,7 +222,7 @@ describe('Unit: v3/utils/validators/input/tags', function () {
return validators.input.tags.edit(apiConfig, frame) return validators.input.tags.edit(apiConfig, frame)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
}); });
}); });

View File

@ -1,10 +1,10 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const path = require('path'); const path = require('path');
const ampController = require('../../../../core/frontend/apps/amp/lib/router'); const ampController = require('../../../../core/frontend/apps/amp/lib/router');
const urlService = require('../../../../core/frontend/services/url'); const urlService = require('../../../../core/frontend/services/url');
const helpers = require('../../../../core/frontend/services/routing/helpers'); const helpers = require('../../../../core/frontend/services/routing/helpers');
const common = require('../../../../core/server/lib/common');
const testUtils = require('../../../utils'); const testUtils = require('../../../utils');
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
@ -71,7 +71,7 @@ describe('Unit - apps/amp/lib/router', function () {
req.body = {}; req.body = {};
ampController.renderer(req, res, function (err) { ampController.renderer(req, res, function (err) {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
helpers.renderer.called.should.be.false(); helpers.renderer.called.should.be.false();
done(); done();
}); });
@ -85,7 +85,7 @@ describe('Unit - apps/amp/lib/router', function () {
}; };
ampController.renderer(req, res, function (err) { ampController.renderer(req, res, function (err) {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
helpers.renderer.called.should.be.false(); helpers.renderer.called.should.be.false();
done(); done();
}); });
@ -158,10 +158,10 @@ describe('Unit - apps/amp/lib/router', function () {
urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/'); urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/');
helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'postsPublic', resource: 'posts'}}) helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/', query: {controller: 'postsPublic', resource: 'posts'}})
.rejects(new common.errors.NotFoundError()); .rejects(new errors.NotFoundError());
ampController.getPostData(req, res, function (err) { ampController.getPostData(req, res, function (err) {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
done(); done();
}); });
}); });

View File

@ -1,8 +1,7 @@
const should = require('should'); const errors = require('@tryghost/errors');
const sinon = require('sinon'); const sinon = require('sinon');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs-extra'); const fs = require('fs-extra');
const common = require('../../../../core/server/lib/common');
const settingsCache = require('../../../../core/server/services/settings/cache'); const settingsCache = require('../../../../core/server/services/settings/cache');
const privateBlogging = require('../../../../core/frontend/apps/private-blogging/lib/middleware'); const privateBlogging = require('../../../../core/frontend/apps/private-blogging/lib/middleware');
@ -248,7 +247,7 @@ describe('Private Blogging', function () {
privateBlogging.filterPrivateRoutes(req, res, next); privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
(next.firstCall.args[0] instanceof common.errors.NotFoundError).should.eql(true); (next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
}); });
it('filterPrivateRoutes should 404 for /rss requests', function () { it('filterPrivateRoutes should 404 for /rss requests', function () {
@ -265,7 +264,7 @@ describe('Private Blogging', function () {
privateBlogging.filterPrivateRoutes(req, res, next); privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
(next.firstCall.args[0] instanceof common.errors.NotFoundError).should.eql(true); (next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
}); });
it('filterPrivateRoutes should 404 for rss with pagination requests', function () { it('filterPrivateRoutes should 404 for rss with pagination requests', function () {
@ -282,7 +281,7 @@ describe('Private Blogging', function () {
privateBlogging.filterPrivateRoutes(req, res, next); privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
(next.firstCall.args[0] instanceof common.errors.NotFoundError).should.eql(true); (next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
}); });
it('filterPrivateRoutes should 404 for tag rss requests', function () { it('filterPrivateRoutes should 404 for tag rss requests', function () {
@ -299,7 +298,7 @@ describe('Private Blogging', function () {
privateBlogging.filterPrivateRoutes(req, res, next); privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
(next.firstCall.args[0] instanceof common.errors.NotFoundError).should.eql(true); (next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
}); });
it('filterPrivateRoutes should return next if tag contains rss', function () { it('filterPrivateRoutes should return next if tag contains rss', function () {

View File

@ -1,3 +1,4 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const rewire = require('rewire'); const rewire = require('rewire');
@ -6,7 +7,6 @@ const _ = require('lodash');
const testUtils = require('../../../utils'); const testUtils = require('../../../utils');
const moment = require('moment'); const moment = require('moment');
const path = require('path'); const path = require('path');
const common = require('../../../../core/server/lib/common');
// Stuff we are testing // Stuff we are testing
const ImportManager = require('../../../../core/server/data/importer'); const ImportManager = require('../../../../core/server/data/importer');
@ -172,13 +172,13 @@ describe('Importer', function () {
it('fails a zip with two base directories', function () { it('fails a zip with two base directories', function () {
const testDir = path.resolve('test/utils/fixtures/import/zips/zip-with-double-base-dir'); const testDir = path.resolve('test/utils/fixtures/import/zips/zip-with-double-base-dir');
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError); ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(errors.UnsupportedMediaTypeError);
}); });
it('fails a zip with no content', function () { it('fails a zip with no content', function () {
const testDir = path.resolve('test/utils/fixtures/import/zips/zip-invalid'); const testDir = path.resolve('test/utils/fixtures/import/zips/zip-invalid');
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError); ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(errors.UnsupportedMediaTypeError);
}); });
it('shows a special error for old Roon exports', function () { it('shows a special error for old Roon exports', function () {
@ -187,7 +187,7 @@ describe('Importer', function () {
const msg = 'Your zip file looks like an old format Roon export, ' + const msg = 'Your zip file looks like an old format Roon export, ' +
'please re-export your Roon blog and try again.'; 'please re-export your Roon blog and try again.';
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(common.errors.UnsupportedMediaTypeError); ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(errors.UnsupportedMediaTypeError);
ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(msg); ImportManager.isValidZip.bind(ImportManager, testDir).should.throw(msg);
}); });
}); });

View File

@ -1,10 +1,9 @@
const should = require('should'); const errors = require('@tryghost/errors');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc; const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc;
const helpers = require('../../../core/frontend/helpers'); const helpers = require('../../../core/frontend/helpers');
const api = require('../../../core/server/api'); const api = require('../../../core/server/api');
const common = require('../../../core/server/lib/common');
// These helpers are the same, their name just changes // These helpers are the same, their name just changes
helpers.next_post = helpers.prev_post; helpers.next_post = helpers.prev_post;
@ -404,7 +403,7 @@ describe('{{next_post}} helper', function () {
describe('general error handling', function () { describe('general error handling', function () {
beforeEach(function () { beforeEach(function () {
browsePostsStub = sinon.stub().callsFake(function () { browsePostsStub = sinon.stub().callsFake(function () {
return Promise.reject(new common.errors.NotFoundError({message: 'Something wasn\'t found'})); return Promise.reject(new errors.NotFoundError({message: 'Something wasn\'t found'}));
}); });
}); });

View File

@ -1,10 +1,9 @@
const should = require('should'); const errors = require('@tryghost/errors');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc; const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc;
const helpers = require('../../../core/frontend/helpers'); const helpers = require('../../../core/frontend/helpers');
const api = require('../../../core/server/api'); const api = require('../../../core/server/api');
const common = require('../../../core/server/lib/common');
describe('{{prev_post}} helper', function () { describe('{{prev_post}} helper', function () {
let browsePostsStub; let browsePostsStub;
@ -399,7 +398,7 @@ describe('{{prev_post}} helper', function () {
describe('general error handling', function () { describe('general error handling', function () {
beforeEach(function () { beforeEach(function () {
browsePostsStub = sinon.stub().callsFake(function (options) { browsePostsStub = sinon.stub().callsFake(function (options) {
return Promise.reject(new common.errors.NotFoundError({message: 'Something wasn\'t found'})); return Promise.reject(new errors.NotFoundError({message: 'Something wasn\'t found'}));
}); });
}); });

View File

@ -1,9 +1,9 @@
const should = require('should'); const should = require('should');
const common = require('../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
describe('Errors', function () { describe('Errors', function () {
it('Ensure we inherit from Error', function () { it('Ensure we inherit from Error', function () {
const ghostError = new common.errors.GhostError(); const ghostError = new errors.GhostError();
(ghostError instanceof Error).should.eql(true); (ghostError instanceof Error).should.eql(true);
}); });
@ -16,7 +16,7 @@ describe('Errors', function () {
someError.context = 'test'; someError.context = 'test';
someError.help = 'test'; someError.help = 'test';
ghostError = new common.errors.GhostError({err: someError}); ghostError = new errors.GhostError({err: someError});
ghostError.stack.should.match(/Error: test/); ghostError.stack.should.match(/Error: test/);
ghostError.context.should.eql(someError.context); ghostError.context.should.eql(someError.context);
ghostError.help.should.eql(someError.help); ghostError.help.should.eql(someError.help);
@ -30,7 +30,7 @@ describe('Errors', function () {
a: 'b' a: 'b'
}; };
ghostError = new common.errors.GhostError({ ghostError = new errors.GhostError({
err: someError err: someError
}); });
@ -43,7 +43,7 @@ describe('Errors', function () {
someError.context = 'test'; someError.context = 'test';
ghostError = new common.errors.GhostError({ ghostError = new errors.GhostError({
err: someError, err: someError,
context: 'context' context: 'context'
}); });
@ -55,7 +55,7 @@ describe('Errors', function () {
const someError = new Error(); const someError = new Error();
let ghostError; let ghostError;
ghostError = new common.errors.GhostError({ ghostError = new errors.GhostError({
err: someError, err: someError,
message: 'test' message: 'test'
}); });
@ -64,7 +64,7 @@ describe('Errors', function () {
}); });
it('error is string', function () { it('error is string', function () {
const ghostError = new common.errors.GhostError({ const ghostError = new errors.GhostError({
err: 'string' err: 'string'
}); });

View File

@ -1,10 +1,10 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const _ = require('lodash'); const _ = require('lodash');
const Promise = require('bluebird'); const Promise = require('bluebird');
const security = require('../../../../core/server/lib/security'); const security = require('../../../../core/server/lib/security');
const models = require('../../../../core/server/models'); const models = require('../../../../core/server/models');
const common = require('../../../../core/server/lib/common');
const urlUtils = require('../../../../core/server/lib/url-utils'); const urlUtils = require('../../../../core/server/lib/url-utils');
const testUtils = require('../../../utils'); const testUtils = require('../../../utils');
@ -356,7 +356,7 @@ describe('Models: base', function () {
return models.Base.Model.edit(data, unfilteredOptions).then(() => { return models.Base.Model.edit(data, unfilteredOptions).then(() => {
throw new Error('That should not happen'); throw new Error('That should not happen');
}).catch((err) => { }).catch((err) => {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
}); });
}); });
}); });

View File

@ -1,10 +1,8 @@
const should = require('should'); const errors = require('@tryghost/errors');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird'); const Promise = require('bluebird');
const common = require('../../../core/server/lib/common');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const settingsCache = require('../../../core/server/services/settings/cache'); const settingsCache = require('../../../core/server/services/settings/cache');
const testUtils = require('../../utils');
describe('Unit: models/invite', function () { describe('Unit: models/invite', function () {
before(function () { before(function () {
@ -46,7 +44,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NotFoundError).should.eql(true); (err instanceof errors.NotFoundError).should.eql(true);
}); });
}); });
@ -57,7 +55,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -141,7 +139,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -152,7 +150,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -183,7 +181,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -194,7 +192,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -205,7 +203,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -216,7 +214,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
}); });
@ -233,7 +231,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -244,7 +242,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -255,7 +253,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
@ -266,7 +264,7 @@ describe('Unit: models/invite', function () {
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true) return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
.then(Promise.reject) .then(Promise.reject)
.catch((err) => { .catch((err) => {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
}); });
}); });
}); });

View File

@ -1,14 +1,11 @@
/* eslint no-invalid-this:0 */ /* eslint no-invalid-this:0 */
const _ = require('lodash'); const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
const knex = require('../../../core/server/data/db').knex; const knex = require('../../../core/server/data/db').knex;
const urlService = require('../../../core/frontend/services/url'); const urlService = require('../../../core/frontend/services/url');
const schema = require('../../../core/server/data/schema');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const common = require('../../../core/server/lib/common');
const security = require('../../../core/server/lib/security'); const security = require('../../../core/server/lib/security');
describe('Unit: models/post', function () { describe('Unit: models/post', function () {
@ -390,7 +387,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -420,7 +417,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -449,7 +446,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.calledOnce).be.true(); should(mockPostObj.get.calledOnce).be.true();
should(mockPostObj.related.called).be.false(); should(mockPostObj.related.called).be.false();
done(); done();
@ -478,7 +475,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledTwice).be.false(); should(mockPostObj.related.calledTwice).be.false();
done(); done();
@ -538,7 +535,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.callCount).eql(3); should(mockPostObj.get.callCount).eql(3);
should(mockPostObj.related.callCount).eql(1); should(mockPostObj.related.callCount).eql(1);
done(); done();
@ -569,7 +566,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.callCount).eql(1); should(mockPostObj.get.callCount).eql(1);
should(mockPostObj.related.callCount).eql(0); should(mockPostObj.related.callCount).eql(0);
done(); done();
@ -626,7 +623,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -651,7 +648,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -676,7 +673,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -701,7 +698,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -726,7 +723,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -802,7 +799,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.calledOnce).be.true(); should(mockPostObj.get.calledOnce).be.true();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -831,7 +828,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.calledOnce).be.true(); should(mockPostObj.get.calledOnce).be.true();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -892,7 +889,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -922,7 +919,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -951,7 +948,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledTwice).be.true(); should(mockPostObj.related.calledTwice).be.true();
done(); done();
@ -981,7 +978,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.calledOnce).be.true(); should(mockPostObj.get.calledOnce).be.true();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -1010,7 +1007,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledTwice).be.true(); should(mockPostObj.related.calledTwice).be.true();
done(); done();
@ -1040,7 +1037,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.calledOnce).be.true(); should(mockPostObj.get.calledOnce).be.true();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();
@ -1070,7 +1067,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
mockPostObj.get.callCount.should.eql(1); mockPostObj.get.callCount.should.eql(1);
mockPostObj.related.callCount.should.eql(2); mockPostObj.related.callCount.should.eql(2);
done(); done();
@ -1124,7 +1121,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -1152,7 +1149,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
done(); done();
}); });
@ -1205,7 +1202,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
).then(() => { ).then(() => {
done(new Error('Permissible function should have rejected.')); done(new Error('Permissible function should have rejected.'));
}).catch((error) => { }).catch((error) => {
error.should.be.an.instanceof(common.errors.NoPermissionError); error.should.be.an.instanceof(errors.NoPermissionError);
should(mockPostObj.get.called).be.false(); should(mockPostObj.get.called).be.false();
should(mockPostObj.related.calledOnce).be.true(); should(mockPostObj.related.calledOnce).be.true();
done(); done();

View File

@ -5,8 +5,8 @@ const errors = require('@tryghost/errors');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const permissions = require('../../../core/server/services/permissions'); const permissions = require('../../../core/server/services/permissions');
const validation = require('../../../core/server/data/validation'); const validation = require('../../../core/server/data/validation');
const {errors: commonErrors} = require('../../../core/server/lib/common');
const security = require('../../../core/server/lib/security'); const security = require('../../../core/server/lib/security');
const common = require('../../../core/server/lib/common');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
describe('Unit: models/user', function () { describe('Unit: models/user', function () {
@ -144,7 +144,7 @@ describe('Unit: models/user', function () {
return models.User.check({email: user.get('email'), password: 'test'}) return models.User.check({email: user.get('email'), password: 'test'})
.catch(function (err) { .catch(function (err) {
(err instanceof common.errors.PasswordResetRequiredError).should.eql(true); (err instanceof commonErrors.PasswordResetRequiredError).should.eql(true);
}); });
}); });
}); });

View File

@ -1,11 +1,9 @@
const errors = require('@tryghost/errors');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const Promise = require('bluebird');
const apiKeyAuth = require('../../../../../core/server/services/auth/api-key'); const apiKeyAuth = require('../../../../../core/server/services/auth/api-key');
const common = require('../../../../../core/server/lib/common');
const models = require('../../../../../core/server/models'); const models = require('../../../../../core/server/models');
const testUtils = require('../../../../utils');
describe('Admin API Key Auth', function () { describe('Admin API Key Auth', function () {
before(models.init); before(models.init);
@ -117,7 +115,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('INVALID_AUTH_HEADER'); err.code.should.eql('INVALID_AUTH_HEADER');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();
@ -135,7 +133,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.BadRequestError, true); should.equal(err instanceof errors.BadRequestError, true);
err.code.should.eql('INVALID_JWT'); err.code.should.eql('INVALID_JWT');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();
@ -162,7 +160,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('UNKNOWN_ADMIN_API_KEY'); err.code.should.eql('UNKNOWN_ADMIN_API_KEY');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();
@ -191,7 +189,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('INVALID_JWT'); err.code.should.eql('INVALID_JWT');
err.message.should.match(/jwt expired/); err.message.should.match(/jwt expired/);
should.not.exist(req.api_key); should.not.exist(req.api_key);
@ -221,7 +219,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('INVALID_JWT'); err.code.should.eql('INVALID_JWT');
err.message.should.match(/maxAge exceeded/); err.message.should.match(/maxAge exceeded/);
should.not.exist(req.api_key); should.not.exist(req.api_key);
@ -251,7 +249,7 @@ describe('Admin API Key Auth', function () {
apiKeyAuth.admin.authenticate(req, res, function next(err) { apiKeyAuth.admin.authenticate(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('INVALID_API_KEY_TYPE'); err.code.should.eql('INVALID_API_KEY_TYPE');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();

View File

@ -1,4 +1,4 @@
const common = require('../../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const {authenticateContentApiKey} = require('../../../../../core/server/services/auth/api-key/content'); const {authenticateContentApiKey} = require('../../../../../core/server/services/auth/api-key/content');
const models = require('../../../../../core/server/models'); const models = require('../../../../../core/server/models');
const should = require('should'); const should = require('should');
@ -53,7 +53,7 @@ describe('Content API Key Auth', function () {
authenticateContentApiKey(req, res, function next(err) { authenticateContentApiKey(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('UNKNOWN_CONTENT_API_KEY'); err.code.should.eql('UNKNOWN_CONTENT_API_KEY');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();
@ -72,7 +72,7 @@ describe('Content API Key Auth', function () {
authenticateContentApiKey(req, res, function next(err) { authenticateContentApiKey(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.UnauthorizedError, true); should.equal(err instanceof errors.UnauthorizedError, true);
err.code.should.eql('INVALID_API_KEY_TYPE'); err.code.should.eql('INVALID_API_KEY_TYPE');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();
@ -89,7 +89,7 @@ describe('Content API Key Auth', function () {
authenticateContentApiKey(req, res, function next(err) { authenticateContentApiKey(req, res, function next(err) {
should.exist(err); should.exist(err);
should.equal(err instanceof common.errors.BadRequestError, true); should.equal(err instanceof errors.BadRequestError, true);
err.code.should.eql('INVALID_REQUEST'); err.code.should.eql('INVALID_REQUEST');
should.not.exist(req.api_key); should.not.exist(req.api_key);
done(); done();

View File

@ -5,7 +5,7 @@ const mail = require('../../../../core/server/services/mail');
const settingsCache = require('../../../../core/server/services/settings/cache'); const settingsCache = require('../../../../core/server/services/settings/cache');
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
const urlUtils = require('../../../../core/server/lib/url-utils'); const urlUtils = require('../../../../core/server/lib/url-utils');
const common = require('../../../../core/server/lib/common'); const {i18n} = require('../../../../core/server/lib/common');
let mailer; let mailer;
// Mock SMTP config // Mock SMTP config
@ -40,7 +40,7 @@ const mailDataIncomplete = {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
common.i18n.init(); i18n.init();
describe('Mail: Ghostmailer', function () { describe('Mail: Ghostmailer', function () {
afterEach(function () { afterEach(function () {

View File

@ -1,6 +1,6 @@
const should = require('should'); const should = require('should');
const _ = require('lodash'); const _ = require('lodash');
const common = require('../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const applyPublicRules = require('../../../../core/server/services/permissions/public'); const applyPublicRules = require('../../../../core/server/services/permissions/public');
describe('Permissions', function () { describe('Permissions', function () {
@ -54,7 +54,7 @@ describe('Permissions', function () {
applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () { applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
done(); done();
}); });
}); });
@ -65,7 +65,7 @@ describe('Permissions', function () {
applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () { applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
done(); done();
}); });
}); });
@ -94,7 +94,7 @@ describe('Permissions', function () {
applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () { applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
done(); done();
}); });
}); });
@ -105,7 +105,7 @@ describe('Permissions', function () {
applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () { applyPublicRules('posts', 'browse', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
done(); done();
}); });
}); });
@ -116,14 +116,14 @@ describe('Permissions', function () {
applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () { applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
draft = {context: {}, data: {status: 'draft', uuid: '1234-abcd', slug: 'abcd'}}; draft = {context: {}, data: {status: 'draft', uuid: '1234-abcd', slug: 'abcd'}};
return applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () { return applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () {
done('Did not throw an error for draft'); done('Did not throw an error for draft');
}).catch(function (err) { }).catch(function (err) {
(err instanceof common.errors.NoPermissionError).should.eql(true); (err instanceof errors.NoPermissionError).should.eql(true);
done(); done();
}); });
}); });

View File

@ -2,7 +2,7 @@ const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const express = require('../../../../core/shared/express')._express; const express = require('../../../../core/shared/express')._express;
const settingsCache = require('../../../../core/server/services/settings/cache'); const settingsCache = require('../../../../core/server/services/settings/cache');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const controllers = require('../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../core/frontend/services/routing/controllers');
const CollectionRouter = require('../../../../core/frontend/services/routing/CollectionRouter'); const CollectionRouter = require('../../../../core/frontend/services/routing/CollectionRouter');
const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}}; const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}};
@ -13,8 +13,8 @@ describe('UNIT - services/routing/CollectionRouter', function () {
let next; let next;
beforeEach(function () { beforeEach(function () {
sinon.stub(common.events, 'emit'); sinon.stub(events, 'emit');
sinon.stub(common.events, 'on'); sinon.stub(events, 'on');
sinon.spy(CollectionRouter.prototype, 'mountRoute'); sinon.spy(CollectionRouter.prototype, 'mountRoute');
sinon.spy(CollectionRouter.prototype, 'mountRouter'); sinon.spy(CollectionRouter.prototype, 'mountRouter');
@ -43,10 +43,10 @@ describe('UNIT - services/routing/CollectionRouter', function () {
collectionRouter.templates.should.eql([]); collectionRouter.templates.should.eql([]);
collectionRouter.getPermalinks().getValue().should.eql('/:slug/'); collectionRouter.getPermalinks().getValue().should.eql('/:slug/');
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', collectionRouter).should.be.true(); events.emit.calledWith('router.created', collectionRouter).should.be.true();
common.events.on.calledTwice.should.be.false(); events.on.calledTwice.should.be.false();
collectionRouter.mountRoute.callCount.should.eql(3); collectionRouter.mountRoute.callCount.should.eql(3);
express.Router.param.callCount.should.eql(2); express.Router.param.callCount.should.eql(2);
@ -92,10 +92,10 @@ describe('UNIT - services/routing/CollectionRouter', function () {
collectionRouter.templates.should.eql([]); collectionRouter.templates.should.eql([]);
collectionRouter.getPermalinks().getValue().should.eql('/blog/:year/:slug/'); collectionRouter.getPermalinks().getValue().should.eql('/blog/:year/:slug/');
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', collectionRouter).should.be.true(); events.emit.calledWith('router.created', collectionRouter).should.be.true();
common.events.on.calledTwice.should.be.false(); events.on.calledTwice.should.be.false();
collectionRouter.mountRoute.callCount.should.eql(3); collectionRouter.mountRoute.callCount.should.eql(3);
@ -190,7 +190,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
sinon.stub(collectionRouter, 'emit'); sinon.stub(collectionRouter, 'emit');
common.events.on.args[0][1]({ events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'}, attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'Europe/London'} _previousAttributes: {value: 'Europe/London'}
}); });
@ -203,7 +203,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
sinon.stub(collectionRouter, 'emit'); sinon.stub(collectionRouter, 'emit');
common.events.on.args[0][1]({ events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'}, attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'America/Los_Angeles'} _previousAttributes: {value: 'America/Los_Angeles'}
}); });
@ -218,7 +218,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
sinon.stub(collectionRouter, 'emit'); sinon.stub(collectionRouter, 'emit');
common.events.on.args[0][1]({ events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'}, attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'Europe/London'} _previousAttributes: {value: 'Europe/London'}
}); });
@ -231,7 +231,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
sinon.stub(collectionRouter, 'emit'); sinon.stub(collectionRouter, 'emit');
common.events.on.args[0][1]({ events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'}, attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'America/Los_Angeles'} _previousAttributes: {value: 'America/Los_Angeles'}
}); });

View File

@ -1,7 +1,7 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const controllers = require('../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../core/frontend/services/routing/controllers');
const RSSRouter = require('../../../../core/frontend/services/routing/RSSRouter'); const RSSRouter = require('../../../../core/frontend/services/routing/RSSRouter');
const urlUtils = require('../../../../core/server/lib/url-utils'); const urlUtils = require('../../../../core/server/lib/url-utils');
@ -9,8 +9,8 @@ const urlUtils = require('../../../../core/server/lib/url-utils');
describe('UNIT - services/routing/RSSRouter', function () { describe('UNIT - services/routing/RSSRouter', function () {
describe('instantiate', function () { describe('instantiate', function () {
beforeEach(function () { beforeEach(function () {
sinon.stub(common.events, 'emit'); sinon.stub(events, 'emit');
sinon.stub(common.events, 'on'); sinon.stub(events, 'on');
sinon.spy(RSSRouter.prototype, 'mountRoute'); sinon.spy(RSSRouter.prototype, 'mountRoute');
sinon.spy(RSSRouter.prototype, 'mountRouter'); sinon.spy(RSSRouter.prototype, 'mountRouter');
@ -29,8 +29,8 @@ describe('UNIT - services/routing/RSSRouter', function () {
should.exist(rssRouter.router); should.exist(rssRouter.router);
rssRouter.route.value.should.eql('/rss/'); rssRouter.route.value.should.eql('/rss/');
common.events.emit.calledOnce.should.be.false(); events.emit.calledOnce.should.be.false();
common.events.on.calledOnce.should.be.false(); events.on.calledOnce.should.be.false();
rssRouter.mountRoute.callCount.should.eql(2); rssRouter.mountRoute.callCount.should.eql(2);
@ -47,8 +47,8 @@ describe('UNIT - services/routing/RSSRouter', function () {
should.exist(rssRouter.router); should.exist(rssRouter.router);
rssRouter.route.value.should.eql('/rss/'); rssRouter.route.value.should.eql('/rss/');
common.events.emit.calledOnce.should.be.false(); events.emit.calledOnce.should.be.false();
common.events.on.calledOnce.should.be.false(); events.on.calledOnce.should.be.false();
rssRouter.mountRoute.callCount.should.eql(2); rssRouter.mountRoute.callCount.should.eql(2);

View File

@ -1,6 +1,6 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const controllers = require('../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../core/frontend/services/routing/controllers');
const StaticRoutesRouter = require('../../../../core/frontend/services/routing/StaticRoutesRouter'); const StaticRoutesRouter = require('../../../../core/frontend/services/routing/StaticRoutesRouter');
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
@ -15,8 +15,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
}); });
beforeEach(function () { beforeEach(function () {
sinon.stub(common.events, 'emit'); sinon.stub(events, 'emit');
sinon.stub(common.events, 'on'); sinon.stub(events, 'on');
sinon.spy(StaticRoutesRouter.prototype, 'mountRoute'); sinon.spy(StaticRoutesRouter.prototype, 'mountRoute');
sinon.spy(StaticRoutesRouter.prototype, 'mountRouter'); sinon.spy(StaticRoutesRouter.prototype, 'mountRouter');
@ -42,8 +42,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
staticRoutesRouter.templates.should.eql(['test']); staticRoutesRouter.templates.should.eql(['test']);
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', staticRoutesRouter).should.be.true(); events.emit.calledWith('router.created', staticRoutesRouter).should.be.true();
staticRoutesRouter.mountRoute.callCount.should.eql(1); staticRoutesRouter.mountRoute.callCount.should.eql(1);
@ -64,8 +64,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
should.not.exist(staticRoutesRouter.getFilter()); should.not.exist(staticRoutesRouter.getFilter());
staticRoutesRouter.templates.should.eql([]); staticRoutesRouter.templates.should.eql([]);
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', staticRoutesRouter).should.be.true(); events.emit.calledWith('router.created', staticRoutesRouter).should.be.true();
staticRoutesRouter.mountRoute.callCount.should.eql(1); staticRoutesRouter.mountRoute.callCount.should.eql(1);
@ -124,8 +124,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
staticRoutesRouter.templates.should.eql([]); staticRoutesRouter.templates.should.eql([]);
should.exist(staticRoutesRouter.data); should.exist(staticRoutesRouter.data);
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', staticRoutesRouter).should.be.true(); events.emit.calledWith('router.created', staticRoutesRouter).should.be.true();
staticRoutesRouter.mountRoute.callCount.should.eql(2); staticRoutesRouter.mountRoute.callCount.should.eql(2);
@ -151,8 +151,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
staticRoutesRouter.templates.should.eql([]); staticRoutesRouter.templates.should.eql([]);
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', staticRoutesRouter).should.be.true(); events.emit.calledWith('router.created', staticRoutesRouter).should.be.true();
staticRoutesRouter.mountRoute.callCount.should.eql(2); staticRoutesRouter.mountRoute.callCount.should.eql(2);

View File

@ -2,7 +2,7 @@ const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const _ = require('lodash'); const _ = require('lodash');
const settingsCache = require('../../../../core/server/services/settings/cache'); const settingsCache = require('../../../../core/server/services/settings/cache');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const controllers = require('../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../core/frontend/services/routing/controllers');
const TaxonomyRouter = require('../../../../core/frontend/services/routing/TaxonomyRouter'); const TaxonomyRouter = require('../../../../core/frontend/services/routing/TaxonomyRouter');
const RESOURCE_CONFIG_V2 = require('../../../../core/frontend/services/routing/config/v2'); const RESOURCE_CONFIG_V2 = require('../../../../core/frontend/services/routing/config/v2');
@ -17,8 +17,8 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
beforeEach(function () { beforeEach(function () {
sinon.stub(settingsCache, 'get').withArgs('permalinks').returns('/:slug/'); sinon.stub(settingsCache, 'get').withArgs('permalinks').returns('/:slug/');
sinon.stub(common.events, 'emit'); sinon.stub(events, 'emit');
sinon.stub(common.events, 'on'); sinon.stub(events, 'on');
sinon.spy(TaxonomyRouter.prototype, 'mountRoute'); sinon.spy(TaxonomyRouter.prototype, 'mountRoute');
sinon.spy(TaxonomyRouter.prototype, 'mountRouter'); sinon.spy(TaxonomyRouter.prototype, 'mountRouter');
@ -43,8 +43,8 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
taxonomyRouter.taxonomyKey.should.eql('tag'); taxonomyRouter.taxonomyKey.should.eql('tag');
taxonomyRouter.getPermalinks().getValue().should.eql('/tag/:slug/'); taxonomyRouter.getPermalinks().getValue().should.eql('/tag/:slug/');
common.events.emit.calledOnce.should.be.true(); events.emit.calledOnce.should.be.true();
common.events.emit.calledWith('router.created', taxonomyRouter).should.be.true(); events.emit.calledWith('router.created', taxonomyRouter).should.be.true();
taxonomyRouter.mountRouter.callCount.should.eql(1); taxonomyRouter.mountRouter.callCount.should.eql(1);
taxonomyRouter.mountRouter.args[0][0].should.eql('/tag/:slug/'); taxonomyRouter.mountRouter.args[0][0].should.eql('/tag/:slug/');

View File

@ -1,7 +1,7 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const testUtils = require('../../../../utils'); const testUtils = require('../../../../utils');
const common = require('../../../../../core/server/lib/common');
const security = require('../../../../../core/server/lib/security'); const security = require('../../../../../core/server/lib/security');
const themeService = require('../../../../../core/frontend/services/themes'); const themeService = require('../../../../../core/frontend/services/themes');
const controllers = require('../../../../../core/frontend/services/routing/controllers'); const controllers = require('../../../../../core/frontend/services/routing/controllers');
@ -151,7 +151,7 @@ describe('Unit - services/routing/controllers/channel', function () {
}); });
controllers.channel(req, res, function (err) { controllers.channel(req, res, function (err) {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
themeService.getActive.calledOnce.should.be.true(); themeService.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false(); security.string.safe.calledOnce.should.be.false();

View File

@ -1,7 +1,7 @@
const errors = require('@tryghost/errors');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const testUtils = require('../../../../utils'); const testUtils = require('../../../../utils');
const common = require('../../../../../core/server/lib/common');
const security = require('../../../../../core/server/lib/security'); const security = require('../../../../../core/server/lib/security');
const themeService = require('../../../../../core/frontend/services/themes'); const themeService = require('../../../../../core/frontend/services/themes');
const urlService = require('../../../../../core/frontend/services/url'); const urlService = require('../../../../../core/frontend/services/url');
@ -160,7 +160,7 @@ describe('Unit - services/routing/controllers/collection', function () {
}); });
controllers.collection(req, res, function (err) { controllers.collection(req, res, function (err) {
(err instanceof common.errors.NotFoundError).should.be.true(); (err instanceof errors.NotFoundError).should.be.true();
themeService.getActive.calledOnce.should.be.true(); themeService.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false(); security.string.safe.calledOnce.should.be.false();

View File

@ -1,6 +1,6 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const helpers = require('../../../../../core/frontend/services/routing/helpers'); const helpers = require('../../../../../core/frontend/services/routing/helpers');
describe('handleError', function () { describe('handleError', function () {
@ -15,7 +15,7 @@ describe('handleError', function () {
}); });
it('should call next with no args for 404 errors', function () { it('should call next with no args for 404 errors', function () {
const notFoundError = new common.errors.NotFoundError({message: 'Something wasn\'t found'}); const notFoundError = new errors.NotFoundError({message: 'Something wasn\'t found'});
helpers.handleError(next)(notFoundError); helpers.handleError(next)(notFoundError);
next.calledOnce.should.be.true(); next.calledOnce.should.be.true();

View File

@ -1,6 +1,6 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const urlUtils = require('../../../../../core/server/lib/url-utils'); const urlUtils = require('../../../../../core/server/lib/url-utils');
const middlewares = require('../../../../../core/frontend/services/routing/middlewares'); const middlewares = require('../../../../../core/frontend/services/routing/middlewares');
@ -52,7 +52,7 @@ describe('UNIT: services/routing/middlewares/page-param', function () {
urlUtils.redirect301.called.should.be.false(); urlUtils.redirect301.called.should.be.false();
next.calledOnce.should.be.true(); next.calledOnce.should.be.true();
(next.args[0][0] instanceof common.errors.NotFoundError).should.be.true(); (next.args[0][0] instanceof errors.NotFoundError).should.be.true();
}); });
it('404 for /page/something/', function () { it('404 for /page/something/', function () {
@ -63,7 +63,7 @@ describe('UNIT: services/routing/middlewares/page-param', function () {
urlUtils.redirect301.called.should.be.false(); urlUtils.redirect301.called.should.be.false();
next.calledOnce.should.be.true(); next.calledOnce.should.be.true();
(next.args[0][0] instanceof common.errors.NotFoundError).should.be.true(); (next.args[0][0] instanceof errors.NotFoundError).should.be.true();
}); });
it('redirect for /rss/page/1/', function () { it('redirect for /rss/page/1/', function () {

View File

@ -4,7 +4,7 @@ const rewire = require('rewire');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const configUtils = require('../../../utils/configUtils'); const configUtils = require('../../../utils/configUtils');
const common = require('../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const loadSettings = rewire('../../../../core/frontend/services/settings/loader'); const loadSettings = rewire('../../../../core/frontend/services/settings/loader');
describe('UNIT > Settings Service loader:', function () { describe('UNIT > Settings Service loader:', function () {
@ -57,7 +57,7 @@ describe('UNIT > Settings Service loader:', function () {
}); });
it('can handle errors from YAML parser', function (done) { it('can handle errors from YAML parser', function (done) {
yamlParserStub.throws(new common.errors.GhostError({ yamlParserStub.throws(new errors.GhostError({
message: 'could not parse yaml file', message: 'could not parse yaml file',
context: 'bad indentation of a mapping entry at line 5, column 10' context: 'bad indentation of a mapping entry at line 5, column 10'
})); }));

View File

@ -1,7 +1,7 @@
const sinon = require('sinon'); const sinon = require('sinon');
const should = require('should'); const should = require('should');
const rewire = require('rewire'); const rewire = require('rewire');
const common = require('../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const settings = rewire('../../../../core/frontend/services/settings'); const settings = rewire('../../../../core/frontend/services/settings');
describe('UNIT > Settings Service:', function () { describe('UNIT > Settings Service:', function () {
@ -62,7 +62,7 @@ describe('UNIT > Settings Service:', function () {
}); });
it('passes SettingsLoader error through', function (done) { it('passes SettingsLoader error through', function (done) {
settingsLoaderStub.throws(new common.errors.GhostError({message: 'oops'})); settingsLoaderStub.throws(new errors.GhostError({message: 'oops'}));
settings.__set__('SettingsLoader', settingsLoaderStub); settings.__set__('SettingsLoader', settingsLoaderStub);
try { try {
@ -120,7 +120,7 @@ describe('UNIT > Settings Service:', function () {
it('passes SettinsLoader error through', function (done) { it('passes SettinsLoader error through', function (done) {
settingsLoaderStub.onFirstCall().returns(settingsStubFile1); settingsLoaderStub.onFirstCall().returns(settingsStubFile1);
settingsLoaderStub.onSecondCall().throws(new common.errors.GhostError({message: 'oops'})); settingsLoaderStub.onSecondCall().throws(new errors.GhostError({message: 'oops'}));
settings.__set__('SettingsLoader', settingsLoaderStub); settings.__set__('SettingsLoader', settingsLoaderStub);
try { try {

View File

@ -1,6 +1,6 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../core/server/lib/common'); const errors = require('@tryghost/errors');
const themesService = require('../../../../core/frontend/services/themes'); const themesService = require('../../../../core/frontend/services/themes');
const validate = require('../../../../core/frontend/services/settings/validate'); const validate = require('../../../../core/frontend/services/settings/validate');
@ -45,7 +45,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -60,7 +60,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -75,7 +75,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -90,7 +90,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -105,7 +105,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -120,7 +120,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -135,7 +135,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -152,7 +152,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -169,7 +169,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -186,7 +186,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -203,7 +203,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -220,7 +220,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -703,7 +703,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -723,7 +723,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -743,7 +743,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -765,7 +765,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -785,7 +785,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -818,7 +818,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -833,7 +833,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -848,7 +848,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -863,7 +863,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -878,7 +878,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -893,7 +893,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -908,7 +908,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -925,7 +925,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -942,7 +942,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -959,7 +959,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -976,7 +976,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -993,7 +993,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1476,7 +1476,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1496,7 +1496,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1516,7 +1516,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1538,7 +1538,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1558,7 +1558,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1591,7 +1591,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1606,7 +1606,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1621,7 +1621,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1636,7 +1636,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1651,7 +1651,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1666,7 +1666,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1681,7 +1681,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1698,7 +1698,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1715,7 +1715,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1732,7 +1732,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1749,7 +1749,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -1766,7 +1766,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -2249,7 +2249,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -2269,7 +2269,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -2289,7 +2289,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -2311,7 +2311,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }
@ -2331,7 +2331,7 @@ describe('UNIT: services/settings/validate', function () {
} }
}); });
} catch (err) { } catch (err) {
(err instanceof common.errors.ValidationError).should.be.true(); (err instanceof errors.ValidationError).should.be.true();
return; return;
} }

View File

@ -1,4 +1,3 @@
const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const _ = require('lodash'); const _ = require('lodash');
const rewire = require('rewire'); const rewire = require('rewire');
@ -8,7 +7,7 @@ const configUtils = require('../../utils/configUtils');
// Stuff we test // Stuff we test
const slack = rewire('../../../core/server/services/slack'); const slack = rewire('../../../core/server/services/slack');
const common = require('../../../core/server/lib/common'); const {logging, events} = require('../../../core/server/lib/common');
const imageLib = require('../../../core/server/lib/image'); const imageLib = require('../../../core/server/lib/image');
const urlService = require('../../../core/frontend/services/url'); const urlService = require('../../../core/frontend/services/url');
const schema = require('../../../core/server/data/schema').checks; const schema = require('../../../core/server/data/schema').checks;
@ -23,7 +22,7 @@ describe('Slack', function () {
let eventStub; let eventStub;
beforeEach(function () { beforeEach(function () {
eventStub = sinon.stub(common.events, 'on'); eventStub = sinon.stub(events, 'on');
}); });
afterEach(function () { afterEach(function () {
@ -107,7 +106,7 @@ describe('Slack', function () {
sinon.stub(urlService, 'getUrlByResourceId'); sinon.stub(urlService, 'getUrlByResourceId');
settingsCacheStub = sinon.stub(settingsCache, 'get'); settingsCacheStub = sinon.stub(settingsCache, 'get');
sinon.spy(common.logging, 'error'); sinon.spy(logging, 'error');
makeRequestStub = sinon.stub(); makeRequestStub = sinon.stub();
slackReset = slack.__set__('request', makeRequestStub); slackReset = slack.__set__('request', makeRequestStub);
@ -189,7 +188,7 @@ describe('Slack', function () {
ping({}); ping({});
(function retry() { (function retry() {
if (common.logging.error.calledOnce) { if (logging.error.calledOnce) {
makeRequestStub.calledOnce.should.be.true(); makeRequestStub.calledOnce.should.be.true();
return done(); return done();
} }

View File

@ -2,7 +2,7 @@ const _ = require('lodash');
const Promise = require('bluebird'); const Promise = require('bluebird');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../core/server/lib/common'); const {logging} = require('../../../../core/server/lib/common');
const Queue = require('../../../../core/frontend/services/url/Queue'); const Queue = require('../../../../core/frontend/services/url/Queue');
describe('Unit: services/url/Queue', function () { describe('Unit: services/url/Queue', function () {
@ -12,7 +12,7 @@ describe('Unit: services/url/Queue', function () {
queue = new Queue(); queue = new Queue();
sinon.spy(queue, 'run'); sinon.spy(queue, 'run');
sinon.stub(common.logging, 'error'); sinon.stub(logging, 'error');
}); });
afterEach(function () { afterEach(function () {
@ -141,7 +141,7 @@ describe('Unit: services/url/Queue', function () {
event: 'nachos' event: 'nachos'
}); });
common.logging.error.calledOnce.should.be.true(); logging.error.calledOnce.should.be.true();
queue.toNotify.nachos.notified.length.should.eql(0); queue.toNotify.nachos.notified.length.should.eql(0);
}); });
}); });

View File

@ -1,9 +1,10 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const Promise = require('bluebird'); const Promise = require('bluebird');
const rewire = require('rewire'); const rewire = require('rewire');
const should = require('should'); const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const common = require('../../../../core/server/lib/common'); const {events} = require('../../../../core/server/lib/common');
const Queue = require('../../../../core/frontend/services/url/Queue'); const Queue = require('../../../../core/frontend/services/url/Queue');
const Resources = require('../../../../core/frontend/services/url/Resources'); const Resources = require('../../../../core/frontend/services/url/Resources');
const UrlGenerator = require('../../../../core/frontend/services/url/UrlGenerator'); const UrlGenerator = require('../../../../core/frontend/services/url/UrlGenerator');
@ -35,7 +36,7 @@ describe('Unit: services/url/UrlService', function () {
UrlService.__set__('Urls', UrlsStub); UrlService.__set__('Urls', UrlsStub);
UrlService.__set__('UrlGenerator', UrlGeneratorStub); UrlService.__set__('UrlGenerator', UrlGeneratorStub);
sinon.stub(common.events, 'on'); sinon.stub(events, 'on');
urlService = new UrlService(); urlService = new UrlService();
}); });
@ -57,9 +58,9 @@ describe('Unit: services/url/UrlService', function () {
urlService.queue.addListener.args[0][0].should.eql('started'); urlService.queue.addListener.args[0][0].should.eql('started');
urlService.queue.addListener.args[1][0].should.eql('ended'); urlService.queue.addListener.args[1][0].should.eql('ended');
common.events.on.calledTwice.should.be.true(); events.on.calledTwice.should.be.true();
common.events.on.args[0][0].should.eql('router.created'); events.on.args[0][0].should.eql('router.created');
common.events.on.args[1][0].should.eql('services.themes.api.changed'); events.on.args[1][0].should.eql('services.themes.api.changed');
}); });
it('fn: _onQueueStarted', function () { it('fn: _onQueueStarted', function () {
@ -102,7 +103,7 @@ describe('Unit: services/url/UrlService', function () {
urlService.getResource('/blog-post/'); urlService.getResource('/blog-post/');
throw new Error('Expected error.'); throw new Error('Expected error.');
} catch (err) { } catch (err) {
(err instanceof common.errors.InternalServerError).should.be.true(); (err instanceof errors.InternalServerError).should.be.true();
} }
}); });

View File

@ -1,9 +1,9 @@
const errors = require('@tryghost/errors');
const _ = require('lodash'); const _ = require('lodash');
const url = require('url'); const url = require('url');
const moment = require('moment'); const moment = require('moment');
const DataGenerator = require('./fixtures/data-generator'); const DataGenerator = require('./fixtures/data-generator');
const config = require('../../core/server/config'); const config = require('../../core/server/config');
const common = require('../../core/server/lib/common');
const sequence = require('../../core/server/lib/promise/sequence'); const sequence = require('../../core/server/lib/promise/sequence');
const host = config.get('server').host; const host = config.get('server').host;
const port = config.get('server').port; const port = config.get('server').port;
@ -100,11 +100,11 @@ const login = (request, API_URL) => {
.then(function then(res) { .then(function then(res) {
if (res.statusCode === 302) { if (res.statusCode === 302) {
// This can happen if you already have an instance running e.g. if you've been using Ghost CLI recently // This can happen if you already have an instance running e.g. if you've been using Ghost CLI recently
return reject(new common.errors.GhostError({ return reject(new errors.GhostError({
message: 'Ghost is redirecting, do you have an instance already running on port 2369?' message: 'Ghost is redirecting, do you have an instance already running on port 2369?'
})); }));
} else if (res.statusCode !== 200 && res.statusCode !== 201) { } else if (res.statusCode !== 200 && res.statusCode !== 201) {
return reject(new common.errors.GhostError({ return reject(new errors.GhostError({
message: res.body.errors[0].message message: res.body.errors[0].message
})); }));
} }

View File

@ -10,7 +10,7 @@ const uuid = require('uuid');
const KnexMigrator = require('knex-migrator'); const KnexMigrator = require('knex-migrator');
const ghost = require('../../core/server'); const ghost = require('../../core/server');
const GhostServer = require('../../core/server/ghost-server'); const GhostServer = require('../../core/server/ghost-server');
const common = require('../../core/server/lib/common'); const {events} = require('../../core/server/lib/common');
const fixtureUtils = require('../../core/server/data/schema/fixtures/utils'); const fixtureUtils = require('../../core/server/data/schema/fixtures/utils');
const db = require('../../core/server/data/db'); const db = require('../../core/server/data/db');
const schema = require('../../core/server/data/schema').tables; const schema = require('../../core/server/data/schema').tables;
@ -493,7 +493,7 @@ fixtures = {
initData = function initData() { initData = function initData() {
return knexMigrator.init() return knexMigrator.init()
.then(function () { .then(function () {
common.events.emit('db.ready'); events.emit('db.ready');
let timeout; let timeout;
@ -850,7 +850,7 @@ startGhost = function startGhost(options) {
}) })
.then(function () { .then(function () {
urlService.softReset(); urlService.softReset();
common.events.emit('db.ready'); events.emit('db.ready');
let timeout; let timeout;
@ -869,7 +869,7 @@ startGhost = function startGhost(options) {
.then(function () { .then(function () {
web.shared.middlewares.customRedirects.reload(); web.shared.middlewares.customRedirects.reload();
common.events.emit('server.start'); events.emit('server.start');
/** /**
* @TODO: this is dirty, but makes routing testing a lot easier for now, because the routing test * @TODO: this is dirty, but makes routing testing a lot easier for now, because the routing test
@ -1042,7 +1042,7 @@ module.exports = {
let timeout; let timeout;
if (!options.dbIsReady) { if (!options.dbIsReady) {
common.events.emit('db.ready'); events.emit('db.ready');
} }
return new Promise(function (resolve) { return new Promise(function (resolve) {
@ -1065,7 +1065,7 @@ module.exports = {
const tagRouter = new routingService.TaxonomyRouter('tag', routes.taxonomies.tag); const tagRouter = new routingService.TaxonomyRouter('tag', routes.taxonomies.tag);
const authorRouter = new routingService.TaxonomyRouter('author', routes.taxonomies.author); const authorRouter = new routingService.TaxonomyRouter('author', routes.taxonomies.author);
common.events.emit('db.ready'); events.emit('db.ready');
return this.waitTillFinished(); return this.waitTillFinished();
}, },