2014-07-17 09:33:21 -05:00
|
|
|
/*globals describe, before, beforeEach, afterEach, after, it */
|
|
|
|
var should = require('should'),
|
|
|
|
rewire = require('rewire'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
packageInfo = require('../../../package'),
|
|
|
|
ghost = require('../../../core'),
|
|
|
|
config = rewire('../../../core/server/config'),
|
|
|
|
defaultConfig = require('../../../config.example')[process.env.NODE_ENV],
|
|
|
|
permissions = require('../../server/permissions'),
|
|
|
|
testUtils = require('../utils'),
|
|
|
|
updateCheck = rewire('../../server/update-check');
|
2014-05-03 20:30:30 -05:00
|
|
|
|
|
|
|
describe('Update Check', function () {
|
|
|
|
var environmentsOrig;
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
environmentsOrig = updateCheck.__get__('allowedCheckEnvironments');
|
|
|
|
updateCheck.__set__('allowedCheckEnvironments', ['development', 'production', 'testing']);
|
|
|
|
|
2014-07-17 09:33:21 -05:00
|
|
|
_.extend(config, defaultConfig);
|
|
|
|
|
|
|
|
ghost({config: config.paths.config}).then(function () {
|
2014-05-03 20:30:30 -05:00
|
|
|
return testUtils.clearData();
|
|
|
|
}).then(function () {
|
|
|
|
done();
|
2014-07-21 04:29:03 -05:00
|
|
|
}).catch(function (err) {
|
|
|
|
console.log('Update Check before error', err);
|
|
|
|
throw new Error(err);
|
|
|
|
});
|
2014-05-03 20:30:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
updateCheck.__set__('allowedCheckEnvironments', environmentsOrig);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
testUtils.initData().then(function () {
|
|
|
|
return testUtils.insertDefaultFixtures();
|
|
|
|
}).then(function () {
|
|
|
|
return testUtils.insertEditorUser();
|
|
|
|
}).then(function () {
|
|
|
|
return testUtils.insertAuthorUser();
|
|
|
|
}).then(function () {
|
|
|
|
return permissions.init();
|
|
|
|
}).then(function () {
|
|
|
|
done();
|
2014-07-21 04:29:03 -05:00
|
|
|
}).catch(function (err) {
|
|
|
|
console.log('Update Check beforeEach error', err);
|
|
|
|
throw new Error(err);
|
|
|
|
});
|
2014-05-03 20:30:30 -05:00
|
|
|
});
|
|
|
|
|
2014-07-21 04:29:03 -05:00
|
|
|
afterEach(testUtils.teardown);
|
2014-05-03 20:30:30 -05:00
|
|
|
|
|
|
|
it('should report the correct data', function (done) {
|
|
|
|
var updateCheckData = updateCheck.__get__('updateCheckData');
|
|
|
|
|
|
|
|
updateCheckData().then(function (data) {
|
2014-05-06 19:49:25 -05:00
|
|
|
should.exist(data);
|
2014-05-03 20:30:30 -05:00
|
|
|
data.ghost_version.should.equal(packageInfo.version);
|
|
|
|
data.node_version.should.equal(process.versions.node);
|
|
|
|
data.env.should.equal(process.env.NODE_ENV);
|
|
|
|
data.database_type.should.match(/sqlite3|pg|mysql/);
|
|
|
|
data.blog_id.should.be.a.string;
|
|
|
|
data.blog_id.should.not.be.empty;
|
|
|
|
data.theme.should.be.equal('casper');
|
|
|
|
data.apps.should.be.a.string;
|
|
|
|
data.blog_created_at.should.be.a.number;
|
|
|
|
data.user_count.should.be.above(0);
|
|
|
|
data.post_count.should.be.above(0);
|
|
|
|
data.npm_version.should.be.a.string;
|
|
|
|
data.npm_version.should.not.be.empty;
|
|
|
|
|
|
|
|
done();
|
2014-05-06 19:49:25 -05:00
|
|
|
}).catch(done);
|
2014-05-03 20:30:30 -05:00
|
|
|
});
|
|
|
|
});
|