Ghost/core/test/integration/export_spec.js
Hannah Wolfe 337713ce63 Refactor fixture use in tests
no issue

- Refactor all integration tests to specify and load ONLY the fixtures
  they require to run, rather than initialising the whole kit-and-kaboodle
  for every single test which takes FOREVER.
- Refactor the route tests to share a doAuth function, and also specify
  additional fixtures required
- Move import and export unit tests, which are actually integration tests
  (they touch the DB)
- Comment out most of the permissions unit tests for now as they need more
  stubs/mocks so as to not touch the DB

Still todo:

- prevent default DB initialisation in route tests, and specify all
  fixtures requires as per the integration tests
- fix up the unit/permissions_spec
2014-07-23 05:04:50 +01:00

54 lines
1.7 KiB
JavaScript

/*globals describe, before, beforeEach, afterEach, it*/
/*jshint expr:true*/
var testUtils = require('../utils/index'),
should = require('should'),
sinon = require('sinon'),
when = require('when'),
_ = require('lodash'),
// Stuff we are testing
versioning = require('../../server/data/versioning/index'),
exporter = require('../../server/data/export/index'),
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 000 as the current database version
var versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () {
return when.resolve('003');
});
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);
exportData.meta.version.should.equal('003');
_.findWhere(exportData.data.settings, {key: 'databaseVersion'}).value.should.equal('003');
_.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);
});
});