2016-02-25 10:10:36 +03:00
|
|
|
/*globals describe, it, afterEach*/
|
2014-12-20 13:16:29 +03:00
|
|
|
var should = require('should'),
|
2016-02-25 10:10:36 +03:00
|
|
|
sinon = require('sinon'),
|
2014-12-20 13:16:29 +03:00
|
|
|
_ = require('lodash'),
|
|
|
|
crypto = require('crypto'),
|
|
|
|
|
|
|
|
// Stuff we are testing
|
|
|
|
schema = require('../../server/data/schema'),
|
2016-02-25 10:10:36 +03:00
|
|
|
fixtures = require('../../server/data/migration/fixtures'),
|
|
|
|
defaultSettings = schema.defaultSettings,
|
|
|
|
|
|
|
|
sandbox = sinon.sandbox.create();
|
2014-12-20 13:16:29 +03:00
|
|
|
|
|
|
|
// To stop jshint complaining
|
|
|
|
should.equal(true, true);
|
|
|
|
|
|
|
|
describe('Migrations', function () {
|
2016-02-25 10:10:36 +03:00
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2016-02-07 19:23:24 +03:00
|
|
|
// Check version integrity
|
2014-12-20 13:16:29 +03:00
|
|
|
// 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
|
2015-01-11 02:49:48 +03:00
|
|
|
var currentDbVersion = '004',
|
2015-09-01 03:51:56 +03:00
|
|
|
currentSchemaHash = 'a195562bf4915e3f3f610f6d178aba01',
|
2016-02-25 10:10:36 +03:00
|
|
|
currentFixturesHash = '17d6aa36a6ba904adca90279eb929381';
|
2014-12-20 13:16:29 +03:00
|
|
|
|
|
|
|
// 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,
|
2016-02-25 10:10:36 +03:00
|
|
|
fixturesHash;
|
2014-12-20 13:16:29 +03:00
|
|
|
|
|
|
|
_.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');
|
2016-02-25 10:10:36 +03:00
|
|
|
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures.fixtures)).digest('hex');
|
2014-12-20 13:16:29 +03:00
|
|
|
|
|
|
|
// Test!
|
|
|
|
defaultSettings.core.databaseVersion.defaultValue.should.eql(currentDbVersion);
|
|
|
|
schemaHash.should.eql(currentSchemaHash);
|
2016-02-25 10:10:36 +03:00
|
|
|
fixturesHash.should.eql(currentFixturesHash);
|
|
|
|
schema.versioning.canMigrateFromVersion.should.eql('003');
|
2014-12-20 13:16:29 +03:00
|
|
|
});
|
|
|
|
});
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
describe('Builder', function () {});
|
2014-12-20 13:16:29 +03:00
|
|
|
});
|