mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
338109c762
- added line to index.js to set node_env to development if it is not set - fixed a small bug with the persistent notifications and used them on debug page from server side - added 002 files to manage export and import for 002 - 002 import is somewhat smarter than 001, merging settings (except version), replacing user & clearing primary keys - added reset to models and migration, which does the down operation the same way that init does the up operation - import and reset clear session & redirect to login / signup - additional unit tests
114 lines
3.7 KiB
JavaScript
114 lines
3.7 KiB
JavaScript
/*globals describe, beforeEach, it*/
|
|
var _ = require("underscore"),
|
|
should = require('should'),
|
|
when = require('when'),
|
|
sinon = require('sinon'),
|
|
helpers = require('./helpers'),
|
|
migration = require('../../server/data/migration'),
|
|
exporter = require('../../server/data/export'),
|
|
Exporter001 = require('../../server/data/export/001'),
|
|
Exporter002 = require('../../server/data/export/002'),
|
|
errors = require('../../server/errorHandling');
|
|
|
|
describe("Export", function () {
|
|
|
|
should.exist(exporter);
|
|
|
|
beforeEach(function (done) {
|
|
// clear database... we need to initialise it manually for each test
|
|
helpers.clearData().then(function () {
|
|
done();
|
|
}, done);
|
|
});
|
|
|
|
it("resolves 001", function (done) {
|
|
var exportStub = sinon.stub(Exporter001, "exportData", function () {
|
|
return when.resolve();
|
|
});
|
|
|
|
exporter("001").then(function () {
|
|
exportStub.called.should.equal(true);
|
|
|
|
exportStub.restore();
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
describe("001", function () {
|
|
|
|
should.exist(Exporter001);
|
|
|
|
it("exports data", function (done) {
|
|
// initialise database to version 001 - confusingly we have to set the max version to be one higher
|
|
// than the migration version we want
|
|
migration.migrateUpFromVersion('001', '002').then(function () {
|
|
return exporter("001");
|
|
}).then(function (exportData) {
|
|
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'settings'];
|
|
|
|
should.exist(exportData);
|
|
|
|
should.exist(exportData.meta);
|
|
should.exist(exportData.data);
|
|
|
|
exportData.meta.version.should.equal("001");
|
|
_.findWhere(exportData.data.settings, {key: "currentVersion"}).value.should.equal("001");
|
|
|
|
_.each(tables, function (name) {
|
|
should.exist(exportData.data[name]);
|
|
});
|
|
// 002 data should not be present
|
|
should.not.exist(exportData.data.tags);
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
});
|
|
|
|
it("resolves 002", function (done) {
|
|
var exportStub = sinon.stub(Exporter002, "exportData", function () {
|
|
return when.resolve();
|
|
});
|
|
|
|
exporter("002").then(function () {
|
|
exportStub.called.should.equal(true);
|
|
|
|
exportStub.restore();
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
describe("002", function () {
|
|
|
|
should.exist(Exporter001);
|
|
|
|
it("exports data", function (done) {
|
|
// initialise database to version 001 - confusingly we have to set the max version to be one higher
|
|
// than the migration version we want
|
|
migration.migrateUpFromVersion('001', '003').then(function () {
|
|
return exporter("002");
|
|
}).then(function (exportData) {
|
|
var tables = [
|
|
'posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles',
|
|
'settings', 'tags', 'posts_tags', 'custom_data', 'posts_custom_data'
|
|
];
|
|
|
|
should.exist(exportData);
|
|
|
|
should.exist(exportData.meta);
|
|
should.exist(exportData.data);
|
|
|
|
exportData.meta.version.should.equal("002");
|
|
_.findWhere(exportData.data.settings, {key: "currentVersion"}).value.should.equal("002");
|
|
|
|
_.each(tables, function (name) {
|
|
should.exist(exportData.data[name]);
|
|
});
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
});
|
|
}); |