mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
Removed ghostVersion parameter from UpdateCheckService
refs https://github.com/TryGhost/Team/issues/728 - This is continuation of the previous commit. TLDR: Passing only the necessary parameter data makes it easier to reason about what dependencies the UpdateCheckService has to deal with - Burned ghostVersion module passing in vafor of just one additional config parameter. Now the module along with unit tests can be easily extracted out of the codebase!
This commit is contained in:
parent
796e2caaff
commit
a4e5436df7
@ -38,14 +38,15 @@ class UpdateCheckService {
|
|||||||
* @param {string[]} [options.config.notificationGroups] - example values ["migration", "something"]
|
* @param {string[]} [options.config.notificationGroups] - example values ["migration", "something"]
|
||||||
* @param {string} options.config.siteUrl - Ghost instance URL
|
* @param {string} options.config.siteUrl - Ghost instance URL
|
||||||
* @param {boolean} [options.config.forceUpdate]
|
* @param {boolean} [options.config.forceUpdate]
|
||||||
|
* @param {string} options.config.ghostVersion - Ghost instance version
|
||||||
|
* @param {Function} options.request - a HTTP request proxy function
|
||||||
*/
|
*/
|
||||||
constructor({api, config, i18n, logging, request, ghostVersion, ghostMailer}) {
|
constructor({api, config, i18n, logging, request, ghostMailer}) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
this.logging = logging;
|
this.logging = logging;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.ghostVersion = ghostVersion;
|
|
||||||
this.ghostMailer = ghostMailer;
|
this.ghostMailer = ghostMailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ class UpdateCheckService {
|
|||||||
let data = {};
|
let data = {};
|
||||||
let mailConfig = this.config.mail;
|
let mailConfig = this.config.mail;
|
||||||
|
|
||||||
data.ghost_version = this.ghostVersion.original;
|
data.ghost_version = this.config.ghostVersion;
|
||||||
data.node_version = process.versions.node;
|
data.node_version = process.versions.node;
|
||||||
data.env = this.config.env;
|
data.env = this.config.env;
|
||||||
data.database_type = this.config.databaseType;
|
data.database_type = this.config.databaseType;
|
||||||
|
@ -2,8 +2,6 @@ const should = require('should');
|
|||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
const packageInfo = require('../../../package.json');
|
|
||||||
const ghostVersion = require('../../../core/server/lib/ghost-version');
|
|
||||||
|
|
||||||
const UpdateCheckService = require('../../../core/server/update-check-service');
|
const UpdateCheckService = require('../../../core/server/update-check-service');
|
||||||
|
|
||||||
@ -38,7 +36,6 @@ describe('Update Check', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
requestStub = sinon.stub();
|
requestStub = sinon.stub();
|
||||||
urlForStub = sinon.stub().returns('https://localhost:2368/');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -62,12 +59,13 @@ describe('Update Check', function () {
|
|||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
checkEndpoint: 'https://updates.ghost.org',
|
checkEndpoint: 'https://updates.ghost.org',
|
||||||
isPrivacyDisabled: true
|
siteUrl: 'https://localhost:2368/test',
|
||||||
|
isPrivacyDisabled: true,
|
||||||
|
ghostVersion: '0.8.0'
|
||||||
},
|
},
|
||||||
i18n: i18nStub,
|
i18n: i18nStub,
|
||||||
logging: loggingStub,
|
logging: loggingStub,
|
||||||
request: requestStub,
|
request: requestStub,
|
||||||
ghostVersion,
|
|
||||||
ghostMailer: {
|
ghostMailer: {
|
||||||
send: sinon.stub().resolves()
|
send: sinon.stub().resolves()
|
||||||
}
|
}
|
||||||
@ -78,7 +76,7 @@ describe('Update Check', function () {
|
|||||||
requestStub.calledOnce.should.equal(true);
|
requestStub.calledOnce.should.equal(true);
|
||||||
|
|
||||||
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
||||||
requestStub.args[0][1].query.ghost_version.should.equal(ghostVersion.full);
|
requestStub.args[0][1].query.ghost_version.should.equal('0.8.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('update check won\'t happen if it\'s too early', async function () {
|
it('update check won\'t happen if it\'s too early', async function () {
|
||||||
@ -125,12 +123,13 @@ describe('Update Check', function () {
|
|||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
checkEndpoint: 'https://updates.ghost.org',
|
checkEndpoint: 'https://updates.ghost.org',
|
||||||
isPrivacyDisabled: true
|
siteUrl: 'https://example.com',
|
||||||
|
isPrivacyDisabled: true,
|
||||||
|
ghostVersion: '5.3.4'
|
||||||
},
|
},
|
||||||
i18n: i18nStub,
|
i18n: i18nStub,
|
||||||
logging: loggingStub,
|
logging: loggingStub,
|
||||||
request: requestStub,
|
request: requestStub,
|
||||||
ghostVersion,
|
|
||||||
ghostMailer: {
|
ghostMailer: {
|
||||||
send: sinon.stub().resolves()
|
send: sinon.stub().resolves()
|
||||||
}
|
}
|
||||||
@ -141,7 +140,7 @@ describe('Update Check', function () {
|
|||||||
requestStub.calledOnce.should.equal(true);
|
requestStub.calledOnce.should.equal(true);
|
||||||
|
|
||||||
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
||||||
requestStub.args[0][1].query.ghost_version.should.equal(ghostVersion.full);
|
requestStub.args[0][1].query.ghost_version.should.equal('5.3.4');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -172,14 +171,15 @@ describe('Update Check', function () {
|
|||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
checkEndpoint: 'https://updates.ghost.org',
|
checkEndpoint: 'https://updates.ghost.org',
|
||||||
|
siteUrl: 'https://localhost:2368/test',
|
||||||
isPrivacyDisabled: false,
|
isPrivacyDisabled: false,
|
||||||
env: process.env.NODE_ENV,
|
env: process.env.NODE_ENV,
|
||||||
databaseType: 'mysql'
|
databaseType: 'mysql',
|
||||||
|
ghostVersion: '4.0.0'
|
||||||
},
|
},
|
||||||
i18n: i18nStub,
|
i18n: i18nStub,
|
||||||
logging: loggingStub,
|
logging: loggingStub,
|
||||||
request: requestStub,
|
request: requestStub,
|
||||||
ghostVersion,
|
|
||||||
ghostMailer: {
|
ghostMailer: {
|
||||||
send: sinon.stub().resolves()
|
send: sinon.stub().resolves()
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ describe('Update Check', function () {
|
|||||||
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
requestStub.args[0][0].should.equal('https://updates.ghost.org');
|
||||||
|
|
||||||
const data = requestStub.args[0][1].body;
|
const data = requestStub.args[0][1].body;
|
||||||
data.ghost_version.should.equal(packageInfo.version);
|
data.ghost_version.should.equal('4.0.0');
|
||||||
data.node_version.should.equal(process.versions.node);
|
data.node_version.should.equal(process.versions.node);
|
||||||
data.env.should.equal(process.env.NODE_ENV);
|
data.env.should.equal(process.env.NODE_ENV);
|
||||||
data.database_type.should.match(/sqlite3|mysql/);
|
data.database_type.should.match(/sqlite3|mysql/);
|
||||||
@ -245,7 +245,9 @@ describe('Update Check', function () {
|
|||||||
add: notificationsAPIAddStub
|
add: notificationsAPIAddStub
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
config: {},
|
config: {
|
||||||
|
siteUrl: 'https://localhost:2368/test'
|
||||||
|
},
|
||||||
i18n: i18nStub,
|
i18n: i18nStub,
|
||||||
logging: loggingStub,
|
logging: loggingStub,
|
||||||
request: sinon.stub().resolves({
|
request: sinon.stub().resolves({
|
||||||
@ -253,7 +255,6 @@ describe('Update Check', function () {
|
|||||||
notifications: [notification]
|
notifications: [notification]
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
ghostVersion,
|
|
||||||
ghostMailer: {
|
ghostMailer: {
|
||||||
send: sinon.stub().resolves()
|
send: sinon.stub().resolves()
|
||||||
}
|
}
|
||||||
@ -321,7 +322,6 @@ describe('Update Check', function () {
|
|||||||
request: sinon.stub().resolves({
|
request: sinon.stub().resolves({
|
||||||
body: [notification]
|
body: [notification]
|
||||||
}),
|
}),
|
||||||
ghostVersion,
|
|
||||||
ghostMailer: mailServiceStub
|
ghostMailer: mailServiceStub
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user