mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Migrated update check to use api v2
refs #9866 - Switched update checker to api v2 - Updated and cleaned up the corresponding test suite - Updated the frame pipeline to respect context passed in with Frame instance - Exposed 'active' verison from api index module
This commit is contained in:
parent
734bcc9040
commit
fd958addb6
4 changed files with 41 additions and 29 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
const config = require('../config');
|
||||||
module.exports = require('./v0.1');
|
module.exports = require('./v0.1');
|
||||||
module.exports['v0.1'] = require('./v0.1');
|
module.exports['v0.1'] = require('./v0.1');
|
||||||
module.exports.v2 = require('./v2');
|
module.exports.v2 = require('./v2');
|
||||||
|
module.exports.active = require(`./${config.get('api:versions:active')}`);
|
||||||
|
|
|
@ -120,8 +120,8 @@ const pipeline = (apiController, apiUtils) => {
|
||||||
if (!(options instanceof shared.Frame)) {
|
if (!(options instanceof shared.Frame)) {
|
||||||
frame = new shared.Frame({
|
frame = new shared.Frame({
|
||||||
body: data,
|
body: data,
|
||||||
options: options,
|
options: _.omit(options, 'context'),
|
||||||
context: {}
|
context: options.context || {}
|
||||||
});
|
});
|
||||||
|
|
||||||
frame.configure({
|
frame.configure({
|
||||||
|
|
|
@ -27,7 +27,7 @@ const crypto = require('crypto'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
debug = require('ghost-ignition').debug('update-check'),
|
debug = require('ghost-ignition').debug('update-check'),
|
||||||
api = require('./api'),
|
api = require('./api').active,
|
||||||
config = require('./config'),
|
config = require('./config'),
|
||||||
urlService = require('./services/url'),
|
urlService = require('./services/url'),
|
||||||
common = require('./lib/common'),
|
common = require('./lib/common'),
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
Promise = require('bluebird'),
|
const Promise = require('bluebird');
|
||||||
should = require('should'),
|
const should = require('should');
|
||||||
rewire = require('rewire'),
|
const rewire = require('rewire');
|
||||||
sinon = require('sinon'),
|
const sinon = require('sinon');
|
||||||
moment = require('moment'),
|
const moment = require('moment');
|
||||||
uuid = require('uuid'),
|
const uuid = require('uuid');
|
||||||
testUtils = require('../utils'),
|
const testUtils = require('../utils');
|
||||||
configUtils = require('../utils/configUtils'),
|
const configUtils = require('../utils/configUtils');
|
||||||
packageInfo = require('../../../package'),
|
const packageInfo = require('../../../package');
|
||||||
updateCheck = rewire('../../server/update-check'),
|
const api = require('../../server/api').active;
|
||||||
ghostVersion = rewire('../../server/lib/ghost-version'),
|
|
||||||
SettingsAPI = require('../../server/api/v0.1/settings'),
|
const sandbox = sinon.sandbox.create();
|
||||||
NotificationsAPI = rewire('../../server/api/v0.1/notifications'),
|
|
||||||
sandbox = sinon.sandbox.create();
|
let updateCheck = rewire('../../server/update-check');
|
||||||
|
let NotificationsAPI = rewire('../../server/api/v2/notifications');
|
||||||
|
|
||||||
describe('Update Check', function () {
|
describe('Update Check', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
updateCheck = rewire('../../server/update-check');
|
updateCheck = rewire('../../server/update-check');
|
||||||
NotificationsAPI = rewire('../../server/api/v0.1/notifications');
|
NotificationsAPI = rewire('../../server/api/v2/notifications');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
@ -47,10 +48,13 @@ describe('Update Check', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('update check was never executed', function (done) {
|
it('update check was never executed', function (done) {
|
||||||
sandbox.stub(SettingsAPI, 'read').returns(Promise.resolve({
|
const readStub = sandbox.stub().resolves({
|
||||||
settings: [{
|
settings: [{
|
||||||
value: null
|
value: null
|
||||||
}]
|
}]
|
||||||
|
});
|
||||||
|
sandbox.stub(api, 'settings').get(() => ({
|
||||||
|
read: readStub
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateCheck()
|
updateCheck()
|
||||||
|
@ -64,10 +68,13 @@ describe('Update Check', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('update check won\'t happen if it\'s too early', function (done) {
|
it('update check won\'t happen if it\'s too early', function (done) {
|
||||||
sandbox.stub(SettingsAPI, 'read').returns(Promise.resolve({
|
const readStub = sandbox.stub().resolves({
|
||||||
settings: [{
|
settings: [{
|
||||||
value: moment().add('10', 'minutes').unix()
|
value: moment().add('10', 'minutes').unix()
|
||||||
}]
|
}]
|
||||||
|
});
|
||||||
|
sandbox.stub(api, 'settings').get(() => ({
|
||||||
|
read: readStub
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateCheck()
|
updateCheck()
|
||||||
|
@ -81,10 +88,13 @@ describe('Update Check', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('update check will happen if it\'s time to check', function (done) {
|
it('update check will happen if it\'s time to check', function (done) {
|
||||||
sandbox.stub(SettingsAPI, 'read').returns(Promise.resolve({
|
const readStub = sandbox.stub().resolves({
|
||||||
settings: [{
|
settings: [{
|
||||||
value: moment().subtract('10', 'minutes').unix()
|
value: moment().subtract('10', 'minutes').unix()
|
||||||
}]
|
}]
|
||||||
|
});
|
||||||
|
sandbox.stub(api, 'settings').get(() => ({
|
||||||
|
read: readStub
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateCheck()
|
updateCheck()
|
||||||
|
@ -153,7 +163,7 @@ describe('Update Check', function () {
|
||||||
beforeEach(testUtils.setup('settings', 'roles', 'owner', 'perms:setting', 'perms:notification', 'perms:user', 'perms:init'));
|
beforeEach(testUtils.setup('settings', 'roles', 'owner', 'perms:setting', 'perms:notification', 'perms:user', 'perms:init'));
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return NotificationsAPI.destroyAll(testUtils.context.internal);
|
return api.notifications.destroyAll(testUtils.context.internal);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a release notification for target version', function (done) {
|
it('should create a release notification for target version', function (done) {
|
||||||
|
@ -173,7 +183,7 @@ describe('Update Check', function () {
|
||||||
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
||||||
|
|
||||||
createCustomNotification(notification).then(function () {
|
createCustomNotification(notification).then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
should.exist(results.notifications);
|
should.exist(results.notifications);
|
||||||
|
@ -208,7 +218,7 @@ describe('Update Check', function () {
|
||||||
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
||||||
|
|
||||||
createCustomNotification(notification).then(function () {
|
createCustomNotification(notification).then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
should.exist(results.notifications);
|
should.exist(results.notifications);
|
||||||
|
@ -234,7 +244,7 @@ describe('Update Check', function () {
|
||||||
NotificationsAPI.__set__('ghostVersion.full', '0.8');
|
NotificationsAPI.__set__('ghostVersion.full', '0.8');
|
||||||
|
|
||||||
createCustomNotification(notification).then(function () {
|
createCustomNotification(notification).then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
should.exist(results.notifications);
|
should.exist(results.notifications);
|
||||||
|
@ -259,7 +269,7 @@ describe('Update Check', function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
createCustomNotification(notification).then(function () {
|
createCustomNotification(notification).then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
should.exist(results.notifications);
|
should.exist(results.notifications);
|
||||||
|
@ -291,7 +301,7 @@ describe('Update Check', function () {
|
||||||
|
|
||||||
createCustomNotification(notification)
|
createCustomNotification(notification)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
})
|
})
|
||||||
.then(function (results) {
|
.then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
|
@ -302,7 +312,7 @@ describe('Update Check', function () {
|
||||||
return createCustomNotification(notification);
|
return createCustomNotification(notification);
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return NotificationsAPI.browse(testUtils.context.internal);
|
return api.notifications.browse(testUtils.context.internal);
|
||||||
})
|
})
|
||||||
.then(function (results) {
|
.then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
|
|
Loading…
Add table
Reference in a new issue