Ghost/test/unit/server/data/schema/integrity.test.js
Rishabh Garg 3b90b1f335
Moved launchComplete user setting as global editor setting (#13703)
refs https://github.com/TryGhost/Team/issues/807

The launch wizard completed flag was previously stored at per user level in accessibility column of user table, so an administrator still got the option to complete the launch wizard even if the owner had completed it previously, which is not expected pattern. This change moves the launch complete flag for Admin to common settings from per user level so a site only needs to complete the launch wizard once irrespective of which user completes it

- adds new `editor_is_launch_complete` setting to track if a site launch steps are completed in Admin
- adds new migration util to easily allow adding new setting 
- adds migration to introduce new `editor_is_launch_complete` setting
- adds migration to update launch complete flag for a site if any of the users have already completed the launch steps
2021-11-04 18:03:51 +05:30

72 lines
3.2 KiB
JavaScript

const should = require('should');
const _ = require('lodash');
const yaml = require('js-yaml');
const crypto = require('crypto');
const fs = require('fs-extra');
const path = require('path');
const {config} = require('../../../../utils/configUtils');
const schema = require('../../../../../core/server/data/schema/schema');
const fixtures = require('../../../../../core/server/data/schema/fixtures/fixtures.json');
const defaultSettings = require('../../../../../core/server/data/schema/default-settings.json');
// Routes are yaml so we can require the file directly
const routeSettings = require('../../../../../core/server/services/route-settings');
const validateRouteSettings = require('../../../../../core/server/services/route-settings/validate');
/**
* @NOTE
*
* If this test fails for you, you have modified one of:
* - the database schema
* - fixtures
* - default settings
* - routes.yaml
*
* When you make a change, please test that:
*
* 1. A new blog get's installed and the database looks correct and complete.
* 2. A blog get's updated from a lower Ghost version and the database looks correct and complete.
*
* Typical cases:
* You have to add a migration script if you've added/modified permissions.
* You have to add a migration script if you've add a new table.
* You have to add a migration script if you've added new settings to populate group/flags column.
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'e649797a5de92d417744f6f2623c79cf';
const currentFixturesHash = '07d4b0c4cf159b34344a6b5e88c74e9f';
const currentSettingsHash = 'b06316ebbf62381158e1c46c97c0b77a';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
// 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 () {
const routesPath = path.join(config.get('paths').defaultSettings, 'default-routes.yaml');
const defaultRoutes = validateRouteSettings(yaml.load(fs.readFileSync(routesPath, 'utf-8')));
const tablesNoValidation = _.cloneDeep(schema);
let schemaHash;
let fixturesHash;
let settingsHash;
let routesHash;
_.each(tablesNoValidation, function (table) {
return _.each(table, function (column, name) {
table[name] = _.omit(column, 'validations');
});
});
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation), 'binary').digest('hex');
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures), 'binary').digest('hex');
settingsHash = crypto.createHash('md5').update(JSON.stringify(defaultSettings), 'binary').digest('hex');
routesHash = crypto.createHash('md5').update(JSON.stringify(defaultRoutes), 'binary').digest('hex');
schemaHash.should.eql(currentSchemaHash);
fixturesHash.should.eql(currentFixturesHash);
settingsHash.should.eql(currentSettingsHash);
routesHash.should.eql(currentRoutesHash);
routesHash.should.eql(routeSettings.getDefaultHash());
});
});