0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/test/unit/import_spec.js
Hannah Wolfe 2b9be5376e Added functional tests for Ghost Admin UI using Casperjs
Hacky implementation of a suite of casper tests. This is here so that we can start to build up some tests.
Main thing missing is being able to simulate keypresses for CodeMirror
Making the tests run nicely with grunt, travis and be independent rather than interdependent can all come later.
- See tests/functional/base.js for full usage instructions & implementation notes
2013-07-31 08:33:28 +01:00

79 lines
No EOL
2.6 KiB
JavaScript

/*globals describe, beforeEach, it*/
var _ = require("underscore"),
should = require('should'),
when = require('when'),
sinon = require('sinon'),
knex = require("../../server/models/base").Knex,
helpers = require('./helpers'),
exporter = require('../../server/data/export'),
importer = require('../../server/data/import'),
Importer001 = require('../../server/data/import/001'),
errors = require('../../server/errorHandling');
describe("Import", function () {
should.exist(exporter);
should.exist(importer);
beforeEach(function (done) {
helpers.resetData().then(function () {
done();
}, done);
});
it("resolves 001", function (done) {
var importStub = sinon.stub(Importer001, "importData", function () {
return when.resolve();
}),
fakeData = { test: true };
importer("001", fakeData).then(function () {
importStub.calledWith(fakeData).should.equal(true);
importStub.restore();
done();
}).then(null, done);
});
describe("001", function () {
this.timeout(4000);
should.exist(Importer001);
it("imports data from 001", function (done) {
var exportData;
// TODO: Should have static test data here?
exporter("001").then(function (exported) {
exportData = exported;
// Clear the data from all tables.
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'settings'],
truncateOps = _.map(tables, function (name) {
return knex(name).truncate();
});
return when.all(truncateOps);
}).then(function () {
return importer("001", exportData);
}).then(function () {
// Grab the data from tables
return when.all([
knex("users").select(),
knex("posts").select(),
knex("settings").select()
]);
}).then(function (importedData) {
should.exist(importedData);
importedData.length.should.equal(3);
importedData[0].length.should.equal(exportData.data.users.length);
importedData[1].length.should.equal(exportData.data.posts.length);
importedData[2].length.should.equal(exportData.data.settings.length);
done();
}).then(null, done);
});
});
});