2013-09-15 20:04:42 +04:00
|
|
|
/*globals describe, before, beforeEach, afterEach, it*/
|
2014-06-05 01:26:03 +04:00
|
|
|
/*jshint expr:true*/
|
|
|
|
var testUtils = require('../utils'),
|
|
|
|
should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
when = require('when'),
|
|
|
|
_ = require('lodash'),
|
2013-09-15 20:04:42 +04:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2014-06-05 01:26:03 +04:00
|
|
|
versioning = require('../../server/data/versioning'),
|
|
|
|
exporter = require('../../server/data/export');
|
2013-09-15 20:04:42 +04:00
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
describe('Exporter', function () {
|
2013-09-15 20:04:42 +04:00
|
|
|
|
|
|
|
should.exist(exporter);
|
|
|
|
|
2014-02-12 07:40:39 +04:00
|
|
|
var sandbox;
|
|
|
|
|
2013-09-15 20:04:42 +04:00
|
|
|
before(function (done) {
|
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
done();
|
2014-05-06 00:58:58 +04:00
|
|
|
}).catch(done);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
2014-02-12 07:40:39 +04:00
|
|
|
sandbox = sinon.sandbox.create();
|
2013-09-15 20:04:42 +04:00
|
|
|
testUtils.initData().then(function () {
|
|
|
|
done();
|
2014-05-06 00:58:58 +04:00
|
|
|
}).catch(done);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2014-02-12 07:40:39 +04:00
|
|
|
sandbox.restore();
|
2013-09-15 20:04:42 +04:00
|
|
|
testUtils.clearData().then(function () {
|
|
|
|
done();
|
2014-05-06 00:58:58 +04:00
|
|
|
}).catch(done);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
it('exports data', function (done) {
|
2013-09-15 20:04:42 +04:00
|
|
|
// Stub migrations to return 000 as the current database version
|
2014-06-05 01:26:03 +04:00
|
|
|
var versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
|
|
|
return when.resolve('003');
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
exporter().then(function (exportData) {
|
2014-06-05 01:26:03 +04:00
|
|
|
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles',
|
|
|
|
'permissions_users', 'settings', 'tags', 'posts_tags'];
|
2013-09-15 20:04:42 +04:00
|
|
|
|
|
|
|
should.exist(exportData);
|
|
|
|
|
|
|
|
should.exist(exportData.meta);
|
|
|
|
should.exist(exportData.data);
|
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
exportData.meta.version.should.equal('003');
|
|
|
|
_.findWhere(exportData.data.settings, {key: 'databaseVersion'}).value.should.equal('003');
|
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);
|
|
|
|
|
2014-06-01 03:53:21 +04:00
|
|
|
versioningStub.restore();
|
2013-09-15 20:04:42 +04:00
|
|
|
done();
|
2014-05-06 00:58:58 +04:00
|
|
|
}).catch(done);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
});
|