mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
869a35c97d
* 🎨 move heart of fixtures to schema folder and change user model - add fixtures.json to schema folder - add fixture utils to schema folder - keep all the logic! --> FIXTURE.JSON - add owner user with roles --> USER MODEL - add password as default - findAll: allow querying inactive users when internal context (defaultFilters) - findOne: do not remove values from original object! - add: do not remove values from original object! * 🔥 remove migrations key from default_settings.json - this was a temporary invention for an older migration script - sephiroth keep alls needed information in a migration collection * 🔥 add code property to errors - add code property to errors - IMPORTANT: please share your opinion about that - this is a copy paste behaviour of how node is doing that (errno, code etc.) - so code specifies a GhostError * 🎨 change error handling in versioning - no need to throw specific database errors anymore (this was just a temporary solution) - now: we are throwing real DatabaseVersionErrors - specified by a code - background: the versioning unit has not idea about seeding and population of the database - it just throws what it knows --> database version does not exist or settings table does not exist * 🎨 sephiroth optimisations - added getPath function to get the path to init scripts and migration scripts - migrationPath is still hardcoded (see TODO) - tidy up database naming to transacting * ✨ migration init scripts are now complete - 1. add tables - 2. add fixtures - 3. add default settings * 🎨 important: make bootup script smaller! - remove all TODO'S except of one - no seeding logic in bootup script anymore 🕵🏻 * ✨ sephiroth: allow params for init command - param: skip (do not run this script) - param: only (only run this script) - very simple way * 🎨 adapt tests and test env - do not use migrate.populate anymore - use sephiroth instead - jscs/jshint * 🎨 fix User model status checks
131 lines
5.6 KiB
JavaScript
131 lines
5.6 KiB
JavaScript
/*jshint unused:false*/
|
|
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
Promise = require('bluebird'),
|
|
rewire = require('rewire'),
|
|
config = require('../../server/config'),
|
|
versioning = require(config.get('paths').corePath + '/server/data/schema/versioning'),
|
|
migration = require(config.get('paths').corePath + '/server/data/migration'),
|
|
models = require(config.get('paths').corePath + '/server/models'),
|
|
errors = require(config.get('paths').corePath + '/server/errors'),
|
|
permissions = require(config.get('paths').corePath + '/server/permissions'),
|
|
api = require(config.get('paths').corePath + '/server/api'),
|
|
Sephiroth = require(config.get('paths').corePath + '/server/data/sephiroth'),
|
|
apps = require(config.get('paths').corePath + '/server/apps'),
|
|
i18n = require(config.get('paths').corePath + '/server/i18n'),
|
|
xmlrpc = require(config.get('paths').corePath + '/server/data/xml/xmlrpc'),
|
|
slack = require(config.get('paths').corePath + '/server/data/slack'),
|
|
scheduling = require(config.get('paths').corePath + '/server/scheduling'),
|
|
bootstrap = rewire(config.get('paths').corePath + '/server'),
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('server bootstrap', function () {
|
|
var middlewareStub, resetMiddlewareStub, initDbHashAndFirstRunStub, resetInitDbHashAndFirstRunStub,
|
|
populateStub;
|
|
|
|
before(function () {
|
|
models.init();
|
|
});
|
|
|
|
beforeEach(function () {
|
|
middlewareStub = sandbox.stub();
|
|
initDbHashAndFirstRunStub = sandbox.stub();
|
|
|
|
populateStub = sandbox.stub(migration, 'populate').returns(Promise.resolve());
|
|
sandbox.stub(models.Settings, 'populateDefaults').returns(Promise.resolve());
|
|
sandbox.stub(permissions, 'init').returns(Promise.resolve());
|
|
sandbox.stub(api, 'init').returns(Promise.resolve());
|
|
sandbox.stub(apps, 'init').returns(Promise.resolve());
|
|
sandbox.stub(slack, 'listen').returns(Promise.resolve());
|
|
sandbox.stub(xmlrpc, 'listen').returns(Promise.resolve());
|
|
sandbox.stub(scheduling, 'init').returns(Promise.resolve());
|
|
|
|
resetMiddlewareStub = bootstrap.__set__('middleware', middlewareStub);
|
|
resetInitDbHashAndFirstRunStub = bootstrap.__set__('initDbHashAndFirstRun', initDbHashAndFirstRunStub);
|
|
});
|
|
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
resetMiddlewareStub();
|
|
resetInitDbHashAndFirstRunStub();
|
|
});
|
|
|
|
describe('migrations', function () {
|
|
it('database does not exist: expect database population error', function (done) {
|
|
sandbox.stub(migration.update, 'isDatabaseOutOfDate').returns({migrate:false});
|
|
|
|
sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
|
return Promise.reject();
|
|
});
|
|
|
|
bootstrap()
|
|
.then(function () {
|
|
done(new Error('expect error: database population'));
|
|
})
|
|
.catch(function (err) {
|
|
migration.populate.calledOnce.should.eql(false);
|
|
config.get('maintenance').enabled.should.eql(false);
|
|
(err instanceof Sephiroth.errors.DatabaseIsNotOkError).should.eql(true);
|
|
err.code.should.eql('MIGRATION_TABLE_IS_MISSING');
|
|
done();
|
|
});
|
|
});
|
|
|
|
// @TODO fix these two tests once we've decided on a new migration
|
|
// @TODO kate-migrations
|
|
// versioning scheme
|
|
// the tests do not work right now because if the version isn't an
|
|
// alpha version, we error. I've added two temporary tests to show this.
|
|
it.skip('database does exist: expect no update', function (done) {
|
|
sandbox.stub(migration.update, 'isDatabaseOutOfDate').returns({migrate:false});
|
|
sandbox.spy(migration.update, 'execute');
|
|
|
|
sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
|
return Promise.resolve('006');
|
|
});
|
|
|
|
bootstrap()
|
|
.then(function () {
|
|
migration.update.isDatabaseOutOfDate.calledOnce.should.eql(true);
|
|
migration.update.execute.called.should.eql(false);
|
|
models.Settings.populateDefaults.callCount.should.eql(1);
|
|
migration.populate.calledOnce.should.eql(false);
|
|
|
|
done();
|
|
})
|
|
.catch(function (err) {
|
|
done(err);
|
|
});
|
|
});
|
|
|
|
it.skip('database does exist: expect update', function (done) {
|
|
sandbox.stub(migration.update, 'isDatabaseOutOfDate').returns({migrate:true});
|
|
sandbox.stub(migration.update, 'execute').returns(Promise.resolve());
|
|
|
|
sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
|
return Promise.resolve('006');
|
|
});
|
|
|
|
bootstrap()
|
|
.then(function () {
|
|
migration.update.isDatabaseOutOfDate.calledOnce.should.eql(true);
|
|
migration.update.execute.calledOnce.should.eql(true);
|
|
|
|
migration.update.execute.calledWith({
|
|
fromVersion: '006',
|
|
toVersion: '008',
|
|
forceMigration: undefined
|
|
}).should.eql(true);
|
|
|
|
models.Settings.populateDefaults.callCount.should.eql(1);
|
|
migration.populate.calledOnce.should.eql(false);
|
|
config.get('maintenance').enabled.should.eql(false);
|
|
|
|
done();
|
|
})
|
|
.catch(function (err) {
|
|
done(err);
|
|
});
|
|
});
|
|
});
|
|
});
|