mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Adjust update check to handle changes in API calls
closes #2681 - fixed api calls and response parsing - added a test to for update check - adjusted gruntfile.js to run new update check integration test
This commit is contained in:
parent
bfd7610e36
commit
4d41e12c02
3 changed files with 75 additions and 4 deletions
|
@ -245,7 +245,8 @@ var path = require('path'),
|
|||
integration: {
|
||||
src: [
|
||||
'core/test/integration/**/model*_spec.js',
|
||||
'core/test/integration/**/api*_spec.js'
|
||||
'core/test/integration/**/api*_spec.js',
|
||||
'core/test/integration/*_spec.js'
|
||||
]
|
||||
},
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ function updateCheckData() {
|
|||
return _.reduce(apps, function (memo, item) { return memo === '' ? memo + item : memo + ', ' + item; }, '');
|
||||
}).otherwise(errors.rejectError));
|
||||
ops.push(api.posts.browse().otherwise(errors.rejectError));
|
||||
ops.push(api.users.browse().otherwise(errors.rejectError));
|
||||
ops.push(api.users.browse.call({user: 1}).otherwise(errors.rejectError));
|
||||
ops.push(nodefn.call(exec, 'npm -v').otherwise(errors.rejectError));
|
||||
|
||||
data.ghost_version = currentVersion;
|
||||
|
@ -86,8 +86,8 @@ function updateCheckData() {
|
|||
data.blog_id = crypto.createHash('md5').update(blogId).digest('hex');
|
||||
data.theme = theme ? theme.value : '';
|
||||
data.apps = apps || '';
|
||||
data.post_count = posts && posts.posts && posts.posts.total ? posts.total : 0;
|
||||
data.user_count = users && users.users && users.users.length ? users.length : 0;
|
||||
data.post_count = posts && posts.meta && posts.meta.pagination ? posts.meta.pagination.total : 0;
|
||||
data.user_count = users && users.users && users.users.length ? users.users.length : 0;
|
||||
data.blog_created_at = users && users.users && users.users[0] && users.users[0].created_at ? moment(users.users[0].created_at).unix() : '';
|
||||
data.npm_version = _.isArray(npm) && npm[0] ? npm[0].toString().replace(/\n/, '') : '';
|
||||
|
||||
|
|
70
core/test/integration/update_check_spec.js
Normal file
70
core/test/integration/update_check_spec.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
var should = require('should');
|
||||
var when = require('when');
|
||||
var rewire = require('rewire');
|
||||
var packageInfo = require('../../../package');
|
||||
var ghost = require('../../../core');
|
||||
var permissions = require('../../server/permissions');
|
||||
var testUtils = require('../utils');
|
||||
var updateCheck = rewire('../../server/update-check');
|
||||
|
||||
describe('Update Check', function () {
|
||||
var environmentsOrig;
|
||||
|
||||
before(function (done) {
|
||||
environmentsOrig = updateCheck.__get__('allowedCheckEnvironments');
|
||||
updateCheck.__set__('allowedCheckEnvironments', ['development', 'production', 'testing']);
|
||||
|
||||
ghost().then(function () {
|
||||
return testUtils.clearData();
|
||||
}).then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
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();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
testUtils.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should report the correct data', function (done) {
|
||||
var updateCheckData = updateCheck.__get__('updateCheckData');
|
||||
|
||||
updateCheckData().then(function (data) {
|
||||
data.should.exist;
|
||||
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();
|
||||
}).otherwise(done);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue