Fixed loadRouteSettingsSync stubs

refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- Because "loadRouteSettingsSync" method is now a getter function these stubs had to be changed to use a different syntax
- It's a lot of maintenance to do such renames, so if someone has to touch this exact place again it might be worth abstracting this mocking into a separate utility of some sort.
This commit is contained in:
Naz 2021-11-23 15:21:55 +04:00 committed by naz
parent 2fed8dbbd5
commit f0b8e9693f
3 changed files with 67 additions and 66 deletions

View File

@ -25,6 +25,7 @@ describe('Integration - Web - Site canary', function () {
localUtils.defaultMocks(sinon, {amp: true});
localUtils.overrideGhostConfig(configUtils);
await routeSettingsService.init();
app = await localUtils.initGhost();
});
@ -361,7 +362,7 @@ describe('Integration - Web - Site canary', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/': {templates: ['home']}
},
@ -382,7 +383,7 @@ describe('Integration - Web - Site canary', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -486,7 +487,7 @@ describe('Integration - Web - Site canary', function () {
describe('no collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/something/': {
templates: ['something']
@ -494,7 +495,7 @@ describe('Integration - Web - Site canary', function () {
},
collections: {},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -533,7 +534,7 @@ describe('Integration - Web - Site canary', function () {
describe('static permalink route', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -548,7 +549,7 @@ describe('Integration - Web - Site canary', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -633,7 +634,7 @@ describe('Integration - Web - Site canary', function () {
describe('primary author permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -643,7 +644,7 @@ describe('Integration - Web - Site canary', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -712,7 +713,7 @@ describe('Integration - Web - Site canary', function () {
describe('primary tag permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -722,7 +723,7 @@ describe('Integration - Web - Site canary', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -806,7 +807,7 @@ describe('Integration - Web - Site canary', function () {
describe('collection/routes with data key', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/my-page/': {
data: {
@ -873,7 +874,7 @@ describe('Integration - Web - Site canary', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -971,7 +972,7 @@ describe('Integration - Web - Site canary', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -983,7 +984,7 @@ describe('Integration - Web - Site canary', function () {
permalink: '/magic/:slug/'
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1034,7 +1035,7 @@ describe('Integration - Web - Site canary', function () {
describe('two templates', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1043,7 +1044,7 @@ describe('Integration - Web - Site canary', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1082,7 +1083,7 @@ describe('Integration - Web - Site canary', function () {
describe('home.hbs priority', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1095,7 +1096,7 @@ describe('Integration - Web - Site canary', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -1154,7 +1155,7 @@ describe('Integration - Web - Site canary', function () {
before(async function () {
localUtils.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/channel1/': {
controller: 'channel',
@ -1274,7 +1275,7 @@ describe('Integration - Web - Site canary', function () {
tag: '/tag/:slug/',
author: '/author/:slug/'
}
});
}));
app = await localUtils.initGhost();
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
@ -1483,7 +1484,7 @@ describe('Integration - Web - Site canary', function () {
describe('extended routes.yaml (5): rss override', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/podcast/rss/': {
templates: ['podcast/rss'],
@ -1515,7 +1516,7 @@ describe('Integration - Web - Site canary', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});

View File

@ -361,7 +361,7 @@ describe('Integration - Web - Site v2', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/': {templates: ['home']}
},
@ -382,7 +382,7 @@ describe('Integration - Web - Site v2', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -486,13 +486,13 @@ describe('Integration - Web - Site v2', function () {
describe('no collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/something/': {templates: ['something']}
},
collections: {},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -531,7 +531,7 @@ describe('Integration - Web - Site v2', function () {
describe('static permalink route', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -546,7 +546,7 @@ describe('Integration - Web - Site v2', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -631,7 +631,7 @@ describe('Integration - Web - Site v2', function () {
describe('primary author permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -641,7 +641,7 @@ describe('Integration - Web - Site v2', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -710,7 +710,7 @@ describe('Integration - Web - Site v2', function () {
describe('primary tag permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -720,7 +720,7 @@ describe('Integration - Web - Site v2', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -804,7 +804,7 @@ describe('Integration - Web - Site v2', function () {
describe('collection/routes with data key', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/my-page/': {
data: {
@ -871,7 +871,7 @@ describe('Integration - Web - Site v2', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -969,7 +969,7 @@ describe('Integration - Web - Site v2', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -981,7 +981,7 @@ describe('Integration - Web - Site v2', function () {
permalink: '/magic/:slug/'
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1035,7 +1035,7 @@ describe('Integration - Web - Site v2', function () {
describe('two templates', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1044,7 +1044,7 @@ describe('Integration - Web - Site v2', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1083,7 +1083,7 @@ describe('Integration - Web - Site v2', function () {
describe('home.hbs priority', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1096,7 +1096,7 @@ describe('Integration - Web - Site v2', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -1158,7 +1158,7 @@ describe('Integration - Web - Site v2', function () {
before(async function () {
localUtils.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/channel1/': {
controller: 'channel',
@ -1278,7 +1278,7 @@ describe('Integration - Web - Site v2', function () {
tag: '/tag/:slug/',
author: '/author/:slug/'
}
});
}));
app = await localUtils.initGhost();
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
@ -1487,7 +1487,7 @@ describe('Integration - Web - Site v2', function () {
describe('extended routes.yaml (5): rss override', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/podcast/rss/': {
templates: ['podcast/rss'],
@ -1519,7 +1519,7 @@ describe('Integration - Web - Site v2', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});

View File

@ -361,7 +361,7 @@ describe('Integration - Web - Site v3', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/': {
templates: ['home']
@ -384,7 +384,7 @@ describe('Integration - Web - Site v3', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -488,13 +488,13 @@ describe('Integration - Web - Site v3', function () {
describe('no collections', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/something/': {templates: ['something']}
},
collections: {},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -533,7 +533,7 @@ describe('Integration - Web - Site v3', function () {
describe('static permalink route', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -548,7 +548,7 @@ describe('Integration - Web - Site v3', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -633,7 +633,7 @@ describe('Integration - Web - Site v3', function () {
describe('primary author permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -643,7 +643,7 @@ describe('Integration - Web - Site v3', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -712,7 +712,7 @@ describe('Integration - Web - Site v3', function () {
describe('primary tag permalink', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -722,7 +722,7 @@ describe('Integration - Web - Site v3', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -805,7 +805,7 @@ describe('Integration - Web - Site v3', function () {
describe('collection/routes with data key', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/my-page/': {
data: {
@ -872,7 +872,7 @@ describe('Integration - Web - Site v3', function () {
tag: '/categories/:slug/',
author: '/authors/:slug/'
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -970,7 +970,7 @@ describe('Integration - Web - Site v3', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -982,7 +982,7 @@ describe('Integration - Web - Site v3', function () {
permalink: '/magic/:slug/'
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1036,7 +1036,7 @@ describe('Integration - Web - Site v3', function () {
describe('two templates', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1045,7 +1045,7 @@ describe('Integration - Web - Site v3', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon);
@ -1084,7 +1084,7 @@ describe('Integration - Web - Site v3', function () {
describe('home.hbs priority', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {},
collections: {
@ -1097,7 +1097,7 @@ describe('Integration - Web - Site v3', function () {
templates: ['something', 'default']
}
}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
@ -1159,7 +1159,7 @@ describe('Integration - Web - Site v3', function () {
before(async function () {
localUtils.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/channel1/': {
controller: 'channel',
@ -1279,7 +1279,7 @@ describe('Integration - Web - Site v3', function () {
tag: '/tag/:slug/',
author: '/author/:slug/'
}
});
}));
app = await localUtils.initGhost();
@ -1489,7 +1489,7 @@ describe('Integration - Web - Site v3', function () {
describe('extended routes.yaml (5): rss override', function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').get(() => () => ({
routes: {
'/about/': 'about',
'/podcast/rss/': {
@ -1522,7 +1522,7 @@ describe('Integration - Web - Site v3', function () {
},
taxonomies: {}
});
}));
localUtils.urlService.resetGenerators();
localUtils.defaultMocks(sinon, {theme: 'test-theme'});