Limited the API surface of the 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
- Limited urlUtils to only one function as that's all the UpdateCheck uses. Next step will be removing the function completely as and passing a 'blogURL' as a config value (way better readability this way)
This commit is contained in:
Naz 2021-06-02 14:31:07 +04:00
parent 94700863a4
commit 7ce5ab27c3
2 changed files with 11 additions and 12 deletions

View File

@ -38,13 +38,14 @@ 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, urlUtils, request, ghostVersion, ghostMailer}) {
constructor({api, config, i18n, logging, urlFor, request, ghostVersion, ghostMailer}) {
this.api = api;
this.config = config;
this.i18n = i18n;
this.logging = logging;
this.urlUtils = urlUtils;
this.urlFor = urlFor;
this.request = request;
this.ghostVersion = ghostVersion;
this.ghostMailer = ghostMailer;
@ -105,7 +106,7 @@ class UpdateCheckService {
const users = await this.api.users.browse(internal);
const npm = await Promise.promisify(exec)('npm -v');
const blogUrl = this.urlUtils.urlFor('home', true);
const blogUrl = this.urlFor('home', true);
const parsedBlogUrl = url.parse(blogUrl);
const blogId = parsedBlogUrl.hostname + parsedBlogUrl.pathname.replace(/\//, '') + hash.value;

View File

@ -2,7 +2,6 @@ const should = require('should');
const sinon = require('sinon');
const moment = require('moment');
const uuid = require('uuid');
const urlUtils = require('../../utils/urlUtils');
const packageInfo = require('../../../package.json');
const ghostVersion = require('../../../core/server/lib/ghost-version');
@ -14,7 +13,7 @@ describe('Update Check', function () {
let i18nStub;
let loggingStub;
let requestStub;
let urlUtilsStub;
let urlForStub;
beforeEach(function () {
settingsStub = sinon.stub().resolves({
@ -40,12 +39,11 @@ describe('Update Check', function () {
};
requestStub = sinon.stub();
urlUtilsStub = urlUtils.stubUrlUtilsFromConfig();
urlForStub = sinon.stub().returns('https://localhost:2368/');
});
afterEach(function () {
sinon.restore();
urlUtils.restore();
});
describe('UpdateCheck execution', function () {
@ -69,7 +67,7 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlUtils: urlUtilsStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -133,7 +131,7 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlUtils: urlUtilsStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -183,7 +181,7 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlUtils: urlUtilsStub,
urlFor: urlForStub,
request: requestStub,
ghostVersion,
ghostMailer: {
@ -254,7 +252,7 @@ describe('Update Check', function () {
config: {},
i18n: i18nStub,
logging: loggingStub,
urlUtils: urlUtilsStub,
urlFor: urlForStub,
request: sinon.stub().resolves({
body: {
notifications: [notification]
@ -325,7 +323,7 @@ describe('Update Check', function () {
},
i18n: i18nStub,
logging: loggingStub,
urlUtils: urlUtilsStub,
urlFor: urlForStub,
request: sinon.stub().resolves({
body: [notification]
}),