From fead0e3dcfa6968fc3b9d8ee5140e9f2ca6e2fda Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 13 Oct 2021 16:37:38 +0200 Subject: [PATCH] Decoupled frontend rss service from the url service refs https://linear.app/tryghost/issue/CORE-103/decouple-internal-frontend-code-from-url-module - We need to decouple all frontend services from URL service as much as possible. "bootstrap" module is now a central point to substitute (proxy really) function previously done by the URL service and this move changes direct usage of URL service to "bootstraps" internal proxy function --- core/frontend/services/rss/generate-feed.js | 4 ++-- test/unit/frontend/services/rss/generate-feed.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/frontend/services/rss/generate-feed.js b/core/frontend/services/rss/generate-feed.js index 87db52ec06..77d0e1f36b 100644 --- a/core/frontend/services/rss/generate-feed.js +++ b/core/frontend/services/rss/generate-feed.js @@ -3,7 +3,7 @@ const Promise = require('bluebird'); const cheerio = require('cheerio'); const RSS = require('rss'); const urlUtils = require('../../../shared/url-utils'); -const urlService = require('../url'); +const bootstrap = require('../routing/bootstrap'); const generateTags = function generateTags(data) { if (data.tags) { @@ -19,7 +19,7 @@ const generateTags = function generateTags(data) { }; const generateItem = function generateItem(post, secure) { - const itemUrl = urlService.getUrlByResourceId(post.id, {secure, absolute: true}); + const itemUrl = bootstrap.internal.getUrlByResourceId(post.id, {secure, absolute: true}); const htmlContent = cheerio.load(post.html || ''); const item = { title: post.title, diff --git a/test/unit/frontend/services/rss/generate-feed.test.js b/test/unit/frontend/services/rss/generate-feed.test.js index 8a2e37e088..2ddc921f5d 100644 --- a/test/unit/frontend/services/rss/generate-feed.test.js +++ b/test/unit/frontend/services/rss/generate-feed.test.js @@ -3,7 +3,7 @@ const sinon = require('sinon'); const _ = require('lodash'); const testUtils = require('../../../../utils'); const configUtils = require('../../../../utils/configUtils'); -const urlService = require('../../../../../core/frontend/services/url'); +const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap'); const generateFeed = require('../../../../../core/frontend/services/rss/generate-feed'); describe('RSS: Generate Feed', function () { @@ -43,7 +43,7 @@ describe('RSS: Generate Feed', function () { }); beforeEach(function () { - sinon.stub(urlService, 'getUrlByResourceId'); + sinon.stub(bootstrap.internal, 'getUrlByResourceId'); baseUrl = '/rss/'; @@ -92,7 +92,7 @@ describe('RSS: Generate Feed', function () { data.posts = posts; _.each(data.posts, function (post) { - urlService.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/'); + bootstrap.internal.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/'); }); generateFeed(baseUrl, data).then(function (xmlData) { @@ -204,7 +204,7 @@ describe('RSS: Generate Feed', function () { data.posts = [posts[0]]; _.each(data.posts, function (post) { - urlService.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/'); + bootstrap.internal.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/'); }); generateFeed(baseUrl, data).then(function (xmlData) {