Ghost/core/test/unit/migration_spec.js
Hannah Wolfe b2f1d0559b Themes API activation permissions & validation (#8104)
refs #8093

 Add activate theme permission
- add permission to activate themes
- update tests
- also: update tests for invites
TODO: change how the active theme setting is updated to reduce extra permissions

 Move theme validation to gscan
- add a new gscan validation method and use it for upload
- update activate endpoint to do validation also using gscan
- change to using SettingsModel instead of API so that we don't call validation or permissions on the settings API
- remove validation from the settings model
- remove the old validation function
- add new invalid theme message to translations & remove a bunch of theme validation related unused keys

📖  Planned changes

🚨 Tests for theme activation API endpoint
🐛 Don't allow deleting the active theme

🚫 Prevent activeTheme being set via settings API
- We want to control how this happens in future.
- We still want to store the information in settings, via the model.
- We just don't want to be able to change this info via the settings edit endpoint

🐛  Fix warnings for uploads & add for activations
- warnings for uploads were broken in f8b498d
- fix the response + adds tests to cover that warnings are correctly returned
- add the same response to activations + more tests
- activations now return a single theme object - the theme that was activated + any warnings

🎨 Improve how we generate theme API responses
- remove the requirement to pass in the active theme!
- move this to a specialist function, away from the list

🎨 Do not load gscan on boot
2017-03-13 12:44:44 +01:00

76 lines
2.8 KiB
JavaScript

var sinon = require('sinon'),
rewire = require('rewire'),
_ = require('lodash'),
should = require('should'),
Promise = require('bluebird'),
crypto = require('crypto'),
fs = require('fs'),
models = require('../../server/models'),
exporter = require('../../server/data/export'),
schema = require('../../server/data/schema'),
backupDatabase = rewire('../../server/data/db/backup'),
fixtures = require('../../server/data/schema/fixtures'),
sandbox = sinon.sandbox.create();
should.equal(true, true);
// Check version integrity
// These tests exist to ensure that developers are not able to modify the database schema, or permissions fixtures
// without knowing that they also need to update the default database version,
// both of which are required for migrations to work properly.
describe('DB version integrity', function () {
// Only these variables should need updating
var currentSchemaHash = 'ae4ada98be2691b4d6e323eebcdb875f',
currentFixturesHash = '46abf9fd0d67fc89fa7845bef7fc7ffd';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation
it('should not change without fixing this test', function () {
var tablesNoValidation = _.cloneDeep(schema.tables),
schemaHash,
fixturesHash;
_.each(tablesNoValidation, function (table) {
return _.each(table, function (column, name) {
table[name] = _.omit(column, 'validations');
});
});
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation)).digest('hex');
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures)).digest('hex');
schemaHash.should.eql(currentSchemaHash);
fixturesHash.should.eql(currentFixturesHash);
});
});
describe('Migrations', function () {
before(function () {
models.init();
});
afterEach(function () {
sandbox.restore();
});
describe('Backup', function () {
var exportStub, filenameStub, fsStub;
beforeEach(function () {
exportStub = sandbox.stub(exporter, 'doExport').returns(new Promise.resolve());
filenameStub = sandbox.stub(exporter, 'fileName').returns(new Promise.resolve('test'));
fsStub = sandbox.stub(fs, 'writeFile').yields();
});
it('should create a backup JSON file', function (done) {
backupDatabase().then(function () {
exportStub.calledOnce.should.be.true();
filenameStub.calledOnce.should.be.true();
fsStub.calledOnce.should.be.true();
done();
}).catch(done);
});
});
});