2013-09-15 20:04:42 +04:00
|
|
|
/*globals describe, before, beforeEach, afterEach, it*/
|
2013-11-07 17:26:47 +04:00
|
|
|
var testUtils = require('../utils'),
|
2013-09-15 20:04:42 +04:00
|
|
|
should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
when = require('when'),
|
2014-02-05 12:40:30 +04:00
|
|
|
_ = require("lodash"),
|
2013-09-15 20:04:42 +04:00
|
|
|
errors = require('../../server/errorHandling'),
|
|
|
|
|
|
|
|
// Stuff we are testing
|
|
|
|
migration = require('../../server/data/migration'),
|
|
|
|
exporter = require('../../server/data/export'),
|
|
|
|
Settings = require('../../server/models/settings').Settings;
|
|
|
|
|
|
|
|
describe("Exporter", function () {
|
|
|
|
|
|
|
|
should.exist(exporter);
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
testUtils.initData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("exports data", function (done) {
|
|
|
|
// Stub migrations to return 000 as the current database version
|
|
|
|
var migrationStub = sinon.stub(migration, "getDatabaseVersion", function () {
|
2014-01-15 17:29:23 +04:00
|
|
|
return when.resolve("002");
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
exporter().then(function (exportData) {
|
|
|
|
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'permissions_users',
|
|
|
|
'settings', 'tags', 'posts_tags'];
|
|
|
|
|
|
|
|
should.exist(exportData);
|
|
|
|
|
|
|
|
should.exist(exportData.meta);
|
|
|
|
should.exist(exportData.data);
|
|
|
|
|
2014-01-15 17:29:23 +04:00
|
|
|
exportData.meta.version.should.equal("002");
|
|
|
|
_.findWhere(exportData.data.settings, {key: "databaseVersion"}).value.should.equal("002");
|
2013-09-15 20:04:42 +04:00
|
|
|
|
|
|
|
_.each(tables, function (name) {
|
|
|
|
should.exist(exportData.data[name]);
|
|
|
|
});
|
|
|
|
// should not export sqlite data
|
|
|
|
should.not.exist(exportData.data.sqlite_sequence);
|
|
|
|
|
|
|
|
migrationStub.restore();
|
|
|
|
done();
|
|
|
|
}).then(null, done);
|
|
|
|
});
|
|
|
|
});
|