Bumped sinon from 4.4.6 to 7.3.2 (#10400)

refs #9389

- https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md

Breaking changes for Ghost:

- no need to create a sandbox anymore, each file get's it's own sandbox
- just require sinon and use this sandbox
- you can still create separate sandboxes with .createSandbox
- reset single stubs: use .resetHistory instead of .reset

This is a global replace for any sandbox creation.

---

From https://sinonjs.org/releases/v7.2.3/sandbox/

> Default sandbox
> Since sinon@5.0.0, the sinon object is a default sandbox. Unless you have a very advanced setup or need a special configuration, you probably want to just use that one.
This commit is contained in:
Katharina Irrgang 2019-01-21 17:53:44 +01:00 committed by GitHub
parent d24229fc16
commit fb044e6d88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
177 changed files with 1611 additions and 1896 deletions

View File

@ -13,7 +13,6 @@ const localUtils = require('./utils');
let ghost = testUtils.startGhost;
let request;
let sandbox = sinon.sandbox.create();
let eventsTriggered;
describe('DB API', function () {
@ -42,7 +41,7 @@ describe('DB API', function () {
beforeEach(function () {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}
@ -52,7 +51,7 @@ describe('DB API', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('attaches the Content-Disposition header on export', function (done) {
@ -144,7 +143,7 @@ describe('DB API', function () {
it('export can be triggered by backup client', function (done) {
backupQuery = '?client_id=' + backupClient.slug + '&client_secret=' + backupClient.secret;
fsStub = sandbox.stub(fs, 'writeFile').resolves();
fsStub = sinon.stub(fs, 'writeFile').resolves();
request.post(localUtils.API.getApiQuery('db/backup' + backupQuery))
.expect('Content-Type', /json/)
.expect(200)
@ -163,7 +162,7 @@ describe('DB API', function () {
it('export can be triggered and named by backup client', function (done) {
backupQuery = '?client_id=' + backupClient.slug + '&client_secret=' + backupClient.secret + '&filename=test';
fsStub = sandbox.stub(fs, 'writeFile').resolves();
fsStub = sinon.stub(fs, 'writeFile').resolves();
request.post(localUtils.API.getApiQuery('db/backup' + backupQuery))
.expect('Content-Type', /json/)
.expect(200)
@ -182,7 +181,7 @@ describe('DB API', function () {
it('export can not be triggered by client other than backup', function (done) {
schedulerQuery = '?client_id=' + schedulerClient.slug + '&client_secret=' + schedulerClient.secret;
fsStub = sandbox.stub(fs, 'writeFile').resolves();
fsStub = sinon.stub(fs, 'writeFile').resolves();
request.post(localUtils.API.getApiQuery('db/backup' + schedulerQuery))
.expect('Content-Type', /json/)
.expect(403)

View File

@ -6,7 +6,7 @@ const localUtils = require('./utils');
const config = require('../../../../../core/server/config');
const mailService = require('../../../../../core/server/services/mail');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
let request;
describe('Invites API', function () {
@ -27,11 +27,11 @@ describe('Invites API', function () {
});
beforeEach(function () {
sandbox.stub(mailService.GhostMailer.prototype, 'send').resolves('Mail is disabled');
sinon.stub(mailService.GhostMailer.prototype, 'send').resolves('Mail is disabled');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('browse', function () {

View File

@ -9,7 +9,6 @@ const SchedulingDefault = require('../../../../../core/server/adapters/schedulin
const models = require('../../../../../core/server/models');
const config = require('../../../../../core/server/config');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
describe('Schedules API', function () {
const posts = [];
@ -21,11 +20,11 @@ describe('Schedules API', function () {
models.init();
// @NOTE: mock the post scheduler, otherwise it will auto publish the post
sandbox.stub(SchedulingDefault.prototype, '_pingUrl').resolves();
sinon.stub(SchedulingDefault.prototype, '_pingUrl').resolves();
});
after(function () {
sandbox.restore();
sinon.restore();
});
before(function () {

View File

@ -8,18 +8,18 @@ const config = require('../../../../../core/server/config');
const labs = require('../../../../../core/server/services/labs');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
let request;
describe('Subscribers API', function () {
let accesstoken = '', ghostServer;
before(function () {
sandbox.stub(labs, 'isSet').withArgs('subscribers').returns(true);
sinon.stub(labs, 'isSet').withArgs('subscribers').returns(true);
});
after(function () {
sandbox.restore();
sinon.restore();
});
before(function () {

View File

@ -12,7 +12,6 @@ const localUtils = require('./utils');
let ghost = testUtils.startGhost;
let request;
let sandbox = sinon.sandbox.create();
let eventsTriggered;
describe('DB API', () => {
@ -40,7 +39,7 @@ describe('DB API', () => {
beforeEach(() => {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake((eventName, eventObj) => {
sinon.stub(common.events, 'emit').callsFake((eventName, eventObj) => {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}
@ -50,7 +49,7 @@ describe('DB API', () => {
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
it('should export data', () => {
@ -139,7 +138,7 @@ describe('DB API', () => {
it('export can be triggered by backup client', () => {
const backupQuery = `?client_id=${backupClient.slug}&client_secret=${backupClient.secret}`;
const fsStub = sandbox.stub(fs, 'writeFile').resolves();
const fsStub = sinon.stub(fs, 'writeFile').resolves();
return request.post(localUtils.API.getApiQuery(`db/backup${backupQuery}`))
.expect('Content-Type', /json/)
@ -153,7 +152,7 @@ describe('DB API', () => {
it('export can be triggered and named by backup client', () => {
const backupQuery = `?client_id=${backupClient.slug}&client_secret=${backupClient.secret}&filename=test`;
const fsStub = sandbox.stub(fs, 'writeFile').resolves();
const fsStub = sinon.stub(fs, 'writeFile').resolves();
return request.post(localUtils.API.getApiQuery(`db/backup${backupQuery}`))
.expect('Content-Type', /json/)
@ -167,7 +166,7 @@ describe('DB API', () => {
it('export can not be triggered by client other than backup', () => {
const schedulerQuery = `?client_id=${schedulerClient.slug}&client_secret=${schedulerClient.secret}`;
const fsStub = sandbox.stub(fs, 'writeFile').resolves();
const fsStub = sinon.stub(fs, 'writeFile').resolves();
return request.post(localUtils.API.getApiQuery(`db/backup${schedulerQuery}`))
.expect('Content-Type', /json/)
@ -180,7 +179,7 @@ describe('DB API', () => {
});
it('export can not be triggered by regular authentication', () => {
const fsStub = sandbox.stub(fs, 'writeFile').resolves();
const fsStub = sinon.stub(fs, 'writeFile').resolves();
return request.post(localUtils.API.getApiQuery(`db/backup`))
.set('Origin', config.get('url'))

View File

@ -6,7 +6,7 @@ const localUtils = require('./utils');
const config = require('../../../../../../core/server/config');
const mailService = require('../../../../../../core/server/services/mail');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
let request;
describe('Invites API V2', function () {
@ -27,11 +27,11 @@ describe('Invites API V2', function () {
});
beforeEach(function () {
sandbox.stub(mailService.GhostMailer.prototype, 'send').resolves('Mail is disabled');
sinon.stub(mailService.GhostMailer.prototype, 'send').resolves('Mail is disabled');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('browse', function () {

View File

@ -6,7 +6,7 @@ const localUtils = require('./utils');
const config = require('../../../../../../core/server/config');
const mailService = require('../../../../../../core/server/services/mail');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
let request;
describe('Mail API V2', function () {
@ -27,11 +27,11 @@ describe('Mail API V2', function () {
});
beforeEach(function () {
sandbox.stub(mailService.GhostMailer.prototype, 'send').resolves({message: 'sent'});
sinon.stub(mailService.GhostMailer.prototype, 'send').resolves({message: 'sent'});
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('default', function () {

View File

@ -11,10 +11,8 @@ let request;
describe('Slack API', function () {
let ghostServer;
let sandbox;
before(function () {
sandbox = sinon.sandbox.create();
before(function () {
return ghost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
@ -25,11 +23,11 @@ describe('Slack API', function () {
});
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('should be able to post slack test', function (done) {
const eventSpy = sandbox.spy(common.events, 'emit');
const eventSpy = sinon.spy(common.events, 'emit');
request.post(localUtils.API.getApiQuery('slack/test/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)

View File

@ -8,16 +8,16 @@ const config = require('../../../../../../core/server/config');
const labs = require('../../../../../../core/server/services/labs');
const ghost = testUtils.startGhost;
const sandbox = sinon.sandbox.create();
let request;
describe('Subscribers API', function () {
before(function () {
sandbox.stub(labs, 'isSet').withArgs('subscribers').returns(true);
sinon.stub(labs, 'isSet').withArgs('subscribers').returns(true);
});
after(function () {
sandbox.restore();
sinon.restore();
});
before(function () {

View File

@ -4,8 +4,7 @@ var supertest = require('supertest'),
testUtils = require('../../../utils'),
labs = require('../../../../server/services/labs'),
config = require('../../../../server/config'),
ghost = testUtils.startGhost,
sandbox = sinon.sandbox.create();
ghost = testUtils.startGhost;
describe('Subscriber: Routing', function () {
var request;
@ -18,7 +17,7 @@ describe('Subscriber: Routing', function () {
});
before(function () {
sandbox.stub(labs, 'isSet').callsFake(function (key) {
sinon.stub(labs, 'isSet').callsFake(function (key) {
if (key === 'subscribers') {
return true;
}
@ -26,7 +25,7 @@ describe('Subscriber: Routing', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
describe('GET', function () {

View File

@ -12,8 +12,7 @@ const should = require('should'),
config = require('../../server/config'),
api = require('../../server/api'),
settingsCache = require('../../server/services/settings/cache'),
ghost = testUtils.startGhost,
sandbox = sinon.sandbox.create();
ghost = testUtils.startGhost;
let request;
@ -38,7 +37,7 @@ describe('Dynamic Routing', function () {
before(function () {
// Default is always casper. We use the old compatible 1.4 casper theme for these tests. Available in the test content folder.
var originalSettingsCacheGetFn = settingsCache.get;
sandbox.stub(settingsCache, 'get').callsFake(function (key, options) {
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
if (key === 'active_theme') {
return 'casper-1.4';
}
@ -54,7 +53,7 @@ describe('Dynamic Routing', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
describe('Collection Index', function () {

View File

@ -14,9 +14,7 @@ var should = require('should'),
settingsCache = require('../../server/services/settings/cache'),
origCache = _.cloneDeep(settingsCache),
ghost = testUtils.startGhost,
request,
sandbox = sinon.sandbox.create();
request;
describe('Frontend Routing', function () {
function doEnd(done) {
@ -45,7 +43,7 @@ describe('Frontend Routing', function () {
}
afterEach(function () {
sandbox.restore();
sinon.restore();
});
before(function () {
@ -251,7 +249,7 @@ describe('Frontend Routing', function () {
});
it('should redirect to regular post when AMP is disabled', function (done) {
sandbox.stub(settingsCache, 'get').callsFake(function (key, options) {
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
if (key === 'amp' && !options) {
return false;
}

View File

@ -17,8 +17,7 @@ var should = require('should'),
returnImportedData: true
},
knex = db.knex,
sandbox = sinon.sandbox.create();
knex = db.knex;
const exportedLatestBody = () => {
return _.clone({
@ -116,12 +115,12 @@ describe('Integration: Importer', function () {
before(testUtils.teardown);
beforeEach(function () {
sandbox.stub(importer, 'cleanUp');
sinon.stub(importer, 'cleanUp');
});
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
sinon.restore();
});
should.exist(importer);

View File

@ -5,15 +5,13 @@ var should = require('should'),
// Stuff we are testing
exporter = require('../../server/data/exporter'),
ghostVersion = require('../../server/lib/ghost-version'),
sandbox = sinon.sandbox.create();
ghostVersion = require('../../server/lib/ghost-version');
describe('Exporter', function () {
before(testUtils.teardown);
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(testUtils.setup('default', 'settings'));

View File

@ -3,14 +3,13 @@ var should = require('should'),
testUtils = require('../utils'),
_ = require('lodash'),
Promise = require('bluebird'),
Models = require('../../server/models'),
sandbox = sinon.sandbox.create();
Models = require('../../server/models');
describe('Database Migration (special functions)', function () {
before(testUtils.teardown);
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('Fixtures', function () {

View File

@ -7,8 +7,7 @@ var should = require('should'),
common = require('../../../../server/lib/common'),
models = require('../../../../server/models'),
testUtils = require('../../../../test/utils'),
sequence = require('../../../../server/lib/promise/sequence'),
sandbox = sinon.sandbox.create();
sequence = require('../../../../server/lib/promise/sequence');
describe('Models: listeners', function () {
var eventsToRemember = {},
@ -25,7 +24,7 @@ describe('Models: listeners', function () {
beforeEach(testUtils.setup('owner', 'user-token:0', 'settings'));
beforeEach(function () {
sandbox.stub(common.events, 'on').callsFake(function (eventName, callback) {
sinon.stub(common.events, 'on').callsFake(function (eventName, callback) {
eventsToRemember[eventName] = callback;
});
@ -34,7 +33,7 @@ describe('Models: listeners', function () {
afterEach(function () {
common.events.on.restore();
sandbox.restore();
sinon.restore();
scope.posts = [];
return testUtils.teardown();
});
@ -254,8 +253,8 @@ describe('Models: listeners', function () {
post1 = posts[0],
listenerHasFinished = false;
sandbox.spy(common.logging, 'error');
sandbox.spy(models.Post, 'findAll');
sinon.spy(common.logging, 'error');
sinon.spy(models.Post, 'findAll');
// simulate a delay, so that the edit operation from the test here interrupts
// the goal here is to force that the listener has old post data, updated_at is then too old

View File

@ -3,11 +3,7 @@ var should = require('should'),
testUtils = require('../../utils'),
common = require('../../../server/lib/common'),
constants = require('../../../server/lib/constants'),
// Stuff we are testing
AccesstokenModel = require('../../../server/models/accesstoken').Accesstoken,
sandbox = sinon.sandbox.create();
AccesstokenModel = require('../../../server/models/accesstoken').Accesstoken;
describe('Accesstoken Model', function () {
// Keep the DB clean
@ -15,14 +11,14 @@ describe('Accesstoken Model', function () {
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(testUtils.setup('owner', 'clients'));
it('on creation emits token.added event', function (done) {
// Setup
var eventSpy = sandbox.spy(common.events, 'emit');
const eventSpy = sinon.spy(common.events, 'emit');
// Test
// Stub refreshtoken

View File

@ -12,7 +12,6 @@ var should = require('should'),
configUtils = require('../../utils/configUtils'),
DataGenerator = testUtils.DataGenerator,
context = testUtils.context.owner,
sandbox = sinon.sandbox.create(),
markdownToMobiledoc = testUtils.DataGenerator.markdownToMobiledoc;
/**
@ -31,11 +30,11 @@ describe('Post Model', function () {
before(testUtils.setup('users:roles'));
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId').withArgs(testUtils.DataGenerator.Content.posts[0].id).returns('/html-ipsum/');
sinon.stub(urlService, 'getUrlByResourceId').withArgs(testUtils.DataGenerator.Content.posts[0].id).returns('/html-ipsum/');
});
function checkFirstPostData(firstPost, options) {
@ -401,7 +400,7 @@ describe('Post Model', function () {
beforeEach(function () {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}
@ -1025,7 +1024,7 @@ describe('Post Model', function () {
beforeEach(function () {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}
@ -1462,7 +1461,7 @@ describe('Post Model', function () {
beforeEach(function () {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}
@ -1907,7 +1906,7 @@ describe('Post Model', function () {
editOptions = _.extend({}, context, {id: postJSON.id, withRelated: ['tags']});
// reset the eventSpy here
sandbox.restore();
sinon.restore();
});
});

View File

@ -2,13 +2,10 @@ var should = require('should'),
_ = require('lodash'),
sinon = require('sinon'),
testUtils = require('../../utils'),
// Stuff we are testing
SettingsModel = require('../../../server/models/settings').Settings,
db = require('../../../server/data/db'),
common = require('../../../server/lib/common'),
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
context = testUtils.context.admin;
describe('Settings Model', function () {
var eventSpy;
@ -23,11 +20,11 @@ describe('Settings Model', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
eventSpy = sandbox.spy(common.events, 'emit');
eventSpy = sinon.spy(common.events, 'emit');
});
describe('API', function () {

View File

@ -7,8 +7,7 @@ var should = require('should'),
db = require('../../../server/data/db'),
models = require('../../../server/models'),
common = require('../../../server/lib/common'),
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
context = testUtils.context.admin;
describe('Tag Model', function () {
var eventSpy;
@ -19,11 +18,11 @@ describe('Tag Model', function () {
before(testUtils.setup('users:roles', 'posts'));
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
eventSpy = sandbox.spy(common.events, 'emit');
eventSpy = sinon.spy(common.events, 'emit');
});
describe('findPage', function () {

View File

@ -9,8 +9,7 @@ var should = require('should'),
imageLib = require('../../../server/lib/image'),
UserModel = require('../../../server/models/user').User,
RoleModel = require('../../../server/models/role').Role,
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
context = testUtils.context.admin;
describe('User Model', function run() {
var eventsTriggered = {};
@ -18,7 +17,7 @@ describe('User Model', function run() {
before(testUtils.teardown);
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
sinon.restore();
});
before(function () {
@ -89,7 +88,7 @@ describe('User Model', function run() {
it('can find gravatar', function (done) {
var userData = testUtils.DataGenerator.forModel.users[4];
sandbox.stub(imageLib.gravatar, 'lookup').callsFake(function (userData) {
sinon.stub(imageLib.gravatar, 'lookup').callsFake(function (userData) {
userData.image = 'http://www.gravatar.com/avatar/2fab21a4c4ed88e76add10650c73bae1?d=404';
return Promise.resolve(userData);
});
@ -106,7 +105,7 @@ describe('User Model', function run() {
it('can handle no gravatar', function (done) {
var userData = testUtils.DataGenerator.forModel.users[0];
sandbox.stub(imageLib.gravatar, 'lookup').callsFake(function (userData) {
sinon.stub(imageLib.gravatar, 'lookup').callsFake(function (userData) {
return Promise.resolve(userData);
});
@ -156,7 +155,7 @@ describe('User Model', function run() {
beforeEach(function () {
eventsTriggered = {};
sandbox.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
sinon.stub(common.events, 'emit').callsFake(function (eventName, eventObj) {
if (!eventsTriggered[eventName]) {
eventsTriggered[eventName] = [];
}

View File

@ -9,15 +9,13 @@ const common = require('../../../../server/lib/common');
const themes = require('../../../../server/services/themes');
const UrlService = rewire('../../../../server/services/url/UrlService');
const sandbox = sinon.sandbox.create();
describe('Integration: services/url/UrlService', function () {
let urlService;
before(function () {
models.init();
sandbox.stub(themes, 'getActive').returns({
sinon.stub(themes, 'getActive').returns({
engine: () => 'v0.1'
});
});
@ -27,7 +25,7 @@ describe('Integration: services/url/UrlService', function () {
after(testUtils.teardown);
after(function () {
sandbox.restore();
sinon.restore();
});
describe('functional: default routing set', function () {
@ -37,40 +35,40 @@ describe('Integration: services/url/UrlService', function () {
urlService = new UrlService();
router1 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'post collection';
}
};
router2 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'authors';
}
};
router3 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'tags';
}
};
router4 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'static pages';
}
@ -221,50 +219,50 @@ describe('Integration: services/url/UrlService', function () {
urlService = new UrlService();
router1 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'post collection 1';
}
};
router2 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'post collection 2';
}
};
router3 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'authors';
}
};
router4 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'tags';
}
};
router5 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'static pages';
}
@ -417,50 +415,50 @@ describe('Integration: services/url/UrlService', function () {
urlService = new UrlService();
router1 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'post collection 1';
}
};
router2 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'post collection 2';
}
};
router3 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'authors';
}
};
router4 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'tags';
}
};
router5 = {
getFilter: sandbox.stub(),
addListener: sandbox.stub(),
getResourceType: sandbox.stub(),
getPermalinks: sandbox.stub(),
getFilter: sinon.stub(),
addListener: sinon.stub(),
getResourceType: sinon.stub(),
getPermalinks: sinon.stub(),
toString: function () {
return 'static pages';
}

View File

@ -10,8 +10,6 @@ const configUtils = require('../utils/configUtils');
const packageInfo = require('../../../package');
const api = require('../../server/api').v2;
const sandbox = sinon.sandbox.create();
let updateCheck = rewire('../../server/update-check');
let NotificationsAPI = rewire('../../server/api/v2/notifications');
@ -22,7 +20,7 @@ describe('Update Check', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});
@ -37,9 +35,9 @@ describe('Update Check', function () {
beforeEach(testUtils.setup('roles', 'owner'));
beforeEach(function () {
updateCheckRequestSpy = sandbox.stub().returns(Promise.resolve());
updateCheckResponseSpy = sandbox.stub().returns(Promise.resolve());
updateCheckErrorSpy = sandbox.stub();
updateCheckRequestSpy = sinon.stub().returns(Promise.resolve());
updateCheckResponseSpy = sinon.stub().returns(Promise.resolve());
updateCheckErrorSpy = sinon.stub();
updateCheck.__set__('updateCheckRequest', updateCheckRequestSpy);
updateCheck.__set__('updateCheckResponse', updateCheckResponseSpy);
@ -48,12 +46,12 @@ describe('Update Check', function () {
});
it('update check was never executed', function (done) {
const readStub = sandbox.stub().resolves({
const readStub = sinon.stub().resolves({
settings: [{
value: null
}]
});
sandbox.stub(api, 'settings').get(() => ({
sinon.stub(api, 'settings').get(() => ({
read: readStub
}));
@ -68,12 +66,12 @@ describe('Update Check', function () {
});
it('update check won\'t happen if it\'s too early', function (done) {
const readStub = sandbox.stub().resolves({
const readStub = sinon.stub().resolves({
settings: [{
value: moment().add('10', 'minutes').unix()
}]
});
sandbox.stub(api, 'settings').get(() => ({
sinon.stub(api, 'settings').get(() => ({
read: readStub
}));
@ -88,12 +86,12 @@ describe('Update Check', function () {
});
it('update check will happen if it\'s time to check', function (done) {
const readStub = sandbox.stub().resolves({
const readStub = sinon.stub().resolves({
settings: [{
value: moment().subtract('10', 'minutes').unix()
}]
});
sandbox.stub(api, 'settings').get(() => ({
sinon.stub(api, 'settings').get(() => ({
read: readStub
}));
@ -330,7 +328,7 @@ describe('Update Check', function () {
it('receives a notifications with messages', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message = {
id: uuid.v4(),
version: '^0.11.11',
@ -351,7 +349,7 @@ describe('Update Check', function () {
it('receives multiple notifications', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message1 = {
id: uuid.v4(),
version: '^0.11.11',
@ -383,7 +381,7 @@ describe('Update Check', function () {
it('ignores some custom notifications which are not marked as group', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message1 = {
id: uuid.v4(),
version: '^0.11.11',
@ -423,7 +421,7 @@ describe('Update Check', function () {
it('group matches', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message1 = {
id: uuid.v4(),
version: '^0.11.11',
@ -465,7 +463,7 @@ describe('Update Check', function () {
it('single custom notification received, group matches', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message1 = {
id: uuid.v4(),
version: '^0.11.11',
@ -491,7 +489,7 @@ describe('Update Check', function () {
it('single custom notification received, group does not match', function (done) {
var updateCheckResponse = updateCheck.__get__('updateCheckResponse'),
createNotificationSpy = sandbox.spy(),
createNotificationSpy = sinon.spy(),
message1 = {
id: uuid.v4(),
version: '^0.11.11',
@ -527,7 +525,7 @@ describe('Update Check', function () {
it('[default]', function () {
var updateCheckRequest = updateCheck.__get__('updateCheckRequest'),
updateCheckDataSpy = sandbox.stub(),
updateCheckDataSpy = sinon.stub(),
hostname,
reqObj,
data = {
@ -561,7 +559,7 @@ describe('Update Check', function () {
it('privacy flag is used', function () {
var updateCheckRequest = updateCheck.__get__('updateCheckRequest'),
updateCheckDataSpy = sandbox.stub(),
updateCheckDataSpy = sinon.stub(),
reqObj,
hostname;
@ -604,7 +602,7 @@ describe('Update Check', function () {
it('received 500 from the service', function () {
var updateCheckRequest = updateCheck.__get__('updateCheckRequest'),
updateCheckDataSpy = sandbox.stub(),
updateCheckDataSpy = sinon.stub(),
reqObj,
hostname;
@ -637,7 +635,7 @@ describe('Update Check', function () {
it('received 404 from the service', function () {
var updateCheckRequest = updateCheck.__get__('updateCheckRequest'),
updateCheckDataSpy = sandbox.stub(),
updateCheckDataSpy = sinon.stub(),
reqObj,
hostname;
@ -671,7 +669,7 @@ describe('Update Check', function () {
it('custom url', function () {
var updateCheckRequest = updateCheck.__get__('updateCheckRequest'),
updateCheckDataSpy = sandbox.stub(),
updateCheckDataSpy = sinon.stub(),
reqObj,
hostname;

View File

@ -6,8 +6,7 @@ const should = require('should'),
configUtils = require('../../utils/configUtils'),
settingsService = require('../../../server/services/settings'),
themeService = require('../../../server/services/themes'),
siteApp = require('../../../server/web/parent-app'),
sandbox = sinon.sandbox.create();
siteApp = require('../../../server/web/parent-app');
describe('Integration - Web - Site', function () {
let app;
@ -21,13 +20,13 @@ describe('Integration - Web - Site', function () {
describe('default routes.yaml', function () {
before(function () {
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
testUtils.integrationTesting.overrideGhostConfig(configUtils);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -37,7 +36,7 @@ describe('Integration - Web - Site', function () {
beforeEach(function () {
configUtils.set('url', 'http://example.com');
sandbox.spy(api.posts, 'browse');
sinon.spy(api.posts, 'browse');
});
afterEach(function () {
@ -46,7 +45,7 @@ describe('Integration - Web - Site', function () {
after(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
describe('behaviour: default cases', function () {
@ -429,7 +428,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/': 'home'
},
@ -453,12 +452,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -474,7 +473,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve static route', function () {
@ -562,7 +561,7 @@ describe('Integration - Web - Site', function () {
describe('no collections', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/test/': 'test'
},
@ -571,12 +570,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -592,7 +591,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve route', function () {
@ -613,7 +612,7 @@ describe('Integration - Web - Site', function () {
describe('static permalink route', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -631,12 +630,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -652,7 +651,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -719,7 +718,7 @@ describe('Integration - Web - Site', function () {
describe('primary author permalink', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -732,12 +731,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -753,7 +752,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -804,7 +803,7 @@ describe('Integration - Web - Site', function () {
describe('primary tag permalink', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -817,12 +816,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -838,7 +837,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -904,7 +903,7 @@ describe('Integration - Web - Site', function () {
describe('collection with data key', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -955,12 +954,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -976,7 +975,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve /food/', function () {
@ -1042,7 +1041,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -1057,12 +1056,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1078,7 +1077,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -1114,7 +1113,7 @@ describe('Integration - Web - Site', function () {
describe('two templates', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -1126,12 +1125,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1147,7 +1146,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -1168,7 +1167,7 @@ describe('Integration - Web - Site', function () {
describe('home.hbs priority', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -1184,12 +1183,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1205,7 +1204,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -1247,9 +1246,9 @@ describe('Integration - Web - Site', function () {
before(testUtils.setup('users:roles', 'posts'));
before(function () {
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme-channels'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme-channels'});
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/channel1/': {
controller: 'channel',
@ -1393,8 +1392,8 @@ describe('Integration - Web - Site', function () {
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(10);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(10);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1410,7 +1409,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve channel 1', function () {
@ -1637,7 +1636,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml (5): rss override', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/about/': 'about',
'/podcast/rss/': {
@ -1673,12 +1672,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v0.1');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1694,7 +1693,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve /rss/', function () {
@ -1794,13 +1793,13 @@ describe('Integration - Web - Site', function () {
describe('default routes.yaml', function () {
before(function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
testUtils.integrationTesting.overrideGhostConfig(configUtils);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -1810,7 +1809,7 @@ describe('Integration - Web - Site', function () {
beforeEach(function () {
const postsAPI = require('../../../server/api/v2/posts');
configUtils.set('url', 'http://example.com');
postSpy = sandbox.spy(postsAPI.browse, 'query');
postSpy = sinon.spy(postsAPI.browse, 'query');
});
afterEach(function () {
@ -1819,7 +1818,7 @@ describe('Integration - Web - Site', function () {
after(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
describe('behaviour: default cases', function () {
@ -2202,7 +2201,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/': 'home'
},
@ -2226,12 +2225,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2247,7 +2246,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve static route', function () {
@ -2335,7 +2334,7 @@ describe('Integration - Web - Site', function () {
describe('no collections', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/test/': 'test'
},
@ -2344,12 +2343,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2365,7 +2364,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve route', function () {
@ -2386,7 +2385,7 @@ describe('Integration - Web - Site', function () {
describe('static permalink route', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2404,12 +2403,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2425,7 +2424,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -2492,7 +2491,7 @@ describe('Integration - Web - Site', function () {
describe('primary author permalink', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2505,12 +2504,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2526,7 +2525,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -2577,7 +2576,7 @@ describe('Integration - Web - Site', function () {
describe('primary tag permalink', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2590,12 +2589,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2611,7 +2610,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve post', function () {
@ -2677,7 +2676,7 @@ describe('Integration - Web - Site', function () {
describe('collection with data key', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2728,12 +2727,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2749,7 +2748,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve /food/', function () {
@ -2815,7 +2814,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2830,12 +2829,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2851,7 +2850,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -2887,7 +2886,7 @@ describe('Integration - Web - Site', function () {
describe('two templates', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2899,12 +2898,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox);
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2920,7 +2919,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -2941,7 +2940,7 @@ describe('Integration - Web - Site', function () {
describe('home.hbs priority', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {},
collections: {
@ -2957,12 +2956,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -2978,7 +2977,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve collection', function () {
@ -3020,9 +3019,9 @@ describe('Integration - Web - Site', function () {
before(testUtils.setup('users:roles', 'posts'));
before(function () {
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme-channels'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme-channels'});
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/channel1/': {
controller: 'channel',
@ -3146,8 +3145,8 @@ describe('Integration - Web - Site', function () {
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(10);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(10);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -3163,7 +3162,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve channel 1', function () {
@ -3356,7 +3355,7 @@ describe('Integration - Web - Site', function () {
describe('extended routes.yaml (5): rss override', function () {
before(function () {
sandbox.stub(settingsService, 'get').returns({
sinon.stub(settingsService, 'get').returns({
routes: {
'/about/': 'about',
'/podcast/rss/': {
@ -3392,12 +3391,12 @@ describe('Integration - Web - Site', function () {
});
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sandbox, {theme: 'test-theme'});
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
sandbox.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sandbox.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeService.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeService.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlService.waitTillFinished();
@ -3413,7 +3412,7 @@ describe('Integration - Web - Site', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('serve /rss/', function () {

View File

@ -6,9 +6,7 @@ var should = require('should'),
express = require('express'),
bodyParser = require('body-parser'),
http = require('http'),
SchedulingDefault = require(config.get('paths').corePath + '/server/adapters/scheduling/SchedulingDefault'),
sandbox = sinon.sandbox.create();
SchedulingDefault = require(config.get('paths').corePath + '/server/adapters/scheduling/SchedulingDefault');
describe('Scheduling Default Adapter', function () {
var scope = {};
@ -18,13 +16,13 @@ describe('Scheduling Default Adapter', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('success', function () {
it('addJob (schedule)', function () {
sandbox.stub(scope.adapter, 'run');
sandbox.stub(scope.adapter, '_execute');
sinon.stub(scope.adapter, 'run');
sinon.stub(scope.adapter, '_execute');
var dates = [
moment().add(1, 'day').subtract(30, 'seconds').toDate(),
@ -69,7 +67,7 @@ describe('Scheduling Default Adapter', function () {
}),
allJobs = {};
sandbox.stub(scope.adapter, '_execute').callsFake(function (nextJobs) {
sinon.stub(scope.adapter, '_execute').callsFake(function (nextJobs) {
Object.keys(nextJobs).length.should.eql(121);
Object.keys(scope.adapter.allJobs).length.should.eql(1000 - 121);
done();
@ -86,7 +84,7 @@ describe('Scheduling Default Adapter', function () {
});
it('ensure recursive run works', function (done) {
sandbox.spy(scope.adapter, '_execute');
sinon.spy(scope.adapter, '_execute');
scope.adapter.allJobs = {};
scope.adapter.runTimeoutInMs = 10;
@ -107,8 +105,8 @@ describe('Scheduling Default Adapter', function () {
}),
nextJobs = {};
sandbox.stub(scope.adapter, 'run');
sandbox.stub(scope.adapter, '_pingUrl').callsFake(function () {
sinon.stub(scope.adapter, 'run');
sinon.stub(scope.adapter, '_pingUrl').callsFake(function () {
pinged = pinged + 1;
});
@ -132,8 +130,8 @@ describe('Scheduling Default Adapter', function () {
jobsToDelete = {},
jobsToExecute = {};
sandbox.stub(scope.adapter, 'run');
sandbox.stub(scope.adapter, '_pingUrl').callsFake(function () {
sinon.stub(scope.adapter, 'run');
sinon.stub(scope.adapter, '_pingUrl').callsFake(function () {
pinged = pinged + 1;
});

View File

@ -3,20 +3,18 @@ var should = require('should'),
rewire = require('rewire'),
Promise = require('bluebird'),
config = require(__dirname + '/../../../../server/config'),
postScheduling = require(__dirname + '/../../../../server/adapters/scheduling/post-scheduling'),
sandbox = sinon.sandbox.create();
postScheduling = require(__dirname + '/../../../../server/adapters/scheduling/post-scheduling');
describe('Scheduling', function () {
var scope = {};
before(function () {
sandbox.stub(postScheduling, 'init').returns(Promise.resolve());
sinon.stub(postScheduling, 'init').returns(Promise.resolve());
scope.scheduling = rewire(config.get('paths').corePath + '/server/adapters/scheduling');
});
after(function () {
sandbox.restore();
sinon.restore();
});
describe('success', function () {

View File

@ -9,9 +9,7 @@ var should = require('should'),
schedulingUtils = require('../../../../../server/adapters/scheduling/utils'),
SchedulingDefault = require('../../../../../server/adapters/scheduling/SchedulingDefault'),
postScheduling = require('../../../../../server/adapters/scheduling/post-scheduling'),
urlService = require('../../../../../server/services/url'),
sandbox = sinon.sandbox.create();
urlService = require('../../../../../server/services/url');
describe('Scheduling: Post Scheduling', function () {
var scope = {
@ -35,28 +33,28 @@ describe('Scheduling: Post Scheduling', function () {
scope.adapter = new SchedulingDefault();
sandbox.stub(api.schedules, 'getScheduledPosts').callsFake(function () {
sinon.stub(api.schedules, 'getScheduledPosts').callsFake(function () {
return Promise.resolve({posts: scope.scheduledPosts});
});
sandbox.stub(common.events, 'onMany').callsFake(function (events, stubDone) {
sinon.stub(common.events, 'onMany').callsFake(function (events, stubDone) {
events.forEach(function (event) {
scope.events[event] = stubDone;
});
});
sandbox.stub(schedulingUtils, 'createAdapter').returns(Promise.resolve(scope.adapter));
sinon.stub(schedulingUtils, 'createAdapter').returns(Promise.resolve(scope.adapter));
sandbox.stub(models.Client, 'findOne').callsFake(function () {
sinon.stub(models.Client, 'findOne').callsFake(function () {
return Promise.resolve(scope.client);
});
sandbox.spy(scope.adapter, 'schedule');
sandbox.spy(scope.adapter, 'reschedule');
sinon.spy(scope.adapter, 'schedule');
sinon.spy(scope.adapter, 'reschedule');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
return testUtils.teardown();
});

View File

@ -7,10 +7,7 @@ var should = require('should'),
common = require('../../../../server/lib/common'),
LocalFileStore = require('../../../../server/adapters/storage/LocalFileStorage'),
localFileStore,
configUtils = require('../../../utils/configUtils'),
sandbox = sinon.sandbox.create();
configUtils = require('../../../utils/configUtils');
describe('Local File System Storage', function () {
var image,
@ -24,26 +21,21 @@ describe('Local File System Storage', function () {
momentStub.withArgs('MM').returns(month < 10 ? '0' + month.toString() : month.toString());
}
before(function () {
beforeEach(function () {
// Fake a date, do this once for all tests in this file
momentStub = sinon.stub(moment.fn, 'format');
});
after(function () {
// Moment stub requires it's own restore after all the tests
momentStub.restore();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});
beforeEach(function () {
sandbox.stub(fs, 'mkdirs').resolves();
sandbox.stub(fs, 'copy').resolves();
sandbox.stub(fs, 'stat').rejects();
sandbox.stub(fs, 'unlink').resolves();
sinon.stub(fs, 'mkdirs').resolves();
sinon.stub(fs, 'copy').resolves();
sinon.stub(fs, 'stat').rejects();
sinon.stub(fs, 'unlink').resolves();
image = {
path: 'tmp/123456.jpg',
@ -232,8 +224,8 @@ describe('Local File System Storage', function () {
var truePathSep = path.sep;
beforeEach(function () {
sandbox.stub(path, 'join');
sandbox.stub(configUtils.config, 'getContentPath').returns('content/images/');
sinon.stub(path, 'join');
sinon.stub(configUtils.config, 'getContentPath').returns('content/images/');
});
afterEach(function () {

View File

@ -3,20 +3,18 @@ var should = require('should'),
urlService = require('../../../../server/services/url'),
// Stuff we are testing
storageUtils = require('../../../../server/adapters/storage/utils'),
sandbox = sinon.sandbox.create();
storageUtils = require('../../../../server/adapters/storage/utils');
describe('storage utils', function () {
var urlForStub,
urlGetSubdirStub;
beforeEach(function () {
urlForStub = sandbox.stub();
urlForStub = sinon.stub();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('fn: getLocalFileStoragePath', function () {
@ -24,9 +22,9 @@ describe('storage utils', function () {
var url = 'http://myblog.com/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(url);
@ -41,9 +39,9 @@ describe('storage utils', function () {
var url = 'https://myblog.com/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(url);
@ -55,9 +53,9 @@ describe('storage utils', function () {
var url = 'http://myblog.com/blog/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.getLocalFileStoragePath(url);
@ -69,9 +67,9 @@ describe('storage utils', function () {
var filePath = '/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(filePath);
@ -83,9 +81,9 @@ describe('storage utils', function () {
var filePath = '/blog/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.getLocalFileStoragePath(filePath);
@ -97,9 +95,9 @@ describe('storage utils', function () {
var url = 'http://example-blog.com/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(url);
@ -113,9 +111,9 @@ describe('storage utils', function () {
var url = 'http://myblog.com/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.isLocalImage(url);
@ -130,9 +128,9 @@ describe('storage utils', function () {
var url = 'https://myblog.com/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.isLocalImage(url);
@ -144,9 +142,9 @@ describe('storage utils', function () {
var url = 'http://myblog.com/blog/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.isLocalImage(url);
@ -158,9 +156,9 @@ describe('storage utils', function () {
var url = '/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.isLocalImage(url);
@ -172,9 +170,9 @@ describe('storage utils', function () {
var url = '/blog/content/images/2017/07/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.isLocalImage(url);
@ -186,9 +184,9 @@ describe('storage utils', function () {
var url = 'http://somewebsite.com/ghost-logo.png',
result;
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.isLocalImage(url);

View File

@ -1,7 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const shared = require('../../../../server/api/shared');
const sandbox = sinon.sandbox.create();
describe('Unit: api/shared/http', function () {
let req;
@ -9,28 +8,28 @@ describe('Unit: api/shared/http', function () {
let next;
beforeEach(function () {
req = sandbox.stub();
res = sandbox.stub();
next = sandbox.stub();
req = sinon.stub();
res = sinon.stub();
next = sinon.stub();
req.body = {
a: 'a'
};
res.status = sandbox.stub();
res.json = sandbox.stub();
res.set = sandbox.stub();
res.send = sandbox.stub();
res.status = sinon.stub();
res.json = sinon.stub();
res.set = sinon.stub();
res.send = sinon.stub();
sandbox.stub(shared.headers, 'get').resolves();
sinon.stub(shared.headers, 'get').resolves();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('check options', function () {
const apiImpl = sandbox.stub().resolves();
const apiImpl = sinon.stub().resolves();
shared.http(apiImpl)(req, res, next);
Object.keys(apiImpl.args[0][0]).should.eql([
@ -53,7 +52,7 @@ describe('Unit: api/shared/http', function () {
});
it('api response is fn', function (done) {
const response = sandbox.stub().callsFake(function (req, res, next) {
const response = sinon.stub().callsFake(function (req, res, next) {
should.exist(req);
should.exist(res);
should.exist(next);
@ -62,12 +61,12 @@ describe('Unit: api/shared/http', function () {
done();
});
const apiImpl = sandbox.stub().resolves(response);
const apiImpl = sinon.stub().resolves(response);
shared.http(apiImpl)(req, res, next);
});
it('api response is fn', function (done) {
const apiImpl = sandbox.stub().resolves('data');
const apiImpl = sinon.stub().resolves('data');
next.callsFake(done);

View File

@ -1,27 +1,26 @@
const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const sandbox = sinon.sandbox.create();
const common = require('../../../../server/lib/common');
const shared = require('../../../../server/api/shared');
describe('Unit: api/shared/pipeline', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('stages', function () {
describe('validation', function () {
describe('input', function () {
beforeEach(function () {
sandbox.stub(shared.validators.handle, 'input').resolves();
sinon.stub(shared.validators.handle, 'input').resolves();
});
it('do it yourself', function () {
const apiUtils = {};
const apiConfig = {};
const apiImpl = {
validation: sandbox.stub().resolves('response')
validation: sinon.stub().resolves('response')
};
const frame = {};
@ -88,7 +87,7 @@ describe('Unit: api/shared/pipeline', function () {
beforeEach(function () {
apiUtils = {
permissions: {
handle: sandbox.stub().resolves()
handle: sinon.stub().resolves()
}
};
});
@ -109,7 +108,7 @@ describe('Unit: api/shared/pipeline', function () {
it('do it yourself', function () {
const apiConfig = {};
const apiImpl = {
permissions: sandbox.stub().resolves('lol')
permissions: sinon.stub().resolves('lol')
};
const frame = {};
@ -178,11 +177,11 @@ describe('Unit: api/shared/pipeline', function () {
describe('pipeline', function () {
beforeEach(function () {
sandbox.stub(shared.pipeline.STAGES.validation, 'input');
sandbox.stub(shared.pipeline.STAGES.serialisation, 'input');
sandbox.stub(shared.pipeline.STAGES.serialisation, 'output');
sandbox.stub(shared.pipeline.STAGES, 'permissions');
sandbox.stub(shared.pipeline.STAGES, 'query');
sinon.stub(shared.pipeline.STAGES.validation, 'input');
sinon.stub(shared.pipeline.STAGES.serialisation, 'input');
sinon.stub(shared.pipeline.STAGES.serialisation, 'output');
sinon.stub(shared.pipeline.STAGES, 'permissions');
sinon.stub(shared.pipeline.STAGES, 'query');
});
it('ensure we receive a callable api controller fn', function () {

View File

@ -3,11 +3,10 @@ const Promise = require('bluebird');
const sinon = require('sinon');
const common = require('../../../../../server/lib/common');
const shared = require('../../../../../server/api/shared');
const sandbox = sinon.sandbox.create();
describe('Unit: api/shared/serializers/handle', function () {
beforeEach(function () {
sandbox.restore();
sinon.restore();
});
describe('input', function () {
@ -28,16 +27,16 @@ describe('Unit: api/shared/serializers/handle', function () {
});
it('ensure serializers are called with apiConfig and frame', function () {
const allStub = sandbox.stub();
const addStub = sandbox.stub();
sandbox.stub(shared.serializers.input.all, 'all').get(() => allStub);
sandbox.stub(shared.serializers.input.all, 'add').get(() => addStub);
const allStub = sinon.stub();
const addStub = sinon.stub();
sinon.stub(shared.serializers.input.all, 'all').get(() => allStub);
sinon.stub(shared.serializers.input.all, 'add').get(() => addStub);
const apiSerializers = {
all: sandbox.stub().resolves(),
all: sinon.stub().resolves(),
posts: {
all: sandbox.stub().resolves(),
add: sandbox.stub().resolves()
all: sinon.stub().resolves(),
add: sinon.stub().resolves()
}
};
@ -87,10 +86,10 @@ describe('Unit: api/shared/serializers/handle', function () {
it('ensure serializers are called', function () {
const apiSerializers = {
posts: {
add: sandbox.stub().resolves()
add: sinon.stub().resolves()
},
users: {
add: sandbox.stub().resolves()
add: sinon.stub().resolves()
}
};

View File

@ -3,11 +3,10 @@ const Promise = require('bluebird');
const sinon = require('sinon');
const common = require('../../../../../server/lib/common');
const shared = require('../../../../../server/api/shared');
const sandbox = sinon.sandbox.create();
describe('Unit: api/shared/validators/handle', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('input', function () {
@ -28,20 +27,20 @@ describe('Unit: api/shared/validators/handle', function () {
});
it('ensure validators are called', function () {
const getStub = sandbox.stub();
const addStub = sandbox.stub();
sandbox.stub(shared.validators.input.all, 'all').get(() => {return getStub;});
sandbox.stub(shared.validators.input.all, 'add').get(() => {return addStub;});
const getStub = sinon.stub();
const addStub = sinon.stub();
sinon.stub(shared.validators.input.all, 'all').get(() => {return getStub;});
sinon.stub(shared.validators.input.all, 'add').get(() => {return addStub;});
const apiValidators = {
all: {
add: sandbox.stub().resolves()
add: sinon.stub().resolves()
},
posts: {
add: sandbox.stub().resolves()
add: sinon.stub().resolves()
},
users: {
add: sandbox.stub().resolves()
add: sinon.stub().resolves()
}
};

View File

@ -3,11 +3,10 @@ const sinon = require('sinon');
const Promise = require('bluebird');
const common = require('../../../../../../server/lib/common');
const shared = require('../../../../../../server/api/shared');
const sandbox = sinon.sandbox.create();
describe('Unit: api/shared/validators/input/all', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('all', function () {
@ -256,7 +255,7 @@ describe('Unit: api/shared/validators/input/all', function () {
describe('read', function () {
it('default', function () {
sandbox.stub(shared.validators.input.all, 'browse');
sinon.stub(shared.validators.input.all, 'browse');
const frame = {
options: {

View File

@ -5,15 +5,13 @@ const testUtils = require('../../../../utils');
const urlService = require('../../../../../server/services/url');
const urls = require('../../../../../server/api/v0.1/decorators/urls');
const sandbox = sinon.sandbox.create();
describe('Unit: api:v0.1:decorators:urls', function () {
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('urlsForPost', function () {

View File

@ -5,13 +5,11 @@ var should = require('should'),
ObjectId = require('bson-objectid'),
permissions = require('../../../../server/services/permissions'),
common = require('../../../../server/lib/common'),
apiUtils = require('../../../../server/api/v0.1/utils'),
sandbox = sinon.sandbox.create();
apiUtils = require('../../../../server/api/v0.1/utils');
describe('API Utils', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('exports', function () {
@ -91,7 +89,7 @@ describe('API Utils', function () {
it('should check data if an object is passed', function (done) {
var object = {test: [{id: 1}]},
checkObjectStub = sandbox.stub(apiUtils, 'checkObject').returns(Promise.resolve(object));
checkObjectStub = sinon.stub(apiUtils, 'checkObject').returns(Promise.resolve(object));
apiUtils.validate('test')(object, {}).then(function (options) {
checkObjectStub.calledOnce.should.be.true();
@ -111,7 +109,7 @@ describe('API Utils', function () {
it('should handle options being undefined when provided with object', function (done) {
var object = {test: [{id: 1}]},
checkObjectStub = sandbox.stub(apiUtils, 'checkObject').returns(Promise.resolve(object));
checkObjectStub = sinon.stub(apiUtils, 'checkObject').returns(Promise.resolve(object));
apiUtils.validate('test')(object, undefined).then(function (options) {
checkObjectStub.calledOnce.should.be.true();
@ -287,14 +285,14 @@ describe('API Utils', function () {
describe('convertOptions', function () {
it('should not call prepareInclude if there is no include option', function () {
var prepareIncludeStub = sandbox.stub(apiUtils, 'prepareInclude');
var prepareIncludeStub = sinon.stub(apiUtils, 'prepareInclude');
apiUtils.convertOptions(['a', 'b', 'c'])({}).should.eql({});
prepareIncludeStub.called.should.be.false();
});
it('should pass options.include to prepareInclude if provided', function () {
var expectedResult = ['a', 'b'],
prepareIncludeStub = sandbox.stub(apiUtils, 'prepareInclude').returns(expectedResult),
prepareIncludeStub = sinon.stub(apiUtils, 'prepareInclude').returns(expectedResult),
allowed = ['a', 'b', 'c'],
options = {include: 'a,b'},
actualResult;
@ -589,7 +587,7 @@ describe('API Utils', function () {
describe('isPublicContext', function () {
it('should call out to permissions', function () {
var permsStub = sandbox.stub(permissions, 'parseContext').returns({public: true});
var permsStub = sinon.stub(permissions, 'parseContext').returns({public: true});
apiUtils.detectPublicContext({context: 'test'}).should.be.true();
permsStub.called.should.be.true();
permsStub.calledWith('test').should.be.true();
@ -598,7 +596,7 @@ describe('API Utils', function () {
describe('applyPublicPermissions', function () {
it('should call out to permissions', function () {
var permsStub = sandbox.stub(permissions, 'applyPublicRules');
var permsStub = sinon.stub(permissions, 'applyPublicRules');
apiUtils.applyPublicPermissions('test', {});
permsStub.called.should.be.true();
permsStub.calledWith('test', {}).should.be.true();
@ -614,7 +612,7 @@ describe('API Utils', function () {
});
it('should treat no context as public', function (done) {
var aPPStub = sandbox.stub(apiUtils, 'applyPublicPermissions').returns(Promise.resolve({}));
var aPPStub = sinon.stub(apiUtils, 'applyPublicPermissions').returns(Promise.resolve({}));
apiUtils.handlePublicPermissions('tests', 'test')({}).then(function (options) {
aPPStub.calledOnce.should.eql(true);
options.should.eql({context: {app: null, external: false, internal: false, public: true, user: null, api_key_id: null}});
@ -625,10 +623,10 @@ describe('API Utils', function () {
it('should treat user context as NOT public', function (done) {
var cTMethodStub = {
test: {
test: sandbox.stub().returns(Promise.resolve())
test: sinon.stub().returns(Promise.resolve())
}
},
cTStub = sandbox.stub(permissions, 'canThis').returns(cTMethodStub);
cTStub = sinon.stub(permissions, 'canThis').returns(cTMethodStub);
apiUtils.handlePublicPermissions('tests', 'test')({context: {user: 1}}).then(function (options) {
cTStub.calledOnce.should.eql(true);
@ -641,10 +639,10 @@ describe('API Utils', function () {
it('should throw a permissions error if permission is not granted', function (done) {
var cTMethodStub = {
test: {
test: sandbox.stub().returns(Promise.reject(new common.errors.NoPermissionError()))
test: sinon.stub().returns(Promise.reject(new common.errors.NoPermissionError()))
}
},
cTStub = sandbox.stub(permissions, 'canThis').returns(cTMethodStub);
cTStub = sinon.stub(permissions, 'canThis').returns(cTMethodStub);
apiUtils.handlePublicPermissions('tests', 'test')({context: {user: 1}}).then(function () {
done(new Error('should throw error when no permissions'));
@ -667,8 +665,8 @@ describe('API Utils', function () {
});
it('should handle an unknown rejection', function (done) {
var testStub = sandbox.stub().returns(new Promise.reject(new Error('not found'))),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(new Promise.reject(new Error('not found'))),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -691,8 +689,8 @@ describe('API Utils', function () {
});
it('should handle a NoPermissions rejection', function (done) {
var testStub = sandbox.stub().returns(Promise.reject(new common.errors.NoPermissionError())),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(Promise.reject(new common.errors.NoPermissionError())),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -717,8 +715,8 @@ describe('API Utils', function () {
});
it('should handle success', function (done) {
var testStub = sandbox.stub().returns(new Promise.resolve()),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(new Promise.resolve()),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -744,8 +742,8 @@ describe('API Utils', function () {
});
it('should ignore unsafe attrs if none are provided', function (done) {
var testStub = sandbox.stub().returns(new Promise.resolve()),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(new Promise.resolve()),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -771,8 +769,8 @@ describe('API Utils', function () {
});
it('should ignore unsafe attrs if they are provided but not present', function (done) {
var testStub = sandbox.stub().returns(new Promise.resolve()),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(new Promise.resolve()),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -798,8 +796,8 @@ describe('API Utils', function () {
});
it('should pass through unsafe attrs if they DO exist', function (done) {
var testStub = sandbox.stub().returns(new Promise.resolve()),
permsStub = sandbox.stub(permissions, 'canThis').callsFake(function () {
var testStub = sinon.stub().returns(new Promise.resolve()),
permsStub = sinon.stub(permissions, 'canThis').callsFake(function () {
return {
testing: {
test: testStub
@ -825,8 +823,8 @@ describe('API Utils', function () {
});
it('should strip excludedAttrs from data if permissions function returns them', function () {
var testStub = sandbox.stub().resolves({excludedAttrs: ['foo']}),
permsStub = sandbox.stub(permissions, 'canThis').returns({
var testStub = sinon.stub().resolves({excludedAttrs: ['foo']}),
permsStub = sinon.stub(permissions, 'canThis').returns({
testing: {
test: testStub
}

View File

@ -1,11 +1,10 @@
const should = require('should');
const sinon = require('sinon');
const utils = require('../../../../server/api/v2/utils');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/index', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('isContentAPI', function () {
it('is truthy when having api key and no user', function () {

View File

@ -8,15 +8,12 @@ const sessionController = require('../../../../server/api/v2/session');
const sessionServiceMiddleware = require('../../../../server/services/auth/session/middleware');
describe('Session controller', function () {
let sandbox;
before(function () {
models.init();
sandbox = sinon.sandbox.create();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('exports an add method', function () {
@ -36,7 +33,7 @@ describe('Session controller', function () {
});
it('it checks the username and password and throws UnauthorizedError if it fails', function () {
const userCheckStub = sandbox.stub(models.User, 'check')
const userCheckStub = sinon.stub(models.User, 'check')
.rejects(new Error());
return sessionController.add({
@ -52,16 +49,16 @@ describe('Session controller', function () {
it('it returns a function that calls req.brute.reset, sets req.user and calls createSession if the check works', function () {
const fakeReq = {
brute: {
reset: sandbox.stub().callsArg(0)
reset: sinon.stub().callsArg(0)
}
};
const fakeRes = {};
const fakeNext = () => {};
const fakeUser = models.User.forge({});
sandbox.stub(models.User, 'check')
sinon.stub(models.User, 'check')
.resolves(fakeUser);
const createSessionStub = sandbox.stub(sessionServiceMiddleware, 'createSession');
const createSessionStub = sinon.stub(sessionServiceMiddleware, 'createSession');
return sessionController.add({
username: 'freddy@vodafone.com',
@ -83,16 +80,16 @@ describe('Session controller', function () {
const resetError = new Error();
const fakeReq = {
brute: {
reset: sandbox.stub().callsArgWith(0, resetError)
reset: sinon.stub().callsArgWith(0, resetError)
}
};
const fakeRes = {};
const fakeNext = sandbox.stub();
const fakeNext = sinon.stub();
const fakeUser = models.User.forge({});
sandbox.stub(models.User, 'check')
sinon.stub(models.User, 'check')
.resolves(fakeUser);
const createSessionStub = sandbox.stub(sessionServiceMiddleware, 'createSession');
const createSessionStub = sinon.stub(sessionServiceMiddleware, 'createSession');
return sessionController.add({
username: 'freddy@vodafone.com',
@ -112,7 +109,7 @@ describe('Session controller', function () {
const fakeReq = {};
const fakeRes = {};
const fakeNext = () => {};
const destroySessionStub = sandbox.stub(sessionServiceMiddleware, 'destroySession');
const destroySessionStub = sinon.stub(sessionServiceMiddleware, 'destroySession');
return sessionController.delete().then((fn) => {
fn(fakeReq, fakeRes, fakeNext);
@ -128,7 +125,7 @@ describe('Session controller', function () {
describe('#get', function () {
it('returns the result of User.findOne', function () {
const findOneReturnVal = new Promise(() => {});
const findOneStub = sandbox.stub(models.User, 'findOne')
const findOneStub = sinon.stub(models.User, 'findOne')
.returns(findOneReturnVal);
const result = sessionController.read({

View File

@ -4,21 +4,19 @@ const testUtils = require('../../../../../../utils');
const mapper = require('../../../../../../../server/api/v2/utils/serializers/output/utils/mapper');
const serializers = require('../../../../../../../server/api/v2/utils/serializers');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/pages', () => {
let pageModel;
beforeEach(() => {
pageModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
sandbox.stub(mapper, 'mapPost').returns({});
sinon.stub(mapper, 'mapPost').returns({});
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
it('calls the mapper', () => {

View File

@ -4,21 +4,19 @@ const testUtils = require('../../../../../../utils');
const mapper = require('../../../../../../../server/api/v2/utils/serializers/output/utils/mapper');
const serializers = require('../../../../../../../server/api/v2/utils/serializers');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/posts', () => {
let postModel;
beforeEach(() => {
postModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
sandbox.stub(mapper, 'mapPost').returns({});
sinon.stub(mapper, 'mapPost').returns({});
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
it('calls the mapper', () => {

View File

@ -4,21 +4,19 @@ const testUtils = require('../../../../../../utils');
const mapper = require('../../../../../../../server/api/v2/utils/serializers/output/utils/mapper');
const serializers = require('../../../../../../../server/api/v2/utils/serializers');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/tags', () => {
let tagModel;
beforeEach(() => {
tagModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
sandbox.stub(mapper, 'mapTag').returns({});
sinon.stub(mapper, 'mapTag').returns({});
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
it('calls the mapper when single tag present', () => {

View File

@ -3,11 +3,9 @@ const sinon = require('sinon');
const settingsCache = require('../../../../../../../../server/services/settings/cache');
const dateUtil = require('../../../../../../../../server/api/v2/utils/serializers/output/utils/date');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/utils/date', () => {
afterEach(() => {
sandbox.restore();
sinon.restore();
});
it('creates date strings in ISO 8601 format with UTC offset', () => {
@ -17,7 +15,7 @@ describe('Unit: v2/utils/serializers/output/utils/date', () => {
{in:'2014-12-31T23:28:58.123Z', out: '2015-01-01T00:28:58.123+01:00'},
{in:'2014-03-01T01:28:58.593Z', out: '2014-03-01T02:28:58.593+01:00'}
];
sandbox.stub(settingsCache, 'get').returns(timezone);
sinon.stub(settingsCache, 'get').returns(timezone);
testDates.forEach((date) => {
dateUtil.format(date.in).should.equal(date.out);

View File

@ -1,7 +1,6 @@
const should = require('should');
const sinon = require('sinon');
const extraAttrsUtil = require('../../../../../../../../server/api/v2/utils/serializers/output/utils/extra-attrs');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/utils/extra-attrs', () => {
const frame = {
@ -11,8 +10,8 @@ describe('Unit: v2/utils/serializers/output/utils/extra-attrs', () => {
let model;
beforeEach(function () {
model = sandbox.stub();
model.get = sandbox.stub();
model = sinon.stub();
model.get = sinon.stub();
model.get.withArgs('plaintext').returns(new Array(5000).join('A'));
});

View File

@ -7,25 +7,23 @@ const cleanUtil = require('../../../../../../../../server/api/v2/utils/serialize
const extraAttrsUtils = require('../../../../../../../../server/api/v2/utils/serializers/output/utils/extra-attrs');
const mapper = require('../../../../../../../../server/api/v2/utils/serializers/output/utils/mapper');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/utils/mapper', () => {
beforeEach(() => {
sandbox.stub(dateUtil, 'forPost').returns({});
sinon.stub(dateUtil, 'forPost').returns({});
sandbox.stub(urlUtil, 'forPost').returns({});
sandbox.stub(urlUtil, 'forTag').returns({});
sandbox.stub(urlUtil, 'forUser').returns({});
sinon.stub(urlUtil, 'forPost').returns({});
sinon.stub(urlUtil, 'forTag').returns({});
sinon.stub(urlUtil, 'forUser').returns({});
sandbox.stub(extraAttrsUtils, 'forPost').returns({});
sinon.stub(extraAttrsUtils, 'forPost').returns({});
sandbox.stub(cleanUtil, 'post').returns({});
sandbox.stub(cleanUtil, 'tag').returns({});
sandbox.stub(cleanUtil, 'author').returns({});
sinon.stub(cleanUtil, 'post').returns({});
sinon.stub(cleanUtil, 'tag').returns({});
sinon.stub(cleanUtil, 'author').returns({});
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
describe('mapPost', () => {
@ -34,7 +32,7 @@ describe('Unit: v2/utils/serializers/output/utils/mapper', () => {
beforeEach(() => {
postModel = (data) => {
return Object.assign(data, {
toJSON: sandbox.stub().returns(data)
toJSON: sinon.stub().returns(data)
});
};
});
@ -118,7 +116,7 @@ describe('Unit: v2/utils/serializers/output/utils/mapper', () => {
beforeEach(() => {
userModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
});
@ -146,7 +144,7 @@ describe('Unit: v2/utils/serializers/output/utils/mapper', () => {
beforeEach(() => {
tagModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
});

View File

@ -4,17 +4,15 @@ const testUtils = require('../../../../../../../utils');
const urlService = require('../../../../../../../../server/services/url');
const urlUtil = require('../../../../../../../../server/api/v2/utils/serializers/output/utils/url');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/utils/url', () => {
beforeEach(() => {
sandbox.stub(urlService, 'getUrlByResourceId').returns('getUrlByResourceId');
sandbox.stub(urlService.utils, 'urlFor').returns('urlFor');
sandbox.stub(urlService.utils, 'makeAbsoluteUrls').returns({html: sandbox.stub()});
sinon.stub(urlService, 'getUrlByResourceId').returns('getUrlByResourceId');
sinon.stub(urlService.utils, 'urlFor').returns('urlFor');
sinon.stub(urlService.utils, 'makeAbsoluteUrls').returns({html: sinon.stub()});
});
afterEach(() => {
sandbox.restore();
sinon.restore();
});
describe('Ensure calls url service', () => {
@ -22,7 +20,7 @@ describe('Unit: v2/utils/serializers/output/utils/url', () => {
beforeEach(() => {
pageModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
};
});

View File

@ -3,11 +3,10 @@ const sinon = require('sinon');
const Promise = require('bluebird');
const common = require('../../../../../../../server/lib/common');
const validators = require('../../../../../../../server/api/v2/utils/validators');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/validators/input/posts', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('add', function () {
@ -84,7 +83,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
describe('edit', function () {
it('default', function () {
sandbox.stub(validators.input.posts, 'add');
sinon.stub(validators.input.posts, 'add');
const apiConfig = {};
const frame = {};

View File

@ -1,8 +1,6 @@
var should = require('should'),
rewire = require('rewire'),
configUtils = require('../../../../test/utils/configUtils'),
// Stuff we are testing
ampContentHelper = rewire('../../../../server/apps/amp/lib/helpers/amp_content');
// TODO: Amperize really needs to get stubbed, so we can test returning errors

View File

@ -6,8 +6,7 @@ const should = require('should'),
helpers = require('../../../../server/services/routing/helpers'),
common = require('../../../../server/lib/common'),
testUtils = require('../../../utils'),
configUtils = require('../../../utils/configUtils'),
sandbox = sinon.sandbox.create();
configUtils = require('../../../utils/configUtils');
// Helper function to prevent unit tests
// from failing via timeout when they
@ -25,14 +24,14 @@ describe('Unit - apps/amp/lib/router', function () {
rendererStub;
beforeEach(function () {
rendererStub = sandbox.stub();
rendererStub = sinon.stub();
sandbox.stub(helpers, 'renderer').get(function () {
sinon.stub(helpers, 'renderer').get(function () {
return rendererStub;
});
res = {
render: sandbox.spy(),
render: sinon.spy(),
locals: {
context: ['amp', 'post']
}
@ -54,7 +53,7 @@ describe('Unit - apps/amp/lib/router', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('fn: renderer', function () {
@ -105,17 +104,17 @@ describe('Unit - apps/amp/lib/router', function () {
req = {};
entryLookupStub = sandbox.stub();
entryLookupStub = sinon.stub();
sandbox.stub(helpers, 'entryLookup').get(function () {
sinon.stub(helpers, 'entryLookup').get(function () {
return entryLookupStub;
});
sandbox.stub(urlService, 'getPermalinkByUrl');
sinon.stub(urlService, 'getPermalinkByUrl');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should successfully get the post data from slug', function (done) {

View File

@ -4,9 +4,7 @@ var should = require('should'),
path = require('path'),
configUtils = require('../../../utils/configUtils'),
themes = require('../../../../server/services/themes'),
privateController = require('../../../../server/apps/private-blogging/lib/router'),
sandbox = sinon.sandbox.create();
privateController = require('../../../../server/apps/private-blogging/lib/router');
describe('Private Controller', function () {
var res, req, defaultPath, hasTemplateStub;
@ -21,16 +19,16 @@ describe('Private Controller', function () {
}
beforeEach(function () {
hasTemplateStub = sandbox.stub().returns(false);
hasTemplateStub = sinon.stub().returns(false);
hasTemplateStub.withArgs('index').returns(true);
sandbox.stub(themes, 'getActive').returns({
sinon.stub(themes, 'getActive').returns({
hasTemplate: hasTemplateStub
});
res = {
locals: {version: ''},
render: sandbox.spy()
render: sinon.spy()
};
req = {
@ -49,7 +47,7 @@ describe('Private Controller', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});

View File

@ -5,8 +5,7 @@ var should = require('should'),
fs = require('fs-extra'),
common = require('../../../../server/lib/common'),
settingsCache = require('../../../../server/services/settings/cache'),
privateBlogging = require('../../../../server/apps/private-blogging/lib/middleware'),
sandbox = sinon.sandbox.create();
privateBlogging = require('../../../../server/apps/private-blogging/lib/middleware');
function hash(password, salt) {
var hasher = crypto.createHash('sha256');
@ -18,7 +17,7 @@ describe('Private Blogging', function () {
var settingsStub;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('passProtect', function () {
@ -29,8 +28,8 @@ describe('Private Blogging', function () {
query: {}
};
res = {};
settingsStub = sandbox.stub(settingsCache, 'get');
next = sandbox.spy();
settingsStub = sinon.stub(settingsCache, 'get');
next = sinon.spy();
});
it('checkIsPrivate should call next if not private', function () {
@ -60,7 +59,7 @@ describe('Private Blogging', function () {
it('isPrivateSessionAuth should redirect if blog is not private', function () {
res = {
redirect: sandbox.spy(),
redirect: sinon.spy(),
isPrivateBlog: false
};
privateBlogging.isPrivateSessionAuth(req, res, next);
@ -78,7 +77,7 @@ describe('Private Blogging', function () {
},
set: function () {
},
redirect: sandbox.spy(),
redirect: sinon.spy(),
isPrivateBlog: true
};
@ -136,9 +135,9 @@ describe('Private Blogging', function () {
it('filterPrivateRoutes should render custom robots.txt', function () {
req.url = req.path = '/robots.txt';
res.writeHead = sandbox.spy();
res.end = sandbox.spy();
sandbox.stub(fs, 'readFile').callsFake(function (file, cb) {
res.writeHead = sinon.spy();
res.end = sinon.spy();
sinon.stub(fs, 'readFile').callsFake(function (file, cb) {
cb(null, 'User-agent: * Disallow: /');
});
privateBlogging.filterPrivateRoutes(req, res, next);
@ -175,7 +174,7 @@ describe('Private Blogging', function () {
token: 'wrongpassword',
salt: Date.now().toString()
};
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.authenticatePrivateSession(req, res, next);
res.redirect.called.should.be.true();
@ -188,7 +187,7 @@ describe('Private Blogging', function () {
token: hash('rightpassword', salt),
salt: salt
};
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.isPrivateSessionAuth(req, res, next);
res.redirect.called.should.be.true();
@ -215,7 +214,7 @@ describe('Private Blogging', function () {
it('authenticateProtection should redirect if password is correct', function () {
req.body = {password: 'rightpassword'};
req.session = {};
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next);
res.redirect.called.should.be.true();
@ -227,7 +226,7 @@ describe('Private Blogging', function () {
req.query = {
r: encodeURIComponent('http://britney.com')
};
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next);
res.redirect.called.should.be.true();
@ -244,7 +243,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -261,7 +260,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -278,7 +277,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -295,7 +294,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -312,7 +311,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -329,7 +328,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -346,7 +345,7 @@ describe('Private Blogging', function () {
};
res.isPrivateBlog = true;
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
next.called.should.be.true();
@ -404,7 +403,7 @@ describe('Private Blogging', function () {
res.isPrivateBlog = true;
res.locals = {};
res.redirect = sandbox.spy();
res.redirect = sinon.spy();
privateBlogging.filterPrivateRoutes(req, res, next);
res.redirect.called.should.be.true();

View File

@ -5,8 +5,7 @@ var should = require('should'),
fs = require('fs-extra'),
models = require('../../../../server/models'),
exporter = require('../../../../server/data/exporter'),
backupDatabase = rewire('../../../../server/data/db/backup'),
sandbox = sinon.sandbox.create();
backupDatabase = rewire('../../../../server/data/db/backup');
describe('Backup', function () {
var exportStub, filenameStub, fsStub;
@ -16,13 +15,13 @@ describe('Backup', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
exportStub = sandbox.stub(exporter, 'doExport').resolves();
filenameStub = sandbox.stub(exporter, 'fileName').resolves('test');
fsStub = sandbox.stub(fs, 'writeFile').resolves();
exportStub = sinon.stub(exporter, 'doExport').resolves();
filenameStub = sinon.stub(exporter, 'fileName').resolves('test');
fsStub = sinon.stub(fs, 'writeFile').resolves();
});
it('should create a backup JSON file', function (done) {

View File

@ -7,9 +7,7 @@ var should = require('should'),
exporter = rewire('../../../../server/data/exporter'),
schema = require('../../../../server/data/schema'),
models = require('../../../../server/models'),
schemaTables = Object.keys(schema.tables),
sandbox = sinon.sandbox.create();
schemaTables = Object.keys(schema.tables);
describe('Exporter', function () {
var tablesStub, queryMock, knexMock;
@ -19,7 +17,7 @@ describe('Exporter', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('doExport', function () {
@ -28,16 +26,16 @@ describe('Exporter', function () {
full: '2.0.0'
});
tablesStub = sandbox.stub(schema.commands, 'getTables').returns(schemaTables);
tablesStub = sinon.stub(schema.commands, 'getTables').returns(schemaTables);
queryMock = {
whereNot: sandbox.stub(),
select: sandbox.stub()
whereNot: sinon.stub(),
select: sinon.stub()
};
knexMock = sandbox.stub().returns(queryMock);
knexMock = sinon.stub().returns(queryMock);
sandbox.stub(db, 'knex').get(function () {
sinon.stub(db, 'knex').get(function () {
return knexMock;
});
});
@ -151,7 +149,7 @@ describe('Exporter', function () {
describe('exportFileName', function () {
it('should return a correctly structured filename', function (done) {
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
var settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.resolve({
get: function () {
return 'testblog';
@ -169,7 +167,7 @@ describe('Exporter', function () {
});
it('should return a correctly structured filename if settings is empty', function (done) {
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
var settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.resolve()
);
@ -183,7 +181,7 @@ describe('Exporter', function () {
});
it('should return a correctly structured filename if settings errors', function (done) {
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
var settingsStub = sinon.stub(models.Settings, 'findOne').returns(
new Promise.reject()
);

View File

@ -17,12 +17,11 @@ var should = require('should'),
storage = require('../../../../server/adapters/storage'),
configUtils = require('../../../utils/configUtils'),
sandbox = sinon.sandbox.create();
configUtils = require('../../../utils/configUtils');
describe('Importer', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});
@ -90,8 +89,8 @@ describe('Importer', function () {
describe('loadFile', function () {
it('knows when to process a file', function (done) {
var testFile = {name: 'myFile.json', path: '/my/path/myFile.json'},
zipSpy = sandbox.stub(ImportManager, 'processZip').returns(Promise.resolve()),
fileSpy = sandbox.stub(ImportManager, 'processFile').returns(Promise.resolve());
zipSpy = sinon.stub(ImportManager, 'processZip').returns(Promise.resolve()),
fileSpy = sinon.stub(ImportManager, 'processFile').returns(Promise.resolve());
ImportManager.loadFile(testFile).then(function () {
zipSpy.calledOnce.should.be.false();
@ -103,8 +102,8 @@ describe('Importer', function () {
// We need to make sure we don't actually extract a zip and leave temporary files everywhere!
it('knows when to process a zip', function (done) {
var testZip = {name: 'myFile.zip', path: '/my/path/myFile.zip'},
zipSpy = sandbox.stub(ImportManager, 'processZip').returns(Promise.resolve()),
fileSpy = sandbox.stub(ImportManager, 'processFile').returns(Promise.resolve());
zipSpy = sinon.stub(ImportManager, 'processZip').returns(Promise.resolve()),
fileSpy = sinon.stub(ImportManager, 'processFile').returns(Promise.resolve());
ImportManager.loadFile(testZip).then(function () {
zipSpy.calledOnce.should.be.true();
@ -117,13 +116,13 @@ describe('Importer', function () {
var testFile = {name: 'myFile.json', path: '/my/path/myFile.json'},
testZip = {name: 'myFile.zip', path: '/my/path/myFile.zip'},
// need to stub out the extract and glob function for zip
extractSpy = sandbox.stub(ImportManager, 'extractZip').returns(Promise.resolve('/tmp/dir/')),
validSpy = sandbox.stub(ImportManager, 'isValidZip').returns(true),
baseDirSpy = sandbox.stub(ImportManager, 'getBaseDirectory').returns(),
getFileSpy = sandbox.stub(ImportManager, 'getFilesFromZip'),
jsonSpy = sandbox.stub(JSONHandler, 'loadFile').returns(Promise.resolve({posts: []})),
imageSpy = sandbox.stub(ImageHandler, 'loadFile'),
mdSpy = sandbox.stub(MarkdownHandler, 'loadFile');
extractSpy = sinon.stub(ImportManager, 'extractZip').returns(Promise.resolve('/tmp/dir/')),
validSpy = sinon.stub(ImportManager, 'isValidZip').returns(true),
baseDirSpy = sinon.stub(ImportManager, 'getBaseDirectory').returns(),
getFileSpy = sinon.stub(ImportManager, 'getFilesFromZip'),
jsonSpy = sinon.stub(JSONHandler, 'loadFile').returns(Promise.resolve({posts: []})),
imageSpy = sinon.stub(ImageHandler, 'loadFile'),
mdSpy = sinon.stub(MarkdownHandler, 'loadFile');
getFileSpy.withArgs(JSONHandler).returns(['/tmp/dir/myFile.json']);
getFileSpy.withArgs(ImageHandler).returns([]);
@ -213,8 +212,8 @@ describe('Importer', function () {
var input = {data: {}, images: []},
// pass a copy so that input doesn't get modified
inputCopy = _.cloneDeep(input),
dataSpy = sandbox.spy(DataImporter, 'preProcess'),
imageSpy = sandbox.spy(ImageImporter, 'preProcess');
dataSpy = sinon.spy(DataImporter, 'preProcess'),
imageSpy = sinon.spy(ImageImporter, 'preProcess');
ImportManager.preProcess(inputCopy).then(function (output) {
dataSpy.calledOnce.should.be.true();
@ -239,10 +238,10 @@ describe('Importer', function () {
var input = {data: {posts: []}, images: []},
// pass a copy so that input doesn't get modified
inputCopy = _.cloneDeep(input),
dataSpy = sandbox.stub(DataImporter, 'doImport').callsFake(function (i) {
dataSpy = sinon.stub(DataImporter, 'doImport').callsFake(function (i) {
return Promise.resolve(i);
}),
imageSpy = sandbox.stub(ImageImporter, 'doImport').callsFake(function (i) {
imageSpy = sinon.stub(ImageImporter, 'doImport').callsFake(function (i) {
return Promise.resolve(i);
}),
@ -280,11 +279,11 @@ describe('Importer', function () {
describe('importFromFile', function () {
it('does the import steps in order', function (done) {
var loadFileSpy = sandbox.stub(ImportManager, 'loadFile').returns(Promise.resolve()),
preProcessSpy = sandbox.stub(ImportManager, 'preProcess').returns(Promise.resolve()),
doImportSpy = sandbox.stub(ImportManager, 'doImport').returns(Promise.resolve()),
generateReportSpy = sandbox.stub(ImportManager, 'generateReport').returns(Promise.resolve()),
cleanupSpy = sandbox.stub(ImportManager, 'cleanUp').returns({});
var loadFileSpy = sinon.stub(ImportManager, 'loadFile').returns(Promise.resolve()),
preProcessSpy = sinon.stub(ImportManager, 'preProcess').returns(Promise.resolve()),
doImportSpy = sinon.stub(ImportManager, 'doImport').returns(Promise.resolve()),
generateReportSpy = sinon.stub(ImportManager, 'generateReport').returns(Promise.resolve()),
cleanupSpy = sinon.stub(ImportManager, 'cleanUp').returns({});
ImportManager.importFromFile({}).then(function () {
loadFileSpy.calledOnce.should.be.true();
@ -364,8 +363,8 @@ describe('Importer', function () {
path: '/my/test/' + filename,
name: filename
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
storeSpy = sinon.spy(store, 'getUniqueFileName'),
storageSpy = sinon.spy(storage, 'getStorage');
ImageHandler.loadFile(_.clone(file)).then(function () {
storageSpy.calledOnce.should.be.true();
@ -384,8 +383,8 @@ describe('Importer', function () {
path: '/my/test/' + filename,
name: filename
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
storeSpy = sinon.spy(store, 'getUniqueFileName'),
storageSpy = sinon.spy(storage, 'getStorage');
ImageHandler.loadFile(_.clone(file)).then(function () {
storageSpy.calledOnce.should.be.true();
@ -404,8 +403,8 @@ describe('Importer', function () {
path: '/my/test/content/images/' + filename,
name: filename
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
storeSpy = sinon.spy(store, 'getUniqueFileName'),
storageSpy = sinon.spy(storage, 'getStorage');
ImageHandler.loadFile(_.clone(file)).then(function () {
storageSpy.calledOnce.should.be.true();
@ -426,8 +425,8 @@ describe('Importer', function () {
path: '/my/test/' + filename,
name: filename
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
storeSpy = sinon.spy(store, 'getUniqueFileName'),
storageSpy = sinon.spy(storage, 'getStorage');
ImageHandler.loadFile(_.clone(file)).then(function () {
storageSpy.calledOnce.should.be.true();
@ -457,8 +456,8 @@ describe('Importer', function () {
path: '/my/test/images/puppy.jpg',
name: 'images/puppy.jpg'
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
storeSpy = sinon.spy(store, 'getUniqueFileName'),
storageSpy = sinon.spy(storage, 'getStorage');
ImageHandler.loadFile(_.clone(files)).then(function () {
storageSpy.calledOnce.should.be.true();
@ -684,9 +683,9 @@ describe('Importer', function () {
it('does import the images correctly', function () {
var inputData = require('../../../utils/fixtures/import/import-data-1.json'),
storageApi = {
save: sandbox.stub().returns(Promise.resolve())
save: sinon.stub().returns(Promise.resolve())
},
storageSpy = sandbox.stub(storage, 'getStorage').callsFake(function () {
storageSpy = sinon.stub(storage, 'getStorage').callsFake(function () {
return storageApi;
});

View File

@ -1,7 +1,6 @@
const should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
sandbox = sinon.sandbox.create(),
urlService = require('../../../../server/services/url'),
testUtils = require('../../../utils');
@ -11,17 +10,17 @@ describe('getAmpUrl', function () {
let getUrlStub;
beforeEach(function () {
getUrlStub = sandbox.stub();
getUrlStub = sinon.stub();
getAmpUrl = rewire('../../../../server/data/meta/amp_url');
getAmpUrl.__set__('getUrl', getUrlStub);
sandbox.stub(urlService.utils, 'urlJoin');
sandbox.stub(urlService.utils, 'urlFor').withArgs('home', true).returns('http://localhost:9999');
sinon.stub(urlService.utils, 'urlJoin');
sinon.stub(urlService.utils, 'urlFor').withArgs('home', true).returns('http://localhost:9999');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return amp url for post', function () {

View File

@ -3,14 +3,12 @@ var should = require('should'),
getAssetUrl = require('../../../../server/data/meta/asset_url'),
settingsCache = require('../../../../server/services/settings/cache'),
configUtils = require('../../../utils/configUtils'),
config = configUtils.config,
sandbox = sinon.sandbox.create();
config = configUtils.config;
describe('getAssetUrl', function () {
afterEach(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
it('should return asset url with just context', function () {
@ -45,7 +43,7 @@ describe('getAssetUrl', function () {
});
it('should correct favicon path for custom png', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
var testUrl = getAssetUrl('favicon.ico');
testUrl.should.equal('/favicon.png');
});
@ -114,7 +112,7 @@ describe('getAssetUrl', function () {
});
it('should return correct favicon path for custom png', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
var testUrl = getAssetUrl('favicon.ico');
testUrl.should.equal('/blog/favicon.png');
});

View File

@ -1,11 +1,10 @@
var should = require('should'),
sinon = require('sinon'),
getAuthorImage = require('../../../../server/data/meta/author_image'),
sandbox = sinon.sandbox.create();
getAuthorImage = require('../../../../server/data/meta/author_image');
describe('getAuthorImage', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return author image url if post and has url', function () {

View File

@ -1,17 +1,16 @@
const should = require('should'),
sinon = require('sinon'),
ObjectId = require('bson-objectid'),
sandbox = sinon.sandbox.create(),
urlService = require('../../../../server/services/url'),
getAuthorUrl = require('../../../../server/data/meta/author_url');
describe('getAuthorUrl', function () {
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return author url if context contains primary author', function () {

View File

@ -1,19 +1,17 @@
var should = require('should'),
getBlogLogo = require('../../../../server/data/meta/blog_logo'),
sinon = require('sinon'),
settingsCache = require('../../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../../server/services/settings/cache');
describe('getBlogLogo', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return logo if uploaded', function () {
var blogLogo;
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return {
logo: '/content/images/logo.png',
icon: null
@ -28,7 +26,7 @@ describe('getBlogLogo', function () {
it('should return custom uploaded png icon if no logo given', function () {
var blogLogo;
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return {
logo: null,
icon: '/content/images/favicon.png'

View File

@ -1,7 +1,6 @@
const should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
sandbox = sinon.sandbox.create(),
urlService = require('../../../../server/services/url'),
testUtils = require('../../../utils');
@ -11,17 +10,17 @@ describe('getCanonicalUrl', function () {
let getUrlStub;
beforeEach(function () {
getUrlStub = sandbox.stub();
getUrlStub = sinon.stub();
getCanonicalUrl = rewire('../../../../server/data/meta/canonical_url');
getCanonicalUrl.__set__('getUrl', getUrlStub);
sandbox.stub(urlService.utils, 'urlJoin');
sandbox.stub(urlService.utils, 'urlFor').withArgs('home', true).returns('http://localhost:9999');
sinon.stub(urlService.utils, 'urlJoin');
sinon.stub(urlService.utils, 'urlFor').withArgs('home', true).returns('http://localhost:9999');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return canonical url', function () {

View File

@ -1,8 +1,7 @@
var should = require('should'),
sinon = require('sinon'),
getContextObject = require('../../../../server/data/meta/context_object.js'),
settingsCache = require('../../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../../server/services/settings/cache');
describe('getContextObject', function () {
var data, context, contextObject;
@ -49,7 +48,7 @@ describe('getContextObject', function () {
describe('override blog', function () {
before(function () {
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return {
cover_image: 'test.png'
}[key];
@ -57,7 +56,7 @@ describe('getContextObject', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
it('should return blog context object for unknown context', function () {

View File

@ -1,18 +1,17 @@
var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
getImageDimensions = rewire('../../../../server/data/meta/image-dimensions'),
sandbox = sinon.sandbox.create();
getImageDimensions = rewire('../../../../server/data/meta/image-dimensions');
describe('getImageDimensions', function () {
var sizeOfStub;
beforeEach(function () {
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return dimension for images', function (done) {

View File

@ -1,8 +1,7 @@
var should = require('should'),
sinon = require('sinon'),
models = require('../../../../server/models'),
getKeywords = require('../../../../server/data/meta/keywords'),
sandbox = sinon.sandbox.create();
getKeywords = require('../../../../server/data/meta/keywords');
describe('getKeywords', function () {
before(function () {
@ -10,7 +9,7 @@ describe('getKeywords', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return tags as keywords if post has tags', function () {

View File

@ -1,16 +1,15 @@
const should = require('should'),
sinon = require('sinon'),
sandbox = sinon.sandbox.create(),
routing = require('../../../../server/services/routing'),
getRssUrl = require('../../../../server/data/meta/rss_url');
describe('getRssUrl', function () {
beforeEach(function () {
sandbox.stub(routing.registry, 'getRssUrl').returns('/rss/');
sinon.stub(routing.registry, 'getRssUrl').returns('/rss/');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return rss url', function () {

View File

@ -1,20 +1,19 @@
var should = require('should'),
sinon = require('sinon'),
getTitle = require('../../../../server/data/meta/title'),
settingsCache = require('../../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../../server/services/settings/cache');
describe('getTitle', function () {
var localSettingsCache = {};
beforeEach(function () {
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return localSettingsCache[key];
});
});
afterEach(function () {
sandbox.restore();
sinon.restore();
localSettingsCache = {};
});

View File

@ -1,18 +1,17 @@
const should = require('should'),
sinon = require('sinon'),
sandbox = sinon.sandbox.create(),
urlService = require('../../../../server/services/url'),
getUrl = require('../../../../server/data/meta/url'),
testUtils = require('../../../utils/');
describe('getUrl', function () {
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sandbox.stub(urlService.utils, 'urlFor');
sinon.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService.utils, 'urlFor');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should return url for a post', function () {

View File

@ -6,24 +6,22 @@ var should = require('should'),
models = require('../../../../../server/models'),
baseUtils = require('../../../../../server/models/base/utils'),
fixtureUtils = rewire('../../../../../server/data/schema/fixtures/utils'),
fixtures = require('../../../../../server/data/schema/fixtures/fixtures'),
sandbox = sinon.sandbox.create();
fixtures = require('../../../../../server/data/schema/fixtures/fixtures');
describe('Migration Fixture Utils', function () {
var loggerStub;
beforeEach(function () {
loggerStub = {
info: sandbox.stub(),
warn: sandbox.stub()
info: sinon.stub(),
warn: sinon.stub()
};
models.init();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('Match Func', function () {
@ -31,7 +29,7 @@ describe('Migration Fixture Utils', function () {
getStub;
beforeEach(function () {
getStub = sandbox.stub();
getStub = sinon.stub();
getStub.withArgs('foo').returns('bar');
getStub.withArgs('fun').returns('baz');
});
@ -100,8 +98,8 @@ describe('Migration Fixture Utils', function () {
describe('Add Fixtures For Model', function () {
it('should call add for main post fixture', function (done) {
var postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve()),
postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve({}));
var postOneStub = sinon.stub(models.Post, 'findOne').returns(Promise.resolve()),
postAddStub = sinon.stub(models.Post, 'add').returns(Promise.resolve({}));
fixtureUtils.addFixturesForModel(fixtures.models[5]).then(function (result) {
should.exist(result);
@ -117,8 +115,8 @@ describe('Migration Fixture Utils', function () {
});
it('should not call add for main post fixture if it is already found', function (done) {
var postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve({})),
postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve({}));
var postOneStub = sinon.stub(models.Post, 'findOne').returns(Promise.resolve({})),
postAddStub = sinon.stub(models.Post, 'add').returns(Promise.resolve({}));
fixtureUtils.addFixturesForModel(fixtures.models[5]).then(function (result) {
should.exist(result);
@ -137,17 +135,17 @@ describe('Migration Fixture Utils', function () {
describe('Add Fixtures For Relation', function () {
it('should call attach for permissions-roles', function (done) {
var fromItem = {
related: sandbox.stub().returnsThis(),
findWhere: sandbox.stub().returns()
related: sinon.stub().returnsThis(),
findWhere: sinon.stub().returns()
},
toItem = [{get: sandbox.stub()}],
toItem = [{get: sinon.stub()}],
dataMethodStub = {
filter: sandbox.stub().returns(toItem),
find: sandbox.stub().returns(fromItem)
filter: sinon.stub().returns(toItem),
find: sinon.stub().returns(fromItem)
},
baseUtilAttachStub = sandbox.stub(baseUtils, 'attach').returns(Promise.resolve([{}])),
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(dataMethodStub)),
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(dataMethodStub));
baseUtilAttachStub = sinon.stub(baseUtils, 'attach').returns(Promise.resolve([{}])),
permsAllStub = sinon.stub(models.Permission, 'findAll').returns(Promise.resolve(dataMethodStub)),
rolesAllStub = sinon.stub(models.Role, 'findAll').returns(Promise.resolve(dataMethodStub));
fixtureUtils.addFixturesForRelation(fixtures.relations[0]).then(function (result) {
should.exist(result);
@ -172,17 +170,17 @@ describe('Migration Fixture Utils', function () {
it('should call attach for posts-tags', function (done) {
var fromItem = {
related: sandbox.stub().returnsThis(),
findWhere: sandbox.stub().returns()
related: sinon.stub().returnsThis(),
findWhere: sinon.stub().returns()
},
toItem = [{get: sandbox.stub()}],
toItem = [{get: sinon.stub()}],
dataMethodStub = {
filter: sandbox.stub().returns(toItem),
find: sandbox.stub().returns(fromItem)
filter: sinon.stub().returns(toItem),
find: sinon.stub().returns(fromItem)
},
baseUtilAttachStub = sandbox.stub(baseUtils, 'attach').returns(Promise.resolve([{}])),
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
baseUtilAttachStub = sinon.stub(baseUtils, 'attach').returns(Promise.resolve([{}])),
postsAllStub = sinon.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
tagsAllStub = sinon.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
fixtureUtils.addFixturesForRelation(fixtures.relations[1]).then(function (result) {
should.exist(result);
@ -206,19 +204,19 @@ describe('Migration Fixture Utils', function () {
it('will not call attach for posts-tags if already present', function (done) {
var fromItem = {
related: sandbox.stub().returnsThis(),
findWhere: sandbox.stub().returns({}),
tags: sandbox.stub().returnsThis(),
attach: sandbox.stub().returns(Promise.resolve({}))
related: sinon.stub().returnsThis(),
findWhere: sinon.stub().returns({}),
tags: sinon.stub().returnsThis(),
attach: sinon.stub().returns(Promise.resolve({}))
},
toItem = [{get: sandbox.stub()}],
toItem = [{get: sinon.stub()}],
dataMethodStub = {
filter: sandbox.stub().returns(toItem),
find: sandbox.stub().returns(fromItem)
filter: sinon.stub().returns(toItem),
find: sinon.stub().returns(fromItem)
},
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
postsAllStub = sinon.stub(models.Post, 'findAll').returns(Promise.resolve(dataMethodStub)),
tagsAllStub = sinon.stub(models.Tag, 'findAll').returns(Promise.resolve(dataMethodStub));
fixtureUtils.addFixturesForRelation(fixtures.relations[1]).then(function (result) {
should.exist(result);

View File

@ -8,8 +8,7 @@ const should = require('should'),
PostGenerator = require('../../../../../server/data/xml/sitemap/post-generator'),
PageGenerator = require('../../../../../server/data/xml/sitemap/page-generator'),
TagGenerator = require('../../../../../server/data/xml/sitemap/tag-generator'),
UserGenerator = require('../../../../../server/data/xml/sitemap/user-generator'),
sandbox = sinon.sandbox.create();
UserGenerator = require('../../../../../server/data/xml/sitemap/user-generator');
should.Assertion.add('ValidUrlNode', function (options) {
// Check urlNode looks correct
@ -50,7 +49,7 @@ describe('Generators', function () {
let generator;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('IndexGenerator', function () {
@ -96,11 +95,11 @@ describe('Generators', function () {
describe('fn: getXml', function () {
beforeEach(function () {
sandbox.stub(urlService.utils, 'urlFor');
sinon.stub(urlService.utils, 'urlFor');
});
it('get cached xml', function () {
sandbox.spy(generator, 'generateXmlFromNodes');
sinon.spy(generator, 'generateXmlFromNodes');
generator.siteMapContent = 'something';
generator.getXml().should.eql('something');
generator.siteMapContent = null;

View File

@ -8,9 +8,7 @@ const should = require('should'),
PageGenerator = require('../../../../../server/data/xml/sitemap/page-generator'),
TagGenerator = require('../../../../../server/data/xml/sitemap/tag-generator'),
UserGenerator = require('../../../../../server/data/xml/sitemap/user-generator'),
IndexGenerator = require('../../../../../server/data/xml/sitemap/index-generator'),
sandbox = sinon.sandbox.create();
IndexGenerator = require('../../../../../server/data/xml/sitemap/index-generator');
describe('Unit: sitemap/manager', function () {
let eventsToRemember;
@ -30,18 +28,18 @@ describe('Unit: sitemap/manager', function () {
beforeEach(function () {
eventsToRemember = {};
sandbox.stub(common.events, 'on').callsFake(function (eventName, callback) {
sinon.stub(common.events, 'on').callsFake(function (eventName, callback) {
eventsToRemember[eventName] = callback;
});
sandbox.stub(PostGenerator.prototype, 'getXml');
sandbox.stub(PostGenerator.prototype, 'addUrl');
sandbox.stub(PostGenerator.prototype, 'removeUrl');
sandbox.stub(IndexGenerator.prototype, 'getXml');
sinon.stub(PostGenerator.prototype, 'getXml');
sinon.stub(PostGenerator.prototype, 'addUrl');
sinon.stub(PostGenerator.prototype, 'removeUrl');
sinon.stub(IndexGenerator.prototype, 'getXml');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('SiteMapManager', function () {
@ -49,7 +47,7 @@ describe('Unit: sitemap/manager', function () {
beforeEach(function () {
manager = makeStubManager();
fake = sandbox.stub();
fake = sinon.stub();
});
it('create SiteMapManager with defaults', function () {

View File

@ -4,9 +4,7 @@ var should = require('should'),
_ = require('lodash'),
// Stuff we are testing
Filters = require('../../server/filters').Filters,
sandbox = sinon.sandbox.create();
Filters = require('../../server/filters').Filters;
describe('Filters', function () {
var filters;
@ -17,13 +15,13 @@ describe('Filters', function () {
afterEach(function () {
filters = null;
sandbox.restore();
sinon.restore();
});
it('can register filters with specific priority', function () {
var filterName = 'test',
filterPriority = 9,
testFilterHandler = sandbox.spy();
testFilterHandler = sinon.spy();
filters.registerFilter(filterName, filterPriority, testFilterHandler);
@ -36,7 +34,7 @@ describe('Filters', function () {
it('can register filters with default priority', function () {
var filterName = 'test',
defaultPriority = 5,
testFilterHandler = sandbox.spy();
testFilterHandler = sinon.spy();
filters.registerFilter(filterName, testFilterHandler);
@ -49,7 +47,7 @@ describe('Filters', function () {
it('can register filters with priority null with default priority', function () {
var filterName = 'test',
defaultPriority = 5,
testFilterHandler = sandbox.spy();
testFilterHandler = sinon.spy();
filters.registerFilter(filterName, null, testFilterHandler);
@ -61,9 +59,9 @@ describe('Filters', function () {
it('executes filters in priority order', function (done) {
var filterName = 'testpriority',
testFilterHandler1 = sandbox.spy(),
testFilterHandler2 = sandbox.spy(),
testFilterHandler3 = sandbox.spy();
testFilterHandler1 = sinon.spy(),
testFilterHandler2 = sinon.spy(),
testFilterHandler3 = sinon.spy();
filters.registerFilter(filterName, 0, testFilterHandler1);
filters.registerFilter(filterName, 2, testFilterHandler2);

View File

@ -2,9 +2,7 @@ var should = require('should'),
sinon = require('sinon'),
configUtils = require('../../utils/configUtils'),
helpers = require('../../../server/helpers'),
settingsCache = require('../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../server/services/settings/cache');
describe('{{asset}} helper', function () {
var rendered, localSettingsCache = {};
@ -13,14 +11,14 @@ describe('{{asset}} helper', function () {
configUtils.set({assetHash: 'abc'});
configUtils.set({useMinFiles: true});
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return localSettingsCache[key];
});
});
after(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
describe('no subdirectory', function () {

View File

@ -1,17 +1,16 @@
const should = require('should'),
sinon = require('sinon'),
sandbox = sinon.sandbox.create(),
testUtils = require('../../utils'),
urlService = require('../../../server/services/url'),
helpers = require('../../../server/helpers');
describe('{{author}} helper', function () {
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('Returns the link to the author from the context', function () {

View File

@ -3,8 +3,7 @@ const should = require('should'),
urlService = require('../../../server/services/url'),
helpers = require('../../../server/helpers'),
models = require('../../../server/models'),
testUtils = require('../../utils'),
sandbox = sinon.sandbox.create();
testUtils = require('../../utils');
describe('{{authors}} helper', function () {
before(function () {
@ -12,11 +11,11 @@ describe('{{authors}} helper', function () {
});
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('can return string with authors', function () {

View File

@ -2,15 +2,13 @@ var should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
helpers = require.main.require('core/server/helpers'),
handlebars = require.main.require('core/server/services/themes/engine').handlebars,
sandbox = sinon.sandbox.create();
handlebars = require.main.require('core/server/services/themes/engine').handlebars;
describe('{{#foreach}} helper', function () {
var options, context, _this, resultData;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('(function call)', function () {
@ -24,8 +22,8 @@ describe('{{#foreach}} helper', function () {
}
options = {
fn: sandbox.spy(fn),
inverse: sandbox.spy(),
fn: sinon.spy(fn),
inverse: sinon.spy(),
data: {}
};
});

View File

@ -7,9 +7,7 @@ var should = require('should'),
models = require('../../../server/models'),
api = require('../../../server/api'),
labs = require('../../../server/services/labs'),
sandbox = sinon.sandbox.create();
labs = require('../../../server/services/labs');
describe('{{#get}} helper', function () {
var fn, inverse, labsStub;
@ -20,15 +18,15 @@ describe('{{#get}} helper', function () {
});
beforeEach(function () {
fn = sandbox.spy();
inverse = sandbox.spy();
labsStub = sandbox.stub(labs, 'isSet').returns(true);
fn = sinon.spy();
inverse = sinon.spy();
labsStub = sinon.stub(labs, 'isSet').returns(true);
locals = {root: {_locals: {apiVersion: 'v0.1'}}};
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('errors correctly if labs flag not set', function (done) {
@ -66,10 +64,10 @@ describe('{{#get}} helper', function () {
meta = {pagination: {}};
beforeEach(function () {
browsePostsStub = sandbox.stub(api["v0.1"].posts, 'browse');
readPostsStub = sandbox.stub(api["v0.1"].posts, 'read');
readTagsStub = sandbox.stub(api["v0.1"].tags, 'read').returns(new Promise.resolve({tags: []}));
readUsersStub = sandbox.stub(api["v0.1"].users, 'read').returns(new Promise.resolve({users: []}));
browsePostsStub = sinon.stub(api["v0.1"].posts, 'browse');
readPostsStub = sinon.stub(api["v0.1"].posts, 'read');
readTagsStub = sinon.stub(api["v0.1"].tags, 'read').returns(new Promise.resolve({tags: []}));
readUsersStub = sinon.stub(api["v0.1"].users, 'read').returns(new Promise.resolve({users: []}));
browsePostsStub.returns(new Promise.resolve({posts: testPostsArr, meta: meta}));
browsePostsStub.withArgs({limit: '3'}).returns(new Promise.resolve({
@ -261,7 +259,7 @@ describe('{{#get}} helper', function () {
const meta = {pagination: {}};
beforeEach(function () {
browseUsersStub = sandbox.stub(api["v0.1"].users, 'browse');
browseUsersStub = sinon.stub(api["v0.1"].users, 'browse');
browseUsersStub.returns(new Promise.resolve({users: [], meta: meta}));
});
@ -288,7 +286,7 @@ describe('{{#get}} helper', function () {
const meta = {pagination: {}};
beforeEach(function () {
browseUsersStub = sandbox.stub(api["v0.1"].users, 'browse');
browseUsersStub = sinon.stub(api["v0.1"].users, 'browse');
browseUsersStub.returns(new Promise.resolve({users: [], meta: meta}));
});
@ -313,9 +311,9 @@ describe('{{#get}} helper', function () {
beforeEach(function () {
locals = {root: {_locals: {apiVersion: 'v2'}}};
browseUsersStub = sandbox.stub(api["v2"], 'authors').get(() => {
browseUsersStub = sinon.stub(api["v2"], 'authors').get(() => {
return {
browse: sandbox.stub().resolves({authors: [], meta: meta})
browse: sinon.stub().resolves({authors: [], meta: meta})
};
});
});
@ -346,9 +344,9 @@ describe('{{#get}} helper', function () {
beforeEach(function () {
locals = {root: {_locals: {apiVersion: 'v2'}}};
browseUsersStub = sandbox.stub(api["v2"], 'authors').get(() => {
browseUsersStub = sinon.stub(api["v2"], 'authors').get(() => {
return {
browse: sandbox.stub().resolves({authors: [], meta: meta})
browse: sinon.stub().resolves({authors: [], meta: meta})
};
});
});
@ -427,8 +425,8 @@ describe('{{#get}} helper', function () {
};
beforeEach(function () {
browseStub = sandbox.stub(api["v0.1"].posts, 'browse').returns(new Promise.resolve());
readStub = sandbox.stub(api["v0.1"].posts, 'read').returns(new Promise.resolve());
browseStub = sinon.stub(api["v0.1"].posts, 'browse').returns(new Promise.resolve());
readStub = sinon.stub(api["v0.1"].posts, 'read').returns(new Promise.resolve());
});
it('should resolve post.tags alias', function (done) {

View File

@ -1,22 +1,18 @@
var should = require('should'),
sinon = require('sinon'),
// Stuff we are testing
helpers = require('../../../server/helpers'),
proxy = require('../../../server/helpers/proxy'),
settingsCache = proxy.settingsCache,
sandbox = sinon.sandbox.create();
settingsCache = proxy.settingsCache;
describe('{{ghost_foot}} helper', function () {
var settingsCacheStub;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
settingsCacheStub = sandbox.stub(settingsCache, 'get');
settingsCacheStub = sinon.stub(settingsCache, 'get');
});
it('outputs global injected code', function (done) {

View File

@ -11,8 +11,7 @@ const should = require('should'),
urlService = require('../../../server/services/url'),
helpers = require('../../../server/helpers'),
proxy = require('../../../server/helpers/proxy'),
settingsCache = proxy.settingsCache,
sandbox = sinon.sandbox.create();
settingsCache = proxy.settingsCache;
describe('{{ghost_head}} helper', function () {
let posts = [], tags = [], authors = [], users = [];
@ -273,16 +272,16 @@ describe('{{ghost_head}} helper', function () {
before(function () {
// @TODO: remove when visibility is refactored out of models
models.init();
sandbox.stub(urlService, 'getUrlByResourceId').returns('https://mysite.com/fakeauthor/');
sinon.stub(urlService, 'getUrlByResourceId').returns('https://mysite.com/fakeauthor/');
// @TODO: this is a LOT of mocking :/
sandbox.stub(routing.registry, 'getRssUrl').returns('http://localhost:65530/rss/');
sandbox.stub(imageLib.imageSize, 'getImageSizeFromUrl').resolves();
sandbox.stub(themes, 'getActive').returns({
sinon.stub(routing.registry, 'getRssUrl').returns('http://localhost:65530/rss/');
sinon.stub(imageLib.imageSize, 'getImageSizeFromUrl').resolves();
sinon.stub(themes, 'getActive').returns({
engine: () => 'v0.1'
});
sandbox.stub(settingsCache, 'get');
sinon.stub(settingsCache, 'get');
settingsCache.get.withArgs('title').returns('Ghost');
settingsCache.get.withArgs('description').returns('blog description');
settingsCache.get.withArgs('cover_image').returns('/content/images/blog-cover.png');
@ -292,7 +291,7 @@ describe('{{ghost_head}} helper', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});

View File

@ -2,20 +2,18 @@ var should = require('should'),
sinon = require('sinon'),
// Stuff we are testing
helpers = require('../../../server/helpers'),
sandbox = sinon.sandbox.create();
helpers = require('../../../server/helpers');
describe('{{#has}} helper', function () {
var fn, inverse, thisCtx, handlebarsOptions;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
beforeEach(function () {
fn = sandbox.spy();
inverse = sandbox.spy();
fn = sinon.spy();
inverse = sinon.spy();
thisCtx = {};

View File

@ -4,9 +4,7 @@ var should = require('should'),
// Stuff we are testing
helpers = require('../../../server/helpers'),
common = require('../../../server/lib/common'),
sandbox = sinon.sandbox.create();
common = require('../../../server/lib/common');
describe('{{image}} helper', function () {
var logWarnStub;
@ -16,11 +14,11 @@ describe('{{image}} helper', function () {
});
beforeEach(function () {
logWarnStub = sandbox.stub(common.logging, 'warn');
logWarnStub = sinon.stub(common.logging, 'warn');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
after(function () {

View File

@ -1,19 +1,17 @@
var should = require('should'),
sinon = require('sinon'),
helpers = require('../../../server/helpers'),
common = require('../../../server/lib/common'),
sandbox = sinon.sandbox.create();
common = require('../../../server/lib/common');
describe('{{#is}} helper', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
// All positive tests
it('should match single context "index"', function () {
var fn = sandbox.spy(),
inverse = sandbox.spy();
var fn = sinon.spy(),
inverse = sinon.spy();
helpers.is.call(
{},
@ -26,8 +24,8 @@ describe('{{#is}} helper', function () {
});
it('should match OR context "index, paged"', function () {
var fn = sandbox.spy(),
inverse = sandbox.spy();
var fn = sinon.spy(),
inverse = sinon.spy();
helpers.is.call(
{},
@ -40,8 +38,8 @@ describe('{{#is}} helper', function () {
});
it('should not match "paged"', function () {
var fn = sandbox.spy(),
inverse = sandbox.spy();
var fn = sinon.spy(),
inverse = sinon.spy();
helpers.is.call(
{},
@ -54,9 +52,9 @@ describe('{{#is}} helper', function () {
});
it('should log warning with no args', function () {
var fn = sandbox.spy(),
inverse = sandbox.spy(),
logWarn = sandbox.stub(common.logging, 'warn');
var fn = sinon.spy(),
inverse = sinon.spy(),
logWarn = sinon.stub(common.logging, 'warn');
helpers.is.call(
{},

View File

@ -2,18 +2,16 @@ var should = require('should'),
sinon = require('sinon'),
configUtils = require('../../utils/configUtils'),
helpers = require('../../../server/helpers'),
settingsCache = require('../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../server/services/settings/cache');
describe('{{meta_description}} helper', function () {
before(function () {
sandbox.stub(settingsCache, 'get').returns('The professional publishing platform');
sinon.stub(settingsCache, 'get').returns('The professional publishing platform');
});
after(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
it('returns correct blog description', function () {

View File

@ -2,13 +2,11 @@ var should = require('should'),
sinon = require('sinon'),
configUtils = require('../../utils/configUtils'),
helpers = require('../../../server/helpers'),
settingsCache = require('../../../server/services/settings/cache'),
sandbox = sinon.sandbox.create();
settingsCache = require('../../../server/services/settings/cache');
describe('{{meta_title}} helper', function () {
before(function () {
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
sinon.stub(settingsCache, 'get').callsFake(function (key) {
return {
title: 'Ghost'
}[key];
@ -17,7 +15,7 @@ describe('{{meta_title}} helper', function () {
after(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
});
it('returns correct title for homepage', function () {

View File

@ -5,9 +5,7 @@ var should = require('should'),
helpers = require('../../../server/helpers'),
api = require('../../../server/api'),
common = require('../../../server/lib/common'),
sandbox = sinon.sandbox.create();
common = require('../../../server/lib/common');
describe('{{next_post}} helper', function () {
let locals;
@ -25,12 +23,12 @@ describe('{{next_post}} helper', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('with valid post data - ', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({
posts: [{slug: '/next/', title: 'post 3'}]
@ -72,7 +70,7 @@ describe('{{next_post}} helper', function () {
describe('for valid post with no next post', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({posts: []});
}
@ -110,7 +108,7 @@ describe('{{next_post}} helper', function () {
describe('for invalid post data', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({});
}
@ -146,7 +144,7 @@ describe('{{next_post}} helper', function () {
}
};
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({posts: [{slug: '/previous/', title: 'post 1'}]});
}
@ -190,7 +188,7 @@ describe('{{next_post}} helper', function () {
}
};
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({posts: [{slug: '/next/', title: 'post 3'}]});
}
@ -224,7 +222,7 @@ describe('{{next_post}} helper', function () {
describe('with "in" option', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:>') > -1) {
return Promise.resolve({
posts: [{slug: '/next/', title: 'post 1'}]
@ -395,7 +393,7 @@ describe('{{next_post}} helper', function () {
describe('general error handling', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function () {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function () {
return Promise.reject(new common.errors.NotFoundError({message: 'Something wasn\'t found'}));
});
});

View File

@ -5,9 +5,7 @@ var should = require('should'),
helpers = require('../../../server/helpers'),
api = require('../../../server/api'),
common = require('../../../server/lib/common'),
sandbox = sinon.sandbox.create();
common = require('../../../server/lib/common');
describe('{{prev_post}} helper', function () {
var browsePostStub;
@ -25,12 +23,12 @@ describe('{{prev_post}} helper', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('with valid post data - ', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({
posts: [{slug: '/previous/', title: 'post 1'}]
@ -72,7 +70,7 @@ describe('{{prev_post}} helper', function () {
describe('for valid post with no previous post', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({posts: []});
}
@ -110,7 +108,7 @@ describe('{{prev_post}} helper', function () {
describe('for invalid post data', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({});
}
@ -146,7 +144,7 @@ describe('{{prev_post}} helper', function () {
}
};
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({posts: [{slug: '/previous/', title: 'post 1'}]});
}
@ -190,7 +188,7 @@ describe('{{prev_post}} helper', function () {
}
};
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({posts: [{slug: '/previous/', title: 'post 1'}]});
}
@ -224,7 +222,7 @@ describe('{{prev_post}} helper', function () {
describe('with "in" option', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function (options) {
if (options.filter.indexOf('published_at:<=') > -1) {
return Promise.resolve({
posts: [{slug: '/previous/', title: 'post 1'}]
@ -395,7 +393,7 @@ describe('{{prev_post}} helper', function () {
describe('general error handling', function () {
beforeEach(function () {
browsePostStub = sandbox.stub(api['v0.1'].posts, 'browse').callsFake(function () {
browsePostStub = sinon.stub(api['v0.1'].posts, 'browse').callsFake(function () {
return Promise.reject(new common.errors.NotFoundError({message: 'Something wasn\'t found'}));
});
});

View File

@ -3,8 +3,7 @@ const should = require('should'),
testUtils = require('../../utils'),
urlService = require('../../../server/services/url'),
models = require('../../../server/models'),
helpers = require('../../../server/helpers'),
sandbox = sinon.sandbox.create();
helpers = require('../../../server/helpers');
describe('{{tags}} helper', function () {
before(function () {
@ -12,11 +11,11 @@ describe('{{tags}} helper', function () {
});
beforeEach(function () {
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('can return string with tags', function () {

View File

@ -6,8 +6,7 @@ var should = require('should'),
markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc,
helpers = require('../../../server/helpers'),
urlService = require('../../../server/services/url'),
api = require('../../../server/api'),
sandbox = sinon.sandbox.create();
api = require('../../../server/api');
describe('{{url}} helper', function () {
var rendered;
@ -19,15 +18,15 @@ describe('{{url}} helper', function () {
beforeEach(function () {
rendered = null;
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(urlService, 'getUrlByResourceId');
sandbox.stub(api.settings, 'read').callsFake(function () {
sinon.stub(api.settings, 'read').callsFake(function () {
return Promise.resolve({settings: [{value: '/:slug/'}]});
});
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
after(function () {

View File

@ -9,9 +9,7 @@ var should = require('should'),
config = configUtils.config,
// stuff we are testing
blogIcon = rewire('../../../../server/lib/image/blog-icon'),
sandbox = sinon.sandbox.create();
blogIcon = rewire('../../../../server/lib/image/blog-icon');
describe('lib/image: blog icon', function () {
before(function () {
@ -20,18 +18,18 @@ describe('lib/image: blog icon', function () {
afterEach(function () {
configUtils.restore();
sandbox.restore();
sinon.restore();
rewire('../../../../server/lib/image/blog-icon');
});
describe('getIconUrl', function () {
it('custom uploaded ico blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
blogIcon.getIconUrl().should.eql('/favicon.ico');
});
it('custom uploaded png blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
blogIcon.getIconUrl().should.eql('/favicon.png');
});
@ -41,13 +39,13 @@ describe('lib/image: blog icon', function () {
describe('absolute URL', function () {
it('custom uploaded ico blog icon', function () {
configUtils.set({url: 'http://my-ghost-blog.com/'});
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
blogIcon.getIconUrl(true).should.eql('http://my-ghost-blog.com/favicon.ico');
});
it('custom uploaded png blog icon', function () {
configUtils.set({url: 'http://my-ghost-blog.com/'});
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
blogIcon.getIconUrl(true).should.eql('http://my-ghost-blog.com/favicon.png');
});
@ -59,14 +57,14 @@ describe('lib/image: blog icon', function () {
describe('with subdirectory', function () {
it('custom uploaded ico blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
blogIcon.getIconUrl().should.eql('/blog/favicon.ico');
});
it('custom uploaded png blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
blogIcon.getIconUrl().should.eql('/blog/favicon.png');
@ -81,12 +79,12 @@ describe('lib/image: blog icon', function () {
describe('getIconPath', function () {
it('custom uploaded ico blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.ico');
blogIcon.getIconPath().should.eql('/2017/04/my-icon.ico');
});
it('custom uploaded png blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/content/images/2017/04/my-icon.png');
blogIcon.getIconPath().should.eql('/2017/04/my-icon.png');
});
@ -96,14 +94,14 @@ describe('lib/image: blog icon', function () {
describe('with subdirectory', function () {
it('custom uploaded ico blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/blog/content/images/2017/04/my-icon.ico');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/blog/content/images/2017/04/my-icon.ico');
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
blogIcon.getIconPath().should.eql('/2017/04/my-icon.ico');
});
it('custom uploaded png blog icon', function () {
sandbox.stub(settingsCache, 'get').withArgs('icon').returns('/blog/content/images/2017/04/my-icon.png');
sinon.stub(settingsCache, 'get').withArgs('icon').returns('/blog/content/images/2017/04/my-icon.png');
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
blogIcon.getIconPath().should.eql('/2017/04/my-icon.png');
@ -174,7 +172,7 @@ describe('lib/image: blog icon', function () {
});
it('[failure] return error message', function (done) {
var sizeOfStub = sandbox.stub();
var sizeOfStub = sinon.stub();
sizeOfStub.throws({error: 'image-size could not find dimensions'});

View File

@ -4,20 +4,18 @@ var should = require('should'),
rewire = require('rewire'),
// Stuff we are testing
getCachedImageSizeFromUrl = rewire('../../../../server/lib/image/cached-image-size-from-url'),
sandbox = sinon.sandbox.create();
getCachedImageSizeFromUrl = rewire('../../../../server/lib/image/cached-image-size-from-url');
describe('lib/image: image size cache', function () {
var sizeOfStub,
cachedImagedSize;
beforeEach(function () {
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
getCachedImageSizeFromUrl.__set__('cache', {});
});

View File

@ -9,9 +9,7 @@ var should = require('should'),
storage = require('../../../../server/adapters/storage'),
// Stuff we are testing
imageSize = rewire('../../../../server/lib/image/image-size'),
sandbox = sinon.sandbox.create();
imageSize = rewire('../../../../server/lib/image/image-size');
describe('lib/image: image size', function () {
var sizeOfStub,
@ -25,7 +23,7 @@ describe('lib/image: image size', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
imageSize = rewire('../../../../server/lib/image/image-size');
storage.getStorage().storagePath = originalStoragePath;
@ -50,7 +48,7 @@ describe('lib/image: image size', function () {
.get('/files/f/feedough/x/11/1540353_20925115.jpg')
.reply(200);
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({width: 50, height: 50, type: 'jpg'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -82,7 +80,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({width: 256, height: 256, type: 'png'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -117,7 +115,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 68 00 00 00 0f 08 02 00 00 00 87 8f 1d 14 00 00 03 33 49 44 41 54 58 c3 ed 97 6b 48 93 51 18>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({width: 104, height: 15, type: 'png'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -149,7 +147,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({
width: 32,
height: 32,
@ -186,9 +184,9 @@ describe('lib/image: image size', function () {
width: 100
};
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
requestMock = nock('http://myblog.com')
@ -197,7 +195,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({width: 100, height: 100, type: 'svg'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -229,7 +227,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.returns({width: 250, height: 250, type: 'jpg'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -299,10 +297,10 @@ describe('lib/image: image size', function () {
};
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/content/images/favicon.png');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
requestMock = nock('http://myblog.com')
@ -381,7 +379,7 @@ describe('lib/image: image size', function () {
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.throws({error: 'image-size could not find dimensions'});
imageSize.__set__('sizeOf', sizeOfStub);
@ -426,10 +424,10 @@ describe('lib/image: image size', function () {
};
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/content/images/ghost-logo.png');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = imageSize.getImageSizeFromStoragePath(url).then(function (res) {
@ -456,10 +454,10 @@ describe('lib/image: image size', function () {
};
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/blog/content/images/favicon_too_large.png');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = imageSize.getImageSizeFromStoragePath(url).then(function (res) {
@ -486,10 +484,10 @@ describe('lib/image: image size', function () {
};
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/content/images/favicon_multi_sizes.ico');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = imageSize.getImageSizeFromStoragePath(url).then(function (res) {
@ -510,10 +508,10 @@ describe('lib/image: image size', function () {
urlGetSubdirStub;
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/content/images/not-existing-image.png');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = imageSize.getImageSizeFromStoragePath(url)
@ -529,15 +527,15 @@ describe('lib/image: image size', function () {
urlForStub,
urlGetSubdirStub;
sizeOfStub = sandbox.stub();
sizeOfStub = sinon.stub();
sizeOfStub.throws({error: 'image-size could not find dimensions'});
imageSize.__set__('sizeOf', sizeOfStub);
storage.getStorage().storagePath = path.join(__dirname, '../../../../test/utils/fixtures/images/');
urlForStub = sandbox.stub(urlService.utils, 'urlFor');
urlForStub = sinon.stub(urlService.utils, 'urlFor');
urlForStub.withArgs('image').returns('http://myblog.com/content/images/ghost-logo.pngx');
urlForStub.withArgs('home').returns('http://myblog.com/');
urlGetSubdirStub = sandbox.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub = sinon.stub(urlService.utils, 'getSubdir');
urlGetSubdirStub.returns('');
result = imageSize.getImageSizeFromStoragePath(url)

View File

@ -4,11 +4,10 @@ const fs = require('fs-extra');
const common = require('../../../../server/lib/common');
const manipulator = require('../../../../server/lib/image/manipulator');
const testUtils = require('../../../utils');
const sandbox = sinon.sandbox.create();
describe('lib/image: manipulator', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
testUtils.unmockNotExistingModule();
});
@ -43,16 +42,16 @@ describe('lib/image: manipulator', function () {
let sharp, sharpInstance;
beforeEach(function () {
sandbox.stub(fs, 'readFile').resolves('original');
sandbox.stub(fs, 'writeFile').resolves();
sinon.stub(fs, 'readFile').resolves('original');
sinon.stub(fs, 'writeFile').resolves();
sharpInstance = {
resize: sandbox.stub().returnsThis(),
rotate: sandbox.stub().returnsThis(),
toBuffer: sandbox.stub(),
resize: sinon.stub().returnsThis(),
rotate: sinon.stub().returnsThis(),
toBuffer: sinon.stub(),
};
sharp = sandbox.stub().callsFake(() => {
sharp = sinon.stub().callsFake(() => {
return sharpInstance;
});

View File

@ -2,10 +2,8 @@ var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
// Stuff we are testing
pipeline = require('../../../../server/lib/promise/pipeline'),
sandbox = sinon.sandbox.create();
// Stuff we are testing
pipeline = require('../../../../server/lib/promise/pipeline');
// These tests are based on the tests in https://github.com/cujojs/when/blob/3.7.4/test/pipeline-test.js
function createTask(y) {
@ -16,7 +14,7 @@ function createTask(y) {
describe('Pipeline', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('should execute tasks in order', function () {
@ -39,7 +37,7 @@ describe('Pipeline', function () {
it('should pass args to initial task', function () {
var expected = [1, 2, 3],
tasks = [sandbox.spy()];
tasks = [sinon.spy()];
return pipeline(tasks, 1, 2, 3).then(function () {
tasks[0].calledOnce.should.be.true();
@ -49,7 +47,7 @@ describe('Pipeline', function () {
it('should allow initial args to be promises', function () {
var expected = [1, 2, 3],
tasks = [sandbox.spy()],
tasks = [sinon.spy()],
Resolver = Promise.resolve;
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(function () {
@ -61,9 +59,9 @@ describe('Pipeline', function () {
it('should allow tasks to be promises', function () {
var expected = [1, 2, 3],
tasks = [
sandbox.stub().returns(new Promise.resolve(4)),
sandbox.stub().returns(new Promise.resolve(5)),
sandbox.stub().returns(new Promise.resolve(6))
sinon.stub().returns(new Promise.resolve(4)),
sinon.stub().returns(new Promise.resolve(5)),
sinon.stub().returns(new Promise.resolve(6))
];
return pipeline(tasks, 1, 2, 3).then(function (result) {
@ -80,9 +78,9 @@ describe('Pipeline', function () {
it('should allow tasks and args to be promises', function () {
var expected = [1, 2, 3],
tasks = [
sandbox.stub().returns(new Promise.resolve(4)),
sandbox.stub().returns(new Promise.resolve(5)),
sandbox.stub().returns(new Promise.resolve(6))
sinon.stub().returns(new Promise.resolve(4)),
sinon.stub().returns(new Promise.resolve(5)),
sinon.stub().returns(new Promise.resolve(6))
],
Resolver = Promise.resolve;

View File

@ -2,11 +2,10 @@ const should = require('should');
const sinon = require('sinon');
const Promise = require('bluebird');
const sequence = require('../../../../server/lib/promise/sequence');
const sandbox = sinon.sandbox.create();
describe('Unit: lib/promise/sequence', function () {
afterEach(function () {
sandbox.restore();
sinon.restore();
});
it('mixed tasks: promise and none promise', function () {

View File

@ -77,8 +77,7 @@ describe('Unit: models/api_key', function () {
describe('refreshSecret', function () {
it('returns a call to edit passing a new secret', function () {
const sandbox = sinon.sandbox.create();
const editStub = sandbox.stub(models.ApiKey, 'edit').resolves();
const editStub = sinon.stub(models.ApiKey, 'edit').resolves();
const fakeData = {
id: 'TREVOR'
@ -92,7 +91,7 @@ describe('Unit: models/api_key', function () {
should.equal(editStub.args[0][0].secret.length, 128);
should.equal(editStub.args[0][1], fakeOptions);
sandbox.restore();
sinon.restore();
});
});
});

View File

@ -6,8 +6,7 @@ var should = require('should'),
models = require('../../../../server/models'),
urlService = require('../../../../server/services/url'),
filters = require('../../../../server/filters'),
testUtils = require('../../../utils'),
sandbox = sinon.sandbox.create();
testUtils = require('../../../utils');
describe('Models: base', function () {
before(function () {
@ -15,7 +14,7 @@ describe('Models: base', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('generateSlug', function () {
@ -23,15 +22,15 @@ describe('Models: base', function () {
let options = {};
beforeEach(function () {
sandbox.stub(security.string, 'safe');
sandbox.stub(filters, 'doFilter').resolves();
sandbox.stub(urlService.utils, 'getProtectedSlugs').returns(['upsi', 'schwupsi']);
sinon.stub(security.string, 'safe');
sinon.stub(filters, 'doFilter').resolves();
sinon.stub(urlService.utils, 'getProtectedSlugs').returns(['upsi', 'schwupsi']);
Model = sandbox.stub();
Model = sinon.stub();
Model.prototype = {
tableName: 'tableName'
};
Model.findOne = sandbox.stub();
Model.findOne = sinon.stub();
});
it('default', function () {
@ -175,7 +174,7 @@ describe('Models: base', function () {
it('resets given empty value to null', function () {
const base = models.Base.Model.forge({a: '', b: ''});
base.emptyStringProperties = sandbox.stub();
base.emptyStringProperties = sinon.stub();
base.emptyStringProperties.returns(['a']);
base.get('a').should.eql('');
@ -201,12 +200,12 @@ describe('Models: base', function () {
}
};
const model = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves(model);
const destroyStub = sandbox.stub(model, 'destroy');
const destroyStub = sinon.stub(model, 'destroy');
return models.Base.Model.destroy(unfilteredOptions).then(() => {
should.equal(filterOptionsSpy.args[0][0], unfilteredOptions);
@ -228,12 +227,12 @@ describe('Models: base', function () {
id: 23
};
const model = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves(model);
const destroyStub = sandbox.stub(model, 'destroy');
const destroyStub = sinon.stub(model, 'destroy');
return models.Base.Model.destroy(unfilteredOptions).then(() => {
should.equal(filterOptionsSpy.args[0][0], unfilteredOptions);
@ -261,11 +260,11 @@ describe('Models: base', function () {
};
const model = models.Base.Model.forge({});
const fetchedModel = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sandbox.spy(models.Base.Model, 'filterData');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sinon.spy(models.Base.Model, 'filterData');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves(fetchedModel);
const findOneReturnValue = models.Base.Model.findOne(data, unfilteredOptions);
@ -299,13 +298,13 @@ describe('Models: base', function () {
};
const model = models.Base.Model.forge({});
const savedModel = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sandbox.spy(models.Base.Model, 'filterData');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sinon.spy(models.Base.Model, 'filterData');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves(model);
const saveStub = sandbox.stub(model, 'save')
const saveStub = sinon.stub(model, 'save')
.resolves(savedModel);
return models.Base.Model.edit(data, unfilteredOptions).then((result) => {
@ -336,9 +335,9 @@ describe('Models: base', function () {
importing: true
};
const model = models.Base.Model.forge({});
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves();
return models.Base.Model.findOne(data, unfilteredOptions).then(() => {
@ -354,13 +353,13 @@ describe('Models: base', function () {
id: 'something real special',
};
const model = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sandbox.spy(models.Base.Model, 'filterData');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sinon.spy(models.Base.Model, 'filterData');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves();
const saveSpy = sandbox.stub(model, 'save');
const saveSpy = sinon.stub(model, 'save');
return models.Base.Model.edit(data, unfilteredOptions).then((result) => {
should.equal(result, undefined);
@ -377,11 +376,11 @@ describe('Models: base', function () {
const unfilteredOptions = {};
const model = models.Base.Model.forge({});
const savedModel = models.Base.Model.forge({});
const filterOptionsSpy = sandbox.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sandbox.spy(models.Base.Model, 'filterData');
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const filterOptionsSpy = sinon.spy(models.Base.Model, 'filterOptions');
const filterDataSpy = sinon.spy(models.Base.Model, 'filterData');
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const saveStub = sandbox.stub(model, 'save')
const saveStub = sinon.stub(model, 'save')
.resolves(savedModel);
return models.Base.Model.add(data, unfilteredOptions).then((result) => {
@ -410,9 +409,9 @@ describe('Models: base', function () {
importing: true
};
const model = models.Base.Model.forge({});
const forgeStub = sandbox.stub(models.Base.Model, 'forge')
const forgeStub = sinon.stub(models.Base.Model, 'forge')
.returns(model);
const saveStub = sandbox.stub(model, 'save')
const saveStub = sinon.stub(model, 'save')
.resolves();
return models.Base.Model.add(data, unfilteredOptions).then(() => {

View File

@ -2,16 +2,14 @@ var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
common = require('../../../../server/lib/common'),
Models = require('../../../../server/models'),
sandbox = sinon.sandbox.create();
Models = require('../../../../server/models');
describe('Models: listeners', function () {
var eventsToRemember = {};
const emit = (event, data) => eventsToRemember[event](data);
before(function () {
sandbox.stub(common.events, 'on').callsFake(function (name, callback) {
sinon.stub(common.events, 'on').callsFake(function (name, callback) {
eventsToRemember[name] = callback;
});
@ -20,21 +18,21 @@ describe('Models: listeners', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('on token added', function () {
it('calls updateLastSeen on the user when the token.added event is emited', function (done) {
const userId = 1;
const user = Models.User.forge({id: 1});
sandbox.stub(Models.User, 'findOne').withArgs({id: userId}).resolves(user);
const updateLastSeenSpy = sandbox.stub(user, 'updateLastSeen').callsFake(function () {
sinon.stub(Models.User, 'findOne').withArgs({id: userId}).resolves(user);
const updateLastSeenSpy = sinon.stub(user, 'updateLastSeen').callsFake(function () {
updateLastSeenSpy.calledOnce.should.be.true();
done();
});
const fakeToken = {
get: sandbox.stub().withArgs('user_id').returns(userId)
get: sinon.stub().withArgs('user_id').returns(userId)
};
emit('token.added', fakeToken);

View File

@ -4,8 +4,7 @@ const should = require('should'),
common = require('../../../server/lib/common'),
models = require('../../../server/models'),
settingsCache = require('../../../server/services/settings/cache'),
testUtils = require('../../utils'),
sandbox = sinon.sandbox.create();
testUtils = require('../../utils');
describe('Unit: models/invite', function () {
before(function () {
@ -13,11 +12,11 @@ describe('Unit: models/invite', function () {
});
beforeEach(function () {
sandbox.stub(settingsCache, 'get').withArgs('db_hash').returns('12345678');
sinon.stub(settingsCache, 'get').withArgs('db_hash').returns('12345678');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
before(testUtils.teardown);
@ -85,8 +84,8 @@ describe('Unit: models/invite', function () {
inviteModel = {};
context = {};
unsafeAttrs = {role_id: 'role_id'};
roleModel = sandbox.stub();
roleModel.get = sandbox.stub();
roleModel = sinon.stub();
roleModel.get = sinon.stub();
loadedPermissions = {
user: {
roles: []
@ -95,7 +94,7 @@ describe('Unit: models/invite', function () {
});
it('role does not exist', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(null);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(null);
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs)
.then(Promise.reject)
@ -105,7 +104,7 @@ describe('Unit: models/invite', function () {
});
it('invite owner', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Owner');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs)
@ -121,28 +120,28 @@ describe('Unit: models/invite', function () {
});
it('invite administrator', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Administrator');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite editor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Editor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite author', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Author');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite contributor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Contributor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
@ -155,28 +154,28 @@ describe('Unit: models/invite', function () {
});
it('invite administrator', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Administrator');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite editor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Editor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite author', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Author');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite contributor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Contributor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
@ -189,7 +188,7 @@ describe('Unit: models/invite', function () {
});
it('invite administrator', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Administrator');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true)
@ -200,7 +199,7 @@ describe('Unit: models/invite', function () {
});
it('invite editor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Editor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true)
@ -211,14 +210,14 @@ describe('Unit: models/invite', function () {
});
it('invite author', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Author');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
});
it('invite contributor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Contributor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, true, true, true);
@ -231,7 +230,7 @@ describe('Unit: models/invite', function () {
});
it('invite administrator', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Administrator');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -242,7 +241,7 @@ describe('Unit: models/invite', function () {
});
it('invite editor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Editor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -253,7 +252,7 @@ describe('Unit: models/invite', function () {
});
it('invite author', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Author');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -264,7 +263,7 @@ describe('Unit: models/invite', function () {
});
it('invite contributor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Contributor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -281,7 +280,7 @@ describe('Unit: models/invite', function () {
});
it('invite administrator', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Administrator');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -292,7 +291,7 @@ describe('Unit: models/invite', function () {
});
it('invite editor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Editor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -303,7 +302,7 @@ describe('Unit: models/invite', function () {
});
it('invite author', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Author');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)
@ -314,7 +313,7 @@ describe('Unit: models/invite', function () {
});
it('invite contributor', function () {
sandbox.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
sinon.stub(models.Role, 'findOne').withArgs({id: 'role_id'}).resolves(roleModel);
roleModel.get.withArgs('name').returns('Contributor');
return models.Invite.permissible(inviteModel, 'add', context, unsafeAttrs, loadedPermissions, false, false, true)

View File

@ -2,8 +2,7 @@ const should = require('should'),
sinon = require('sinon'),
models = require('../../../server/models'),
testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils'),
sandbox = sinon.sandbox.create();
configUtils = require('../../utils/configUtils');
describe('Unit: models/permission', function () {
before(function () {
@ -11,7 +10,7 @@ describe('Unit: models/permission', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
configUtils.restore();
});

View File

@ -2,14 +2,13 @@ var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
rewire = require('rewire'),
pagination = rewire('../../../../server/models/plugins/pagination'),
sandbox = sinon.sandbox.create();
pagination = rewire('../../../../server/models/plugins/pagination');
describe('pagination', function () {
var paginationUtils;
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('paginationUtils', function () {
@ -144,7 +143,7 @@ describe('pagination', function () {
});
beforeEach(function () {
collection.query = sandbox.stub().returns(collection);
collection.query = sinon.stub().returns(collection);
});
it('should add query options if limit is set', function () {
@ -172,15 +171,15 @@ describe('pagination', function () {
beforeEach(function () {
// Stub paginationUtils
paginationUtils.parseOptions = sandbox.stub();
paginationUtils.addLimitAndOffset = sandbox.stub();
paginationUtils.formatResponse = sandbox.stub().returns({});
paginationUtils.parseOptions = sinon.stub();
paginationUtils.addLimitAndOffset = sinon.stub();
paginationUtils.formatResponse = sinon.stub().returns({});
// Mock out bookshelf model
mockQuery = {
clone: sandbox.stub(),
select: sandbox.stub(),
toQuery: sandbox.stub()
clone: sinon.stub(),
select: sinon.stub(),
toQuery: sinon.stub()
};
mockQuery.clone.returns(mockQuery);
mockQuery.select.returns(Promise.resolve([{aggregate: 1}]));
@ -188,11 +187,11 @@ describe('pagination', function () {
model = function () {
};
model.prototype.fetchAll = sandbox.stub().returns(Promise.resolve({}));
model.prototype.query = sandbox.stub();
model.prototype.fetchAll = sinon.stub().returns(Promise.resolve({}));
model.prototype.query = sinon.stub();
model.prototype.query.returns(mockQuery);
knex = {raw: sandbox.stub().returns(Promise.resolve())};
knex = {raw: sinon.stub().returns(Promise.resolve())};
bookshelf = {Model: model, knex: knex};

View File

@ -10,7 +10,6 @@ const schema = require('../../../server/data/schema');
const models = require('../../../server/models');
const common = require('../../../server/lib/common');
const security = require('../../../server/lib/security');
const sandbox = sinon.sandbox.create();
describe('Unit: models/post', function () {
const mockDb = require('mock-knex');
@ -23,7 +22,7 @@ describe('Unit: models/post', function () {
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
after(function () {
@ -356,16 +355,16 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
before(testUtils.setup('users:roles', 'posts'));
beforeEach(function () {
sandbox.stub(security.password, 'hash').resolves('$2a$10$we16f8rpbrFZ34xWj0/ZC.LTPUux8ler7bcdTs5qIleN6srRHhilG');
sandbox.stub(urlService, 'getUrlByResourceId');
sinon.stub(security.password, 'hash').resolves('$2a$10$we16f8rpbrFZ34xWj0/ZC.LTPUux8ler7bcdTs5qIleN6srRHhilG');
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
after(function () {
sandbox.restore();
sinon.restore();
});
describe('add', function () {
@ -375,7 +374,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -424,7 +423,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -447,7 +446,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -481,7 +480,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -516,7 +515,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -562,7 +561,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -611,7 +610,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
testUtils.DataGenerator.forKnex.posts[4].featured.should.eql(true);
// @NOTE: simulate that the onSaving hook takes longer
sandbox.stub(models.Post.prototype, 'onSaving').callsFake(function () {
sinon.stub(models.Post.prototype, 'onSaving').callsFake(function () {
var self = this,
args = arguments;
@ -650,11 +649,11 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
tag: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push(event);
});
sandbox.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
events.tag.push(event);
});
@ -689,11 +688,11 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
tag: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push(event);
});
sandbox.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
events.tag.push(event);
});
@ -723,11 +722,11 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
tag: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push(event);
});
sandbox.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Tag.prototype, 'emitChange').callsFake(function (event) {
events.tag.push(event);
});
@ -772,7 +771,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -810,7 +809,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -851,7 +850,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -892,7 +891,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -936,7 +935,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
@ -1517,8 +1516,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Editing', function () {
it('rejects if changing status', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'published'};
@ -1547,8 +1546,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing author id', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 2};
@ -1576,8 +1575,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing authors.0', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', authors: [{id: 2}]};
@ -1605,8 +1604,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('ignores if changes authors.1', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', authors: [{id: 1}, {id: 2}]};
@ -1634,8 +1633,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if post is not draft', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'published', author_id: 1};
@ -1665,8 +1664,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if contributor is not author of post', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 2};
@ -1696,8 +1695,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if none of the above cases are true', function () {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 1};
@ -1727,7 +1726,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Adding', function () {
it('rejects if "published" status', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'published', author_id: 1};
@ -1752,7 +1751,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if different author id', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 2};
@ -1777,7 +1776,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if different logged in user and `authors.0`', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', authors: [{id: 2}]};
@ -1802,7 +1801,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if same logged in user and `authors.0`, but different author_id', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 3, authors: [{id: 1}]};
@ -1827,7 +1826,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if different logged in user and `authors.0`, but correct author_id', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 1, authors: [{id: 2}]};
@ -1852,7 +1851,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if same logged in user and `authors.0`', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', authors: [{id: 1}]};
@ -1876,7 +1875,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if none of the above cases are true', function () {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {status: 'draft', author_id: 1};
@ -1901,8 +1900,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Destroying', function () {
it('rejects if destroying another author\'s post', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1};
@ -1929,8 +1928,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if destroying a published post', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1};
@ -1958,8 +1957,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if none of the above cases are true', function () {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1};
@ -1989,8 +1988,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Editing', function () {
it('rejects if editing another\'s post', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 2};
@ -2019,8 +2018,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if editing another\'s post (using `authors`)', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {authors: [{id: 2}]};
@ -2048,8 +2047,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing author', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 2};
@ -2078,8 +2077,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing authors', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {authors: [{id: 2}]};
@ -2107,8 +2106,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing authors and author_id', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {authors: [{id: 1}], author_id: 2};
@ -2137,8 +2136,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if changing authors and author_id', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {authors: [{id: 2}], author_id: 1};
@ -2167,8 +2166,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if none of the above cases are true', function () {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 1};
@ -2195,7 +2194,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Adding', function () {
it('rejects if different author id', function (done) {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 2};
@ -2220,8 +2219,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('rejects if different authors', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {authors: [{id: 2}]};
@ -2248,7 +2247,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if none of the above cases are true', function () {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 1};
@ -2272,8 +2271,8 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
describe('Everyone Else', function () {
it('rejects if hasUserPermissions is false and not current owner', function (done) {
var mockPostObj = {
get: sandbox.stub(),
related: sandbox.stub()
get: sinon.stub(),
related: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 2};
@ -2302,7 +2301,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
it('resolves if hasUserPermission is true', function () {
var mockPostObj = {
get: sandbox.stub()
get: sinon.stub()
},
context = {user: 1},
unsafeAttrs = {author_id: 2};
@ -2335,7 +2334,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
post: []
};
sandbox.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
sinon.stub(models.Post.prototype, 'emitChange').callsFake(function (event) {
events.post.push({event: event, data: this.toJSON()});
});
});

View File

@ -2,18 +2,13 @@ const should = require('should');
const sinon = require('sinon');
const models = require('../../../server/models');
const sandbox = sinon.sandbox.create();
describe('Unit: models/session', function () {
let sandbox;
before(function () {
models.init();
sandbox = sinon.sandbox.create();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('parse', function () {
@ -65,7 +60,7 @@ describe('Unit: models/session', function () {
describe('user', function () {
it('sets up the relation to the "User" model', function () {
const model = models.Session.forge({});
const belongsToSpy = sandbox.spy(model, 'belongsTo');
const belongsToSpy = sinon.spy(model, 'belongsTo');
model.user();
should.equal(belongsToSpy.args[0][0], 'User');
@ -78,7 +73,7 @@ describe('Unit: models/session', function () {
beforeEach(function () {
basePermittedOptionsReturnVal = ['super', 'doopa'];
basePermittedOptionsStub = sandbox.stub(models.Base.Model, 'permittedOptions')
basePermittedOptionsStub = sinon.stub(models.Base.Model, 'permittedOptions')
.returns(basePermittedOptionsReturnVal);
});
@ -112,7 +107,7 @@ describe('Unit: models/session', function () {
describe('destroy', function () {
it('calls and returns the Base Model destroy if an id is passed', function () {
const baseDestroyReturnVal = {};
const baseDestroyStub = sandbox.stub(models.Base.Model, 'destroy')
const baseDestroyStub = sinon.stub(models.Base.Model, 'destroy')
.returns(baseDestroyReturnVal);
const options = {id: 1};
@ -128,13 +123,13 @@ describe('Unit: models/session', function () {
const unfilteredOptions = {session_id};
const filteredOptions = {session_id};
const filterOptionsStub = sandbox.stub(models.Session, 'filterOptions')
const filterOptionsStub = sinon.stub(models.Session, 'filterOptions')
.returns(filteredOptions);
const forgeStub = sandbox.stub(models.Session, 'forge')
const forgeStub = sinon.stub(models.Session, 'forge')
.returns(model);
const fetchStub = sandbox.stub(model, 'fetch')
const fetchStub = sinon.stub(model, 'fetch')
.resolves(model);
const destroyStub = sandbox.stub(model, 'destroy')
const destroyStub = sinon.stub(model, 'destroy')
.resolves();
models.Session.destroy(unfilteredOptions).then(() => {
@ -162,13 +157,13 @@ describe('Unit: models/session', function () {
}
};
const filterOptionsStub = sandbox.stub(models.Session, 'filterOptions')
const filterOptionsStub = sinon.stub(models.Session, 'filterOptions')
.returns(filteredOptions);
const findOneStub = sandbox.stub(models.Session, 'findOne')
const findOneStub = sinon.stub(models.Session, 'findOne')
.resolves();
const addStub = sandbox.stub(models.Session, 'add');
const addStub = sinon.stub(models.Session, 'add');
models.Session.upsert(data, unfilteredOptions).then(() => {
should.equal(filterOptionsStub.args[0][0], unfilteredOptions);
@ -201,13 +196,13 @@ describe('Unit: models/session', function () {
}
};
const filterOptionsStub = sandbox.stub(models.Session, 'filterOptions')
const filterOptionsStub = sinon.stub(models.Session, 'filterOptions')
.returns(filteredOptions);
const findOneStub = sandbox.stub(models.Session, 'findOne')
const findOneStub = sinon.stub(models.Session, 'findOne')
.resolves(model);
const editStub = sandbox.stub(models.Session, 'edit');
const editStub = sinon.stub(models.Session, 'edit');
models.Session.upsert(data, unfilteredOptions).then(() => {
should.equal(filterOptionsStub.args[0][0], unfilteredOptions);

View File

@ -5,15 +5,13 @@ const models = require('../../../server/models');
const testUtils = require('../../utils');
const {knex} = require('../../../server/data/db');
const sandbox = sinon.sandbox.create();
describe('Unit: models/tag', function () {
before(function () {
models.init();
});
afterEach(function () {
sandbox.restore();
sinon.restore();
});
describe('SQL', function () {
@ -26,7 +24,7 @@ describe('Unit: models/tag', function () {
});
after(function () {
sandbox.restore();
sinon.restore();
});
after(function () {

Some files were not shown because too many files have changed in this diff Show More