Ghost/test/unit/data/schema/integrity_spec.js
Hannah Wolfe fdc043227a Updated fixtures for Ghost v4.0
- With 4.0 we have a brand new version of Casper, new fixtures and new default settings
- Fixture posts cover the key features and give users an introduction to how to use their site
- This all comes from the marketing and design teams to refresh the look and feel of Ghost and give users the best possible onboarding experience
Note: this fixture overhaul includes
- new content for new 4.0 features
- regenerated post content using our updated mobiledoc structure
- a switch from British to US English
2021-03-10 17:37:16 +00:00

70 lines
3.1 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');
const fixtures = require('../../../../core/server/data/schema/fixtures');
const frontendSettings = require('../../../../core/frontend/services/settings');
const validateFrontendSettings = require('../../../../core/frontend/services/settings/validate');
const defaultSettings = require('../../../../core/server/data/schema/default-settings');
/**
* @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 = '559cdbb49a7eeb5758caf0c6e3bf790d';
const currentFixturesHash = '05a291a44821aa340a91796b4c101575';
const currentSettingsHash = '7ac732b994a5bb1565f88c8a84872964';
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 = validateFrontendSettings(yaml.load(fs.readFileSync(routesPath, 'utf-8')));
const tablesNoValidation = _.cloneDeep(schema.tables);
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(frontendSettings.getDefaulHash('routes'));
});
});