2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
_ = require('lodash'),
|
2016-04-08 13:39:50 +03:00
|
|
|
rewire = require('rewire'),
|
2017-01-04 19:10:29 +03:00
|
|
|
uuid = require('uuid'),
|
2017-02-07 22:58:03 +03:00
|
|
|
testUtils = require('../utils'),
|
2017-02-03 21:25:39 +03:00
|
|
|
configUtils = require('../utils/configUtils'),
|
2016-07-22 16:02:10 +03:00
|
|
|
packageInfo = require('../../../package'),
|
|
|
|
updateCheck = rewire('../../server/update-check'),
|
|
|
|
NotificationsAPI = require('../../server/api/notifications');
|
2014-05-04 05:30:30 +04:00
|
|
|
|
|
|
|
describe('Update Check', function () {
|
2017-02-07 22:58:03 +03:00
|
|
|
after(function () {
|
|
|
|
return NotificationsAPI.destroyAll(testUtils.context.internal);
|
|
|
|
});
|
|
|
|
|
2016-07-22 16:02:10 +03:00
|
|
|
describe('Reporting to UpdateCheck', function () {
|
|
|
|
before(function () {
|
2017-02-03 21:25:39 +03:00
|
|
|
configUtils.set('privacy:useUpdateCheck', true);
|
2016-07-22 16:02:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2017-02-03 21:25:39 +03:00
|
|
|
configUtils.restore();
|
2016-07-22 16:02:10 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(testUtils.setup('owner', 'posts', 'perms:setting', 'perms:user', 'perms:init'));
|
|
|
|
|
|
|
|
afterEach(testUtils.teardown);
|
2014-05-04 05:30:30 +04:00
|
|
|
|
2016-07-22 16:02:10 +03:00
|
|
|
it('should report the correct data', function (done) {
|
|
|
|
var updateCheckData = updateCheck.__get__('updateCheckData');
|
|
|
|
|
|
|
|
updateCheckData().then(function (data) {
|
|
|
|
should.exist(data);
|
|
|
|
data.ghost_version.should.equal(packageInfo.version);
|
|
|
|
data.node_version.should.equal(process.versions.node);
|
|
|
|
data.env.should.equal(process.env.NODE_ENV);
|
2016-09-16 12:40:23 +03:00
|
|
|
data.database_type.should.match(/sqlite3|mysql/);
|
2016-07-22 16:02:10 +03:00
|
|
|
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();
|
2017-02-07 22:58:03 +03:00
|
|
|
data.lts.should.eql(false);
|
2016-07-22 16:02:10 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2014-05-04 05:30:30 +04:00
|
|
|
});
|
|
|
|
|
2016-07-22 16:02:10 +03:00
|
|
|
describe('Custom Notifications', function () {
|
|
|
|
var currentVersionOrig;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
currentVersionOrig = updateCheck.__get__('currentVersion');
|
|
|
|
updateCheck.__set__('currentVersion', '0.9.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
updateCheck.__set__('currentVersion', currentVersionOrig);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(testUtils.setup('owner', 'posts', 'settings', 'perms:setting', 'perms:notification', 'perms:user', 'perms:init'));
|
|
|
|
|
|
|
|
afterEach(testUtils.teardown);
|
|
|
|
|
|
|
|
it('should create a custom notification for target version', function (done) {
|
|
|
|
var createCustomNotification = updateCheck.__get__('createCustomNotification'),
|
|
|
|
message = {
|
|
|
|
id: uuid.v4(),
|
|
|
|
version: '0.9.x',
|
|
|
|
content: '<p>Hey there! This is for 0.9.0 version</p>'
|
|
|
|
};
|
|
|
|
|
|
|
|
createCustomNotification(message).then(function () {
|
|
|
|
return NotificationsAPI.browse(testUtils.context.internal);
|
|
|
|
}).then(function (results) {
|
|
|
|
should.exist(results);
|
|
|
|
should.exist(results.notifications);
|
|
|
|
results.notifications.length.should.be.above(0);
|
|
|
|
should.exist(_.find(results.notifications, {uuid: message.id}));
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not create notifications meant for other versions', function (done) {
|
|
|
|
var createCustomNotification = updateCheck.__get__('createCustomNotification'),
|
|
|
|
message = {
|
|
|
|
id: uuid.v4(),
|
|
|
|
version: '0.5.x',
|
|
|
|
content: '<p>Hey there! This is for 0.5.0 version</p>'
|
|
|
|
};
|
|
|
|
|
|
|
|
createCustomNotification(message).then(function () {
|
|
|
|
return NotificationsAPI.browse(testUtils.context.internal);
|
|
|
|
}).then(function (results) {
|
|
|
|
should.not.exist(_.find(results.notifications, {uuid: message.id}));
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
2014-05-04 05:30:30 +04:00
|
|
|
});
|
|
|
|
});
|
2016-07-22 16:02:10 +03:00
|
|
|
|