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 7ce5ab27c3
commit 796e2caaff
2 changed files with 2 additions and 10 deletions

View File

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

View File

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