0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Removed urlFor parameter from UpdateCheckService

refs https://github.com/TryGhost/Team/issues/728

- This is continuation of the previous commit. TLDR: Passing only the necessary API endpoint function makes it easier to reason about what dependencies the UpdateCheckService has to deal with
- Substituted a parameter with already existing 'siteUrl' config value. No need to duplicate work!
This commit is contained in:
Naz 2021-06-02 14:36:53 +04:00
parent bd51dd09db
commit 759f6ed3ba
3 changed files with 3 additions and 12 deletions

View file

@ -38,14 +38,12 @@ class UpdateCheckService {
* @param {string[]} [options.config.notificationGroups] - example values ["migration", "something"]
* @param {string} options.config.siteUrl - Ghost instance URL
* @param {boolean} [options.config.forceUpdate]
* @param {Function} urlFor - function creating a URL for a certain context
*/
constructor({api, config, i18n, logging, urlFor, request, ghostVersion, ghostMailer}) {
constructor({api, config, i18n, logging, request, ghostVersion, ghostMailer}) {
this.api = api;
this.config = config;
this.i18n = i18n;
this.logging = logging;
this.urlFor = urlFor;
this.request = request;
this.ghostVersion = ghostVersion;
this.ghostMailer = ghostMailer;
@ -106,7 +104,7 @@ class UpdateCheckService {
const users = await this.api.users.browse(internal);
const npm = await Promise.promisify(exec)('npm -v');
const blogUrl = this.urlFor('home', true);
const blogUrl = this.config.siteUrl;
const parsedBlogUrl = url.parse(blogUrl);
const blogId = parsedBlogUrl.hostname + parsedBlogUrl.pathname.replace(/\//, '') + hash.value;

View file

@ -43,12 +43,11 @@ module.exports = () => {
checkEndpoint: config.get('updateCheck:url'),
isPrivacyDisabled: config.isPrivacyDisabled('useUpdateCheck'),
notificationGroups: this.config.get('notificationGroups'),
siteUrl: config.get('url'),
siteUrl: urlUtils.urlFor('home', true),
forceUpdate: config.get('updateCheck:forceUpdate')
},
i18n,
logging,
urlFor: urlUtils.urlFor,
request,
ghostVersion,
ghostMailer

View file

@ -13,7 +13,6 @@ describe('Update Check', function () {
let i18nStub;
let loggingStub;
let requestStub;
let urlForStub;
beforeEach(function () {
settingsStub = sinon.stub().resolves({
@ -67,7 +66,6 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -131,7 +129,6 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -181,7 +178,6 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -252,7 +248,6 @@ describe('Update Check', function () {
config: {},
i18n: i18nStub,
logging: loggingStub,
urlFor: urlForStub,
request: sinon.stub().resolves({
body: {
notifications: [notification]
@ -323,7 +318,6 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlFor: urlForStub,
request: sinon.stub().resolves({
body: [notification]
}),