mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -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['v0.1'] = require('./v0.1');
|
||||
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)) {
|
||||
frame = new shared.Frame({
|
||||
body: data,
|
||||
options: options,
|
||||
context: {}
|
||||
options: _.omit(options, 'context'),
|
||||
context: options.context || {}
|
||||
});
|
||||
|
||||
frame.configure({
|
||||
|
|
|
@ -27,7 +27,7 @@ const crypto = require('crypto'),
|
|||
_ = require('lodash'),
|
||||
url = require('url'),
|
||||
debug = require('ghost-ignition').debug('update-check'),
|
||||
api = require('./api'),
|
||||
api = require('./api').active,
|
||||
config = require('./config'),
|
||||
urlService = require('./services/url'),
|
||||
common = require('./lib/common'),
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
var _ = require('lodash'),
|
||||
Promise = require('bluebird'),
|
||||
should = require('should'),
|
||||
rewire = require('rewire'),
|
||||
sinon = require('sinon'),
|
||||
moment = require('moment'),
|
||||
uuid = require('uuid'),
|
||||
testUtils = require('../utils'),
|
||||
configUtils = require('../utils/configUtils'),
|
||||
packageInfo = require('../../../package'),
|
||||
updateCheck = rewire('../../server/update-check'),
|
||||
ghostVersion = rewire('../../server/lib/ghost-version'),
|
||||
SettingsAPI = require('../../server/api/v0.1/settings'),
|
||||
NotificationsAPI = rewire('../../server/api/v0.1/notifications'),
|
||||
sandbox = sinon.sandbox.create();
|
||||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const should = require('should');
|
||||
const rewire = require('rewire');
|
||||
const sinon = require('sinon');
|
||||
const moment = require('moment');
|
||||
const uuid = require('uuid');
|
||||
const testUtils = require('../utils');
|
||||
const configUtils = require('../utils/configUtils');
|
||||
const packageInfo = require('../../../package');
|
||||
const api = require('../../server/api').active;
|
||||
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
||||
let updateCheck = rewire('../../server/update-check');
|
||||
let NotificationsAPI = rewire('../../server/api/v2/notifications');
|
||||
|
||||
describe('Update Check', function () {
|
||||
beforeEach(function () {
|
||||
updateCheck = rewire('../../server/update-check');
|
||||
NotificationsAPI = rewire('../../server/api/v0.1/notifications');
|
||||
NotificationsAPI = rewire('../../server/api/v2/notifications');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -47,10 +48,13 @@ describe('Update Check', function () {
|
|||
});
|
||||
|
||||
it('update check was never executed', function (done) {
|
||||
sandbox.stub(SettingsAPI, 'read').returns(Promise.resolve({
|
||||
const readStub = sandbox.stub().resolves({
|
||||
settings: [{
|
||||
value: null
|
||||
}]
|
||||
});
|
||||
sandbox.stub(api, 'settings').get(() => ({
|
||||
read: readStub
|
||||
}));
|
||||
|
||||
updateCheck()
|
||||
|
@ -64,10 +68,13 @@ describe('Update Check', function () {
|
|||
});
|
||||
|
||||
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: [{
|
||||
value: moment().add('10', 'minutes').unix()
|
||||
}]
|
||||
});
|
||||
sandbox.stub(api, 'settings').get(() => ({
|
||||
read: readStub
|
||||
}));
|
||||
|
||||
updateCheck()
|
||||
|
@ -81,10 +88,13 @@ describe('Update Check', function () {
|
|||
});
|
||||
|
||||
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: [{
|
||||
value: moment().subtract('10', 'minutes').unix()
|
||||
}]
|
||||
});
|
||||
sandbox.stub(api, 'settings').get(() => ({
|
||||
read: readStub
|
||||
}));
|
||||
|
||||
updateCheck()
|
||||
|
@ -153,7 +163,7 @@ describe('Update Check', function () {
|
|||
beforeEach(testUtils.setup('settings', 'roles', 'owner', 'perms:setting', 'perms:notification', 'perms:user', 'perms:init'));
|
||||
|
||||
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) {
|
||||
|
@ -173,7 +183,7 @@ describe('Update Check', function () {
|
|||
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
||||
|
||||
createCustomNotification(notification).then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
}).then(function (results) {
|
||||
should.exist(results);
|
||||
should.exist(results.notifications);
|
||||
|
@ -208,7 +218,7 @@ describe('Update Check', function () {
|
|||
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
|
||||
|
||||
createCustomNotification(notification).then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
}).then(function (results) {
|
||||
should.exist(results);
|
||||
should.exist(results.notifications);
|
||||
|
@ -234,7 +244,7 @@ describe('Update Check', function () {
|
|||
NotificationsAPI.__set__('ghostVersion.full', '0.8');
|
||||
|
||||
createCustomNotification(notification).then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
}).then(function (results) {
|
||||
should.exist(results);
|
||||
should.exist(results.notifications);
|
||||
|
@ -259,7 +269,7 @@ describe('Update Check', function () {
|
|||
};
|
||||
|
||||
createCustomNotification(notification).then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
}).then(function (results) {
|
||||
should.exist(results);
|
||||
should.exist(results.notifications);
|
||||
|
@ -291,7 +301,7 @@ describe('Update Check', function () {
|
|||
|
||||
createCustomNotification(notification)
|
||||
.then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
})
|
||||
.then(function (results) {
|
||||
should.exist(results);
|
||||
|
@ -302,7 +312,7 @@ describe('Update Check', function () {
|
|||
return createCustomNotification(notification);
|
||||
})
|
||||
.then(function () {
|
||||
return NotificationsAPI.browse(testUtils.context.internal);
|
||||
return api.notifications.browse(testUtils.context.internal);
|
||||
})
|
||||
.then(function (results) {
|
||||
should.exist(results);
|
||||
|
|
Loading…
Add table
Reference in a new issue