Ghost/core/test/integration/export_spec.js
Hannah Wolfe 9309adc511 Exporter cleanup & tests
refs #6301

- change knex getter def to be configurable, else it is not testable
- remove exportPath and lang from config - neither are used
- add client_trusted_domains to tables which shouldn't be exported as there are no clients in the export
- change export signature to be an object with `doExport` function consistent with import & easier to test
- cleanup export code so it is clearer, easier to read & to test:
  - use mapSeries instead of sequence
  - use Promise.props instead of Promise.join
  - split functionality into smaller functions
- add test coverage
2016-03-12 19:01:25 +00:00

60 lines
2.0 KiB
JavaScript

/*globals describe, before, beforeEach, afterEach, it*/
var testUtils = require('../utils/index'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
// Stuff we are testing
versioning = require('../../server/data/schema').versioning,
exporter = require('../../server/data/export'),
DEF_DB_VERSION = versioning.getDefaultDatabaseVersion(),
sandbox = sinon.sandbox.create();
describe('Exporter', function () {
before(testUtils.teardown);
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
});
beforeEach(testUtils.setup('default'));
should.exist(exporter);
it('exports data', function (done) {
// Stub migrations to return DEF_DB_VERSION as the current database version
var versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () {
return Promise.resolve(DEF_DB_VERSION);
});
exporter.doExport().then(function (exportData) {
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles',
'permissions_users', 'settings', 'tags', 'posts_tags'],
dbVersionSetting;
should.exist(exportData);
should.exist(exportData.meta);
should.exist(exportData.data);
exportData.meta.version.should.equal(DEF_DB_VERSION);
dbVersionSetting = _.findWhere(exportData.data.settings, {key: 'databaseVersion'});
should.exist(dbVersionSetting);
dbVersionSetting.value.should.equal(DEF_DB_VERSION);
_.each(tables, function (name) {
should.exist(exportData.data[name]);
});
// should not export sqlite data
should.not.exist(exportData.data.sqlite_sequence);
versioningStub.restore();
done();
}).catch(done);
});
});