2016-02-25 10:10:36 +03:00
|
|
|
/*global describe, it, beforeEach, afterEach */
|
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
rewire = require('rewire'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
|
|
|
|
// Stuff we are testing
|
|
|
|
configUtils = require('../utils/configUtils'),
|
|
|
|
models = require('../../server/models'),
|
|
|
|
notifications = require('../../server/api/notifications'),
|
2016-03-14 20:39:00 +03:00
|
|
|
versioning = require('../../server/data/schema/versioning'),
|
2016-02-25 10:10:36 +03:00
|
|
|
update = rewire('../../server/data/migration/fixtures/update'),
|
|
|
|
populate = rewire('../../server/data/migration/fixtures/populate'),
|
|
|
|
fixtures004 = require('../../server/data/migration/fixtures/004'),
|
2016-03-22 21:02:00 +03:00
|
|
|
fixtures005 = require('../../server/data/migration/fixtures/005'),
|
2016-03-13 23:49:30 +03:00
|
|
|
ensureDefaultSettings = require('../../server/data/migration/fixtures/settings'),
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
describe('Fixtures', function () {
|
2016-03-21 15:44:23 +03:00
|
|
|
var loggerStub;
|
|
|
|
|
2016-03-02 07:42:01 +03:00
|
|
|
beforeEach(function () {
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub = {
|
|
|
|
info: sandbox.stub(),
|
|
|
|
warn: sandbox.stub()
|
|
|
|
};
|
|
|
|
|
2016-03-02 07:42:01 +03:00
|
|
|
models.init();
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Update fixtures', function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
it('should call `getUpdateFixturesTasks` when upgrading from 003 -> 004', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
var getVersionTasksStub = sandbox.stub(versioning, 'getUpdateFixturesTasks').returns([]);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
update(['004'], loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-02-25 10:10:36 +03:00
|
|
|
getVersionTasksStub.calledOnce.should.be.true();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('should NOT call `getUpdateFixturesTasks` when upgrading from 004 -> 004', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
var getVersionTasksStub = sandbox.stub(versioning, 'getUpdateFixturesTasks').returns([]);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
update([], loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-02-25 10:10:36 +03:00
|
|
|
getVersionTasksStub.calledOnce.should.be.false();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('should call tasks in correct order if provided', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
var task1Stub = sandbox.stub().returns(Promise.resolve()),
|
2016-03-14 20:39:00 +03:00
|
|
|
task2Stub = sandbox.stub().returns(Promise.resolve()),
|
|
|
|
getVersionTasksStub = sandbox.stub(versioning, 'getUpdateFixturesTasks').returns([task1Stub, task2Stub]);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
update(['000'], loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledTwice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-14 20:39:00 +03:00
|
|
|
getVersionTasksStub.calledOnce.should.be.true();
|
|
|
|
task1Stub.calledOnce.should.be.true();
|
|
|
|
task2Stub.calledOnce.should.be.true();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Update to 004', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
it('should call all the 004 fixture upgrade tasks', function (done) {
|
|
|
|
// Setup
|
|
|
|
// Create a new stub, this will replace sequence, so that db calls don't actually get run
|
|
|
|
var sequenceStub = sandbox.stub(),
|
|
|
|
sequenceReset = update.__set__('sequence', sequenceStub);
|
|
|
|
|
|
|
|
// The first time we call sequence, it should be to execute a top level version, e.g 004
|
|
|
|
// yieldsTo('0') means this stub will execute the function at index 0 of the array passed as the
|
|
|
|
// first argument. In short the `runVersionTasks` function gets executed, and sequence gets called
|
|
|
|
// again with the array of tasks to execute for 004, which is what we want to check
|
|
|
|
sequenceStub.onFirstCall().yieldsTo('0').returns(Promise.resolve([]));
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
update(['004'], loggerStub).then(function (result) {
|
2016-02-25 10:10:36 +03:00
|
|
|
should.exist(result);
|
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
loggerStub.info.calledTwice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
|
|
|
|
sequenceStub.calledTwice.should.be.true();
|
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
sequenceStub.firstCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
sequenceStub.firstCall.args[0].should.be.an.Array().with.lengthOf(1);
|
|
|
|
sequenceStub.firstCall.args[0][0].should.be.a.Function().with.property('name', 'runVersionTasks');
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
sequenceStub.secondCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
|
|
|
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(8);
|
2016-03-23 18:02:40 +03:00
|
|
|
sequenceStub.secondCall.args[0][0].should.be.a.Function().with.property('name', 'moveJQuery');
|
|
|
|
sequenceStub.secondCall.args[0][1].should.be.a.Function().with.property('name', 'updatePrivateSetting');
|
|
|
|
sequenceStub.secondCall.args[0][2].should.be.a.Function().with.property('name', 'updatePasswordSetting');
|
|
|
|
sequenceStub.secondCall.args[0][3].should.be.a.Function().with.property('name', 'updateGhostAdminClient');
|
|
|
|
sequenceStub.secondCall.args[0][4].should.be.a.Function().with.property('name', 'addGhostFrontendClient');
|
|
|
|
sequenceStub.secondCall.args[0][5].should.be.a.Function().with.property('name', 'cleanBrokenTags');
|
|
|
|
sequenceStub.secondCall.args[0][6].should.be.a.Function().with.property('name', 'addPostTagOrder');
|
|
|
|
sequenceStub.secondCall.args[0][7].should.be.a.Function().with.property('name', 'addNewPostFixture');
|
|
|
|
|
|
|
|
// Reset
|
|
|
|
sequenceReset();
|
2016-02-25 10:10:36 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('Tasks:', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
var getObjStub, settingsOneStub, settingsEditStub, clientOneStub, clientEditStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
getObjStub = {get: sandbox.stub()};
|
|
|
|
settingsOneStub = sandbox.stub(models.Settings, 'findOne').returns(Promise.resolve(getObjStub));
|
|
|
|
settingsEditStub = sandbox.stub(models.Settings, 'edit').returns(Promise.resolve());
|
|
|
|
clientOneStub = sandbox.stub(models.Client, 'findOne').returns(Promise.resolve(getObjStub));
|
|
|
|
clientEditStub = sandbox.stub(models.Client, 'edit').returns(Promise.resolve());
|
|
|
|
});
|
|
|
|
|
2016-03-22 21:02:00 +03:00
|
|
|
it('should have tasks for 004', function () {
|
|
|
|
should.exist(fixtures004);
|
|
|
|
fixtures004.should.be.an.Array().with.lengthOf(8);
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('01-move-jquery-with-alert', function () {
|
|
|
|
it('tries to move jQuery to ghost_foot', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.returns('');
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[0]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('ghost_foot').should.be.true();
|
|
|
|
settingsEditStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
done();
|
2016-03-21 15:44:23 +03:00
|
|
|
}).catch(done);
|
2016-03-14 20:39:00 +03:00
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('does not move jQuery to ghost_foot if it is already there', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.returns(
|
|
|
|
'<!-- You can safely delete this line if your theme does not require jQuery -->\n'
|
|
|
|
+ '<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>\n\n'
|
|
|
|
);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[0]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('ghost_foot').should.be.true();
|
|
|
|
settingsEditStub.calledOnce.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
it('does not move jQuery to ghost_foot if the setting is missing', function (done) {
|
|
|
|
settingsOneStub.returns(Promise.resolve());
|
|
|
|
|
|
|
|
fixtures004[0]({}, loggerStub).then(function () {
|
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('ghost_foot').should.be.true();
|
|
|
|
settingsEditStub.called.should.be.false();
|
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('tried to move jQuery AND add a privacy message if any privacy settings are on', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
var notificationsAddStub = sandbox.stub(notifications, 'add').returns(Promise.resolve());
|
2016-03-14 20:39:00 +03:00
|
|
|
configUtils.set({privacy: {useGoogleFonts: false}});
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.returns('');
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[0]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('ghost_foot').should.be.true();
|
|
|
|
settingsEditStub.calledOnce.should.be.true();
|
|
|
|
notificationsAddStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledTwice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('02-update-private-setting-type', function () {
|
|
|
|
it('tries to update setting type correctly', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[1]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('isPrivate').should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledOnce.should.be.true();
|
|
|
|
getObjStub.get.calledWith('type').should.be.true();
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsEditStub.calledOnce.should.be.true();
|
|
|
|
settingsEditStub.calledWith({key: 'isPrivate', type: 'private'}).should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-23 18:02:40 +03:00
|
|
|
sinon.assert.callOrder(settingsOneStub, getObjStub.get, loggerStub.info, settingsEditStub);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not try to update setting type if it is already set', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.returns('private');
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[1]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('isPrivate').should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledOnce.should.be.true();
|
|
|
|
getObjStub.get.calledWith('type').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
settingsEditStub.called.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
sinon.assert.callOrder(settingsOneStub, getObjStub.get, loggerStub.warn);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('03-update-password-setting-type', function () {
|
|
|
|
it('tries to update setting type correctly', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[2]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('password').should.be.true();
|
|
|
|
settingsEditStub.calledOnce.should.be.true();
|
|
|
|
settingsEditStub.calledWith({key: 'password', type: 'private'}).should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
sinon.assert.callOrder(settingsOneStub, loggerStub.info, settingsEditStub);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
it('does not try to update setting type if it is already set', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.returns('private');
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[2]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
settingsOneStub.calledOnce.should.be.true();
|
|
|
|
settingsOneStub.calledWith('password').should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledOnce.should.be.true();
|
|
|
|
getObjStub.get.calledWith('type').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
settingsEditStub.called.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
sinon.assert.callOrder(settingsOneStub, getObjStub.get);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('04-update-ghost-admin-client', function () {
|
|
|
|
it('tries to update client correctly', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[3]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-admin'}).should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledTwice.should.be.true();
|
|
|
|
getObjStub.get.calledWith('secret').should.be.true();
|
|
|
|
getObjStub.get.calledWith('status').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
clientEditStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
sinon.assert.callOrder(
|
2016-03-23 18:02:40 +03:00
|
|
|
clientOneStub, getObjStub.get, getObjStub.get, loggerStub.info, clientEditStub
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not try to update client if the secret and status are already correct', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.withArgs('secret').returns('abc');
|
|
|
|
getObjStub.get.withArgs('status').returns('enabled');
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[3]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-admin'}).should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledTwice.should.be.true();
|
|
|
|
getObjStub.get.calledWith('secret').should.be.true();
|
|
|
|
getObjStub.get.calledWith('status').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
clientEditStub.called.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
sinon.assert.callOrder(clientOneStub, getObjStub.get, getObjStub.get, loggerStub.warn);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tries to update client if secret is correct but status is wrong', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.withArgs('secret').returns('abc');
|
|
|
|
getObjStub.get.withArgs('status').returns('development');
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[3]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-admin'}).should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledTwice.should.be.true();
|
|
|
|
getObjStub.get.calledWith('secret').should.be.true();
|
|
|
|
getObjStub.get.calledWith('status').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
clientEditStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
sinon.assert.callOrder(
|
2016-03-23 18:02:40 +03:00
|
|
|
clientOneStub, getObjStub.get, getObjStub.get, loggerStub.info, clientEditStub
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tries to update client if status is correct but secret is wrong', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.withArgs('secret').returns('not_available');
|
|
|
|
getObjStub.get.withArgs('status').returns('enabled');
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[3]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-admin'}).should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
getObjStub.get.calledOnce.should.be.true();
|
|
|
|
getObjStub.get.calledWith('secret').should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
clientEditStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
sinon.assert.callOrder(
|
2016-03-23 18:02:40 +03:00
|
|
|
clientOneStub, getObjStub.get, loggerStub.info, clientEditStub
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('05-add-ghost-frontend-client', function () {
|
|
|
|
it('tries to add client correctly', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
var clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve());
|
|
|
|
clientOneStub.returns(Promise.resolve());
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[4]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-frontend'}).should.be.true();
|
|
|
|
clientAddStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
sinon.assert.callOrder(clientOneStub, loggerStub.info, clientAddStub);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
it('does not try to add client if it already exists', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
var clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve());
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[4]({}, loggerStub).then(function () {
|
2016-03-21 20:53:36 +03:00
|
|
|
clientOneStub.calledOnce.should.be.true();
|
|
|
|
clientOneStub.calledWith({slug: 'ghost-frontend'}).should.be.true();
|
|
|
|
clientAddStub.called.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('06-clean-broken-tags', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
var tagObjStub, tagCollStub, tagAllStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
tagObjStub = {
|
|
|
|
get: sandbox.stub(),
|
|
|
|
save: sandbox.stub().returns(Promise.resolve)
|
|
|
|
};
|
|
|
|
tagCollStub = {each: sandbox.stub().callsArgWith(0, tagObjStub)};
|
|
|
|
tagAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(tagCollStub));
|
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('tries to clean broken tags correctly', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
tagObjStub.get.returns(',hello');
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[5]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
tagAllStub.calledOnce.should.be.true();
|
|
|
|
tagCollStub.each.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledWith('name').should.be.true();
|
|
|
|
tagObjStub.save.calledOnce.should.be.true();
|
|
|
|
tagObjStub.save.calledWith({name: 'hello'}).should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
sinon.assert.callOrder(tagAllStub, tagCollStub.each, tagObjStub.get, tagObjStub.save, loggerStub.info);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
it('tries can handle tags which end up empty', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
tagObjStub.get.returns(',');
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[5]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
tagAllStub.calledOnce.should.be.true();
|
|
|
|
tagCollStub.each.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledWith('name').should.be.true();
|
|
|
|
tagObjStub.save.calledOnce.should.be.true();
|
|
|
|
tagObjStub.save.calledWith({name: 'tag'}).should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
sinon.assert.callOrder(tagAllStub, tagCollStub.each, tagObjStub.get, tagObjStub.save, loggerStub.info);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 20:53:36 +03:00
|
|
|
it('does not change tags if not necessary', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
tagObjStub.get.returns('hello');
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[5]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
tagAllStub.calledOnce.should.be.true();
|
|
|
|
tagCollStub.each.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledOnce.should.be.true();
|
|
|
|
tagObjStub.get.calledWith('name').should.be.true();
|
|
|
|
tagObjStub.save.called.should.be.false();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
sinon.assert.callOrder(tagAllStub, tagCollStub.each, tagObjStub.get, loggerStub.warn);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does nothing if there are no tags', function (done) {
|
|
|
|
tagAllStub.returns(Promise.resolve());
|
|
|
|
|
|
|
|
fixtures004[5]({}, loggerStub).then(function () {
|
|
|
|
tagAllStub.calledOnce.should.be.true();
|
|
|
|
tagCollStub.each.called.should.be.false();
|
|
|
|
tagObjStub.get.called.should.be.false();
|
|
|
|
tagObjStub.save.called.should.be.false();
|
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
|
|
|
sinon.assert.callOrder(tagAllStub, loggerStub.warn);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('07-add-post-tag-order', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
var tagOp1Stub, tagOp2Stub, tagObjStub, postObjStub, postCollStub, postAllStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
tagOp1Stub = sandbox.stub().returns(Promise.resolve());
|
|
|
|
tagOp2Stub = sandbox.stub().returns(Promise.resolve());
|
|
|
|
tagObjStub = {
|
|
|
|
pivot: {get: sandbox.stub()}
|
|
|
|
};
|
|
|
|
postCollStub = {mapThen: sandbox.stub()};
|
|
|
|
postAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(postCollStub));
|
|
|
|
|
|
|
|
postObjStub = {
|
|
|
|
load: sandbox.stub(),
|
|
|
|
reduce: sandbox.stub(),
|
|
|
|
// By returning an array from related, we can use native reduce to simulate a result
|
|
|
|
related: sandbox.stub().returns([tagObjStub]),
|
|
|
|
// Get called when executing sequence
|
|
|
|
tags: sandbox.stub().returnsThis(),
|
|
|
|
updatePivot: sandbox.stub().returns(Promise.resolve())
|
|
|
|
};
|
|
|
|
});
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
it('calls load on each post', function (done) {
|
|
|
|
// Fake mapThen behaviour
|
|
|
|
postCollStub.mapThen.callsArgWith(0, postObjStub).returns([]);
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
|
|
|
postObjStub.load.calledOnce.should.be.true();
|
|
|
|
postObjStub.load.calledWith(['tags']).should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
// gets called because we're stubbing to return an empty array
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
|
|
|
sinon.assert.callOrder(loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.load);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-03-21 20:53:36 +03:00
|
|
|
it('returns early, if no posts are found', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
// Fake mapThen behaviour
|
|
|
|
postCollStub.mapThen.returns([]);
|
|
|
|
postAllStub.returns(Promise.resolve());
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
sinon.assert.callOrder(loggerStub.info, postAllStub, loggerStub.warn);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('executes sequence, if at least one tag is found', function (done) {
|
|
|
|
var tagOpStub = sandbox.stub().returns(Promise.resolve()),
|
2016-03-23 18:02:40 +03:00
|
|
|
tagOpsArr = [tagOpStub];
|
|
|
|
|
|
|
|
// By stubbing reduce, we can return an array directly without pretending to process tags
|
|
|
|
postObjStub.reduce.returns(tagOpsArr);
|
|
|
|
// By returning from mapThen, we can skip doing tag.load in this test
|
|
|
|
postCollStub.mapThen.returns(postObjStub);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledThrice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
postObjStub.reduce.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
tagOpStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
sinon.assert.callOrder(
|
2016-03-23 18:02:40 +03:00
|
|
|
loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.reduce,
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info, tagOpStub, loggerStub.info
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('executes sequence, if more than one tag is found', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
var tagOpsArr = [tagOp1Stub, tagOp2Stub];
|
|
|
|
// By stubbing reduce, we can return an array directly without pretending to process tags
|
|
|
|
postObjStub.reduce.returns(tagOpsArr);
|
|
|
|
// By returning from mapThen, we can skip doing tag.load in this test
|
|
|
|
postCollStub.mapThen.returns(postObjStub);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledThrice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
2016-03-23 18:02:40 +03:00
|
|
|
postObjStub.reduce.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
tagOp1Stub.calledOnce.should.be.true();
|
|
|
|
tagOp2Stub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
sinon.assert.callOrder(
|
2016-03-23 18:02:40 +03:00
|
|
|
loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.reduce,
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info, tagOp1Stub, tagOp2Stub, loggerStub.info
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not execute sequence, if migrationHasRunFlag gets set to true', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
tagObjStub.pivot.get.returns(1);
|
|
|
|
// By returning from mapThen, we can skip doing tag.load in this test
|
|
|
|
postCollStub.mapThen.returns([postObjStub]);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
|
|
|
postObjStub.related.calledOnce.should.be.true();
|
|
|
|
tagObjStub.pivot.get.calledOnce.should.be.true();
|
|
|
|
tagObjStub.pivot.get.calledWith('sort_order').should.be.true();
|
|
|
|
sinon.assert.callOrder(
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.related,
|
|
|
|
tagObjStub.pivot.get, loggerStub.warn
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does execute sequence, if migrationHasRunFlag is false', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
// If pivot gets a non-zero, migrationHasRunFlag gets set to true
|
|
|
|
tagObjStub.pivot.get.returns(0);
|
|
|
|
// By returning from mapThen, we can skip doing tag.load in this test
|
|
|
|
postCollStub.mapThen.returns([postObjStub]);
|
2016-03-14 20:39:00 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledThrice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-14 20:39:00 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
|
|
|
postObjStub.related.calledOnce.should.be.true();
|
2016-03-21 20:53:36 +03:00
|
|
|
tagObjStub.pivot.get.calledOnce.should.be.true();
|
|
|
|
tagObjStub.pivot.get.calledWith('sort_order').should.be.true();
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
postObjStub.tags.calledOnce.should.be.true();
|
|
|
|
postObjStub.updatePivot.calledOnce.should.be.true();
|
|
|
|
sinon.assert.callOrder(
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.related, tagObjStub.pivot.get,
|
|
|
|
loggerStub.info, postObjStub.tags, postObjStub.updatePivot, loggerStub.info
|
2016-03-14 20:39:00 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-21 20:53:36 +03:00
|
|
|
|
|
|
|
it('tries to add incremental sort_order to posts_tags', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
// If pivot gets a non-zero, migrationHasRunFlag gets set to true
|
|
|
|
tagObjStub.pivot.get.returns(0);
|
|
|
|
// By returning an array from related, we can use real reduce to simulate a result here
|
|
|
|
postObjStub.related.returns([tagObjStub, tagObjStub, tagObjStub]);
|
2016-03-21 20:53:36 +03:00
|
|
|
// By returning from mapThen, we can skip doing tag.load in this test
|
2016-03-23 18:02:40 +03:00
|
|
|
postCollStub.mapThen.returns([postObjStub]);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[6]({}, loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledThrice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
postAllStub.calledOnce.should.be.true();
|
|
|
|
postCollStub.mapThen.calledOnce.should.be.true();
|
|
|
|
postObjStub.related.calledOnce.should.be.true();
|
|
|
|
tagObjStub.pivot.get.calledThrice.should.be.true();
|
|
|
|
|
|
|
|
postObjStub.tags.calledThrice.should.be.true();
|
|
|
|
postObjStub.updatePivot.calledThrice.should.be.true();
|
|
|
|
|
|
|
|
postObjStub.updatePivot.firstCall.args[0].should.eql({sort_order: 0});
|
|
|
|
postObjStub.updatePivot.secondCall.args[0].should.eql({sort_order: 1});
|
|
|
|
postObjStub.updatePivot.thirdCall.args[0].should.eql({sort_order: 2});
|
|
|
|
|
|
|
|
sinon.assert.callOrder(
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info, postAllStub, postCollStub.mapThen, postObjStub.related,
|
2016-03-21 20:53:36 +03:00
|
|
|
tagObjStub.pivot.get, tagObjStub.pivot.get, tagObjStub.pivot.get,
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info,
|
2016-03-21 20:53:36 +03:00
|
|
|
postObjStub.tags, postObjStub.updatePivot,
|
|
|
|
postObjStub.tags, postObjStub.updatePivot,
|
|
|
|
postObjStub.tags, postObjStub.updatePivot,
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info
|
2016-03-21 20:53:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
describe('08-add-post-fixture', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
var postOneStub, postAddStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve());
|
|
|
|
postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve());
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-23 18:02:40 +03:00
|
|
|
it('tries to add a new post fixture correctly', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
fixtures004[7]({}, loggerStub).then(function () {
|
2016-03-14 20:39:00 +03:00
|
|
|
postOneStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-03-14 20:39:00 +03:00
|
|
|
postAddStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
sinon.assert.callOrder(postOneStub, loggerStub.info, postAddStub);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
it('does not try to add new post fixture if it already exists', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
postOneStub.returns(Promise.resolve({}));
|
2016-03-21 15:44:23 +03:00
|
|
|
|
|
|
|
fixtures004[7]({}, loggerStub).then(function () {
|
|
|
|
postOneStub.calledOnce.should.be.true();
|
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
|
|
|
postAddStub.called.should.be.false();
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
sinon.assert.callOrder(postOneStub, loggerStub.warn);
|
2016-03-21 20:53:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-21 20:53:36 +03:00
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
});
|
2016-03-22 21:02:00 +03:00
|
|
|
|
|
|
|
describe('Update to 005', function () {
|
|
|
|
it('should call all the 005 fixture upgrades', function (done) {
|
|
|
|
// Setup
|
|
|
|
// Create a new stub, this will replace sequence, so that db calls don't actually get run
|
|
|
|
var sequenceStub = sandbox.stub(),
|
|
|
|
sequenceReset = update.__set__('sequence', sequenceStub);
|
|
|
|
|
|
|
|
// The first time we call sequence, it should be to execute a top level version, e.g 005
|
|
|
|
// yieldsTo('0') means this stub will execute the function at index 0 of the array passed as the
|
|
|
|
// first argument. In short the `runVersionTasks` function gets executed, and sequence gets called
|
|
|
|
// again with the array of tasks to execute for 005, which is what we want to check
|
2016-03-22 21:27:48 +03:00
|
|
|
sequenceStub.onFirstCall().yieldsTo('0').returns(Promise.resolve([]));
|
2016-03-22 21:02:00 +03:00
|
|
|
|
|
|
|
update(['005'], loggerStub).then(function (result) {
|
|
|
|
should.exist(result);
|
|
|
|
|
2016-03-22 21:27:48 +03:00
|
|
|
loggerStub.info.calledTwice.should.be.true();
|
2016-03-22 21:02:00 +03:00
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
|
2016-03-22 21:27:48 +03:00
|
|
|
sequenceStub.calledTwice.should.be.true();
|
2016-03-22 21:02:00 +03:00
|
|
|
|
|
|
|
sequenceStub.firstCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
2016-03-22 21:27:48 +03:00
|
|
|
sequenceStub.firstCall.args[0].should.be.an.Array().with.lengthOf(1);
|
|
|
|
sequenceStub.firstCall.args[0][0].should.be.a.Function().with.property('name', 'runVersionTasks');
|
|
|
|
|
|
|
|
sequenceStub.secondCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
|
|
|
|
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(1);
|
|
|
|
sequenceStub.secondCall.args[0][0].should.be.a.Function().with.property('name', 'updateGhostClientsSecrets');
|
2016-03-22 21:02:00 +03:00
|
|
|
|
|
|
|
// Reset
|
|
|
|
sequenceReset();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Tasks:', function () {
|
|
|
|
it('should have tasks for 005', function () {
|
|
|
|
should.exist(fixtures005);
|
2016-03-22 21:27:48 +03:00
|
|
|
fixtures005.should.be.an.Array().with.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('01-update-ghost-client-secrets', function () {
|
|
|
|
var queryStub, clientForgeStub, clientEditStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
queryStub = {
|
|
|
|
query: sandbox.stub().returnsThis(),
|
|
|
|
fetch: sandbox.stub()
|
|
|
|
};
|
|
|
|
|
|
|
|
clientForgeStub = sandbox.stub(models.Clients, 'forge').returns(queryStub);
|
|
|
|
clientEditStub = sandbox.stub(models.Client, 'edit');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should do nothing if there are no incorrect secrets', function (done) {
|
|
|
|
// Setup
|
|
|
|
queryStub.fetch.returns(new Promise.resolve({models: []}));
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
fixtures005[0]({}, loggerStub).then(function () {
|
|
|
|
clientForgeStub.calledOnce.should.be.true();
|
|
|
|
clientEditStub.called.should.be.false();
|
|
|
|
loggerStub.info.called.should.be.false();
|
|
|
|
loggerStub.warn.calledOnce.should.be.true();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should try to fix any incorrect secrets', function (done) {
|
|
|
|
// Setup
|
|
|
|
queryStub.fetch.returns(new Promise.resolve({models: [{id: 1}]}));
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
fixtures005[0]({}, loggerStub).then(function () {
|
|
|
|
clientForgeStub.calledOnce.should.be.true();
|
|
|
|
clientEditStub.called.should.be.true();
|
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-03-22 21:02:00 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Populate fixtures', function () {
|
|
|
|
// This tests that all the models & relations get called correctly
|
|
|
|
it('should call all the fixture populations', function (done) {
|
|
|
|
// Stub all the model methods so that nothing happens
|
2016-03-21 15:44:23 +03:00
|
|
|
var postAddStub = sandbox.stub(models.Post, 'add').returns(Promise.resolve()),
|
2016-02-25 10:10:36 +03:00
|
|
|
tagAddStub = sandbox.stub(models.Tag, 'add').returns(Promise.resolve()),
|
|
|
|
roleAddStub = sandbox.stub(models.Role, 'add').returns(Promise.resolve()),
|
|
|
|
clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve()),
|
|
|
|
permsAddStub = sandbox.stub(models.Permission, 'add').returns(Promise.resolve()),
|
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
// Existence checks
|
|
|
|
postOneStub = sandbox.stub(models.Post, 'findOne').returns(Promise.resolve()),
|
|
|
|
tagOneStub = sandbox.stub(models.Tag, 'findOne').returns(Promise.resolve()),
|
|
|
|
roleOneStub = sandbox.stub(models.Role, 'findOne').returns(Promise.resolve()),
|
|
|
|
clientOneStub = sandbox.stub(models.Client, 'findOne').returns(Promise.resolve()),
|
|
|
|
permOneStub = sandbox.stub(models.Permission, 'findOne').returns(Promise.resolve()),
|
|
|
|
|
2016-02-25 10:10:36 +03:00
|
|
|
// Relations
|
2016-04-08 12:09:26 +03:00
|
|
|
fromItem = {
|
|
|
|
related: sandbox.stub().returnsThis(),
|
|
|
|
findWhere: sandbox.stub().returns({})
|
|
|
|
},
|
|
|
|
toItem = [{get: sandbox.stub()}],
|
|
|
|
modelMethodStub = {filter: sandbox.stub().returns(toItem), find: sandbox.stub().returns(fromItem)},
|
2016-02-25 10:10:36 +03:00
|
|
|
permsAllStub = sandbox.stub(models.Permission, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
|
|
|
rolesAllStub = sandbox.stub(models.Role, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
|
|
|
postsAllStub = sandbox.stub(models.Post, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
|
|
|
tagsAllStub = sandbox.stub(models.Tag, 'findAll').returns(Promise.resolve(modelMethodStub)),
|
|
|
|
|
|
|
|
// Create Owner
|
|
|
|
userAddStub = sandbox.stub(models.User, 'add').returns(Promise.resolve({}));
|
2016-04-08 12:09:26 +03:00
|
|
|
roleOneStub.onCall(4).returns(Promise.resolve({id: 1}));
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
populate(loggerStub).then(function () {
|
|
|
|
loggerStub.info.calledTwice.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
postOneStub.calledOnce.should.be.true();
|
2016-02-25 10:10:36 +03:00
|
|
|
postAddStub.calledOnce.should.be.true();
|
2016-04-08 12:09:26 +03:00
|
|
|
tagOneStub.calledOnce.should.be.true();
|
2016-02-25 10:10:36 +03:00
|
|
|
tagAddStub.calledOnce.should.be.true();
|
2016-04-08 12:09:26 +03:00
|
|
|
roleOneStub.callCount.should.be.aboveOrEqual(4);
|
2016-02-25 10:10:36 +03:00
|
|
|
roleAddStub.callCount.should.eql(4);
|
2016-04-08 12:09:26 +03:00
|
|
|
clientOneStub.calledTwice.should.be.true();
|
2016-02-25 10:10:36 +03:00
|
|
|
clientAddStub.calledTwice.should.be.true();
|
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
permOneStub.callCount.should.eql(30);
|
2016-02-25 10:10:36 +03:00
|
|
|
permsAddStub.called.should.be.true();
|
|
|
|
permsAddStub.callCount.should.eql(30);
|
|
|
|
|
|
|
|
permsAllStub.calledOnce.should.be.true();
|
|
|
|
rolesAllStub.calledOnce.should.be.true();
|
|
|
|
postsAllStub.calledOnce.should.be.true();
|
|
|
|
tagsAllStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
// Relations
|
|
|
|
modelMethodStub.filter.called.should.be.true();
|
|
|
|
// 22 permissions, 1 tag
|
|
|
|
modelMethodStub.filter.callCount.should.eql(22 + 1);
|
|
|
|
modelMethodStub.find.called.should.be.true();
|
|
|
|
// 3 roles, 1 post
|
|
|
|
modelMethodStub.find.callCount.should.eql(3 + 1);
|
|
|
|
|
|
|
|
// Create Owner
|
2016-04-08 12:09:26 +03:00
|
|
|
roleOneStub.callCount.should.eql(5);
|
2016-02-25 10:10:36 +03:00
|
|
|
userAddStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Create Owner', function () {
|
2016-03-23 18:02:40 +03:00
|
|
|
var createOwner = populate.__get__('createOwner'),
|
|
|
|
roleOneStub, userAddStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
roleOneStub = sandbox.stub(models.Role, 'findOne');
|
|
|
|
userAddStub = sandbox.stub(models.User, 'add');
|
|
|
|
});
|
|
|
|
|
2016-02-25 10:10:36 +03:00
|
|
|
it('createOwner will add user if owner role is present', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
roleOneStub.returns(Promise.resolve({id: 1}));
|
|
|
|
userAddStub.returns(Promise.resolve({}));
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
createOwner(loggerStub).then(function () {
|
|
|
|
loggerStub.info.called.should.be.true();
|
|
|
|
loggerStub.warn.called.should.be.false();
|
2016-02-25 10:10:36 +03:00
|
|
|
roleOneStub.calledOnce.should.be.true();
|
|
|
|
userAddStub.called.should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('createOwner does not add user if owner role is not present', function (done) {
|
2016-03-23 18:02:40 +03:00
|
|
|
roleOneStub.returns(Promise.resolve());
|
|
|
|
userAddStub.returns(Promise.resolve({}));
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
createOwner().then(function () {
|
|
|
|
roleOneStub.calledOnce.should.be.true();
|
|
|
|
userAddStub.called.should.be.false();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-13 23:49:30 +03:00
|
|
|
|
|
|
|
describe('Ensure default settings', function () {
|
|
|
|
it('should call populate settings and provide messaging', function (done) {
|
2016-03-21 15:44:23 +03:00
|
|
|
var settingsStub = sandbox.stub(models.Settings, 'populateDefaults').returns(new Promise.resolve());
|
2016-03-13 23:49:30 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
ensureDefaultSettings(loggerStub).then(function () {
|
2016-03-13 23:49:30 +03:00
|
|
|
settingsStub.calledOnce.should.be.true();
|
2016-03-21 15:44:23 +03:00
|
|
|
loggerStub.info.calledOnce.should.be.true();
|
2016-03-13 23:49:30 +03:00
|
|
|
|
|
|
|
done();
|
2016-03-21 15:44:23 +03:00
|
|
|
}).catch(done);
|
2016-03-13 23:49:30 +03:00
|
|
|
});
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|