2013-06-16 00:52:03 +04:00
|
|
|
/*globals describe, beforeEach, it*/
|
2013-06-25 15:43:15 +04:00
|
|
|
var _ = require("underscore"),
|
|
|
|
should = require('should'),
|
|
|
|
when = require('when'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
helpers = require('./helpers'),
|
2013-08-03 19:11:16 +04:00
|
|
|
migration = require('../../server/data/migration'),
|
2013-07-11 23:02:18 +04:00
|
|
|
exporter = require('../../server/data/export'),
|
|
|
|
Exporter001 = require('../../server/data/export/001'),
|
2013-08-03 19:11:16 +04:00
|
|
|
Exporter002 = require('../../server/data/export/002'),
|
2013-07-11 23:02:18 +04:00
|
|
|
errors = require('../../server/errorHandling');
|
2013-06-25 15:43:15 +04:00
|
|
|
|
|
|
|
describe("Export", function () {
|
|
|
|
|
|
|
|
should.exist(exporter);
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
2013-08-03 19:11:16 +04:00
|
|
|
// clear database... we need to initialise it manually for each test
|
|
|
|
helpers.clearData().then(function () {
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("resolves 001", function (done) {
|
|
|
|
var exportStub = sinon.stub(Exporter001, "exportData", function () {
|
|
|
|
return when.resolve();
|
2013-06-16 00:52:03 +04:00
|
|
|
});
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
exporter("001").then(function () {
|
|
|
|
exportStub.called.should.equal(true);
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
exportStub.restore();
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
describe("001", function () {
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
should.exist(Exporter001);
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("exports data", function (done) {
|
2013-08-03 19:11:16 +04:00
|
|
|
// 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) {
|
2013-06-25 15:43:15 +04:00
|
|
|
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'settings'];
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
should.exist(exportData);
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
should.exist(exportData.meta);
|
|
|
|
should.exist(exportData.data);
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
exportData.meta.version.should.equal("001");
|
2013-08-03 19:11:16 +04:00
|
|
|
_.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");
|
2013-06-16 00:52:03 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
_.each(tables, function (name) {
|
|
|
|
should.exist(exportData.data[name]);
|
2013-06-16 00:52:03 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
|
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-16 00:52:03 +04:00
|
|
|
});
|
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|