mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Removed bootstrap module dependency from frontend routers
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events - "routerCreated" call was causing a need to create a dependency on the frontend Router level which didn't fit nicely with the refactor of the bootstrap into a class, it's also makes way more sense having it as an independent parameter instead of a call on a module (makes testing way more readable too!)
This commit is contained in:
parent
edd7b09909
commit
098891ee9a
@ -5,7 +5,6 @@ const ParentRouter = require('./ParentRouter');
|
||||
const controllers = require('./controllers');
|
||||
const middlewares = require('./middlewares');
|
||||
const RSSRouter = require('./RSSRouter');
|
||||
const bootstrap = require('./bootstrap');
|
||||
|
||||
/**
|
||||
* @description Collection Router for post resource.
|
||||
@ -13,7 +12,7 @@ const bootstrap = require('./bootstrap');
|
||||
* Fundamental router to define where resources live and how their url structure is.
|
||||
*/
|
||||
class CollectionRouter extends ParentRouter {
|
||||
constructor(mainRoute, object, RESOURCE_CONFIG) {
|
||||
constructor(mainRoute, object, RESOURCE_CONFIG, routerCreated) {
|
||||
super('CollectionRouter');
|
||||
|
||||
this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.post;
|
||||
@ -53,6 +52,7 @@ class CollectionRouter extends ParentRouter {
|
||||
};
|
||||
|
||||
this.context = [this.routerName];
|
||||
this.routerCreated = routerCreated;
|
||||
|
||||
debug(this.name, this.route, this.permalinks);
|
||||
|
||||
@ -89,7 +89,7 @@ class CollectionRouter extends ParentRouter {
|
||||
// REGISTER: permalinks e.g. /:slug/, /podcast/:slug
|
||||
this.mountRoute(this.permalinks.getValue({withUrlOptions: true}), controllers.entry);
|
||||
|
||||
bootstrap.internal.routerCreated(this);
|
||||
this.routerCreated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,16 +2,16 @@ const debug = require('@tryghost/debug')('routing:static-pages-router');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const ParentRouter = require('./ParentRouter');
|
||||
const controllers = require('./controllers');
|
||||
const bootstrap = require('./bootstrap');
|
||||
|
||||
/**
|
||||
* @description Resource: pages
|
||||
*/
|
||||
class StaticPagesRouter extends ParentRouter {
|
||||
constructor(RESOURCE_CONFIG) {
|
||||
constructor(RESOURCE_CONFIG, routerCreated) {
|
||||
super('StaticPagesRouter');
|
||||
|
||||
this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.page;
|
||||
this.routerCreated = routerCreated;
|
||||
|
||||
// @NOTE: Permalink is always /:slug, not configure able
|
||||
this.permalinks = {
|
||||
@ -48,7 +48,7 @@ class StaticPagesRouter extends ParentRouter {
|
||||
// REGISTER: permalink for static pages
|
||||
this.mountRoute(this.permalinks.getValue({withUrlOptions: true}), controllers.entry);
|
||||
|
||||
bootstrap.internal.routerCreated(this);
|
||||
this.routerCreated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,19 +5,19 @@ const RSSRouter = require('./RSSRouter');
|
||||
const controllers = require('./controllers');
|
||||
const middlewares = require('./middlewares');
|
||||
const ParentRouter = require('./ParentRouter');
|
||||
const bootstrap = require('./bootstrap');
|
||||
|
||||
/**
|
||||
* @description Template routes allow you to map individual URLs to specific template files within a Ghost theme
|
||||
*/
|
||||
class StaticRoutesRouter extends ParentRouter {
|
||||
constructor(mainRoute, object) {
|
||||
constructor(mainRoute, object, routerCreated) {
|
||||
super('StaticRoutesRouter');
|
||||
|
||||
this.route = {value: mainRoute};
|
||||
this.templates = object.templates || [];
|
||||
this.data = object.data || {query: {}, router: {}};
|
||||
this.routerName = mainRoute === '/' ? 'index' : mainRoute.replace(/\//g, '');
|
||||
this.routerCreated = routerCreated;
|
||||
|
||||
debug(this.route.value, this.templates);
|
||||
|
||||
@ -62,7 +62,7 @@ class StaticRoutesRouter extends ParentRouter {
|
||||
this.router().param('page', middlewares.pageParam);
|
||||
this.mountRoute(urlUtils.urlJoin(this.route.value, 'page', ':page(\\d+)'), controllers[this.controller]);
|
||||
|
||||
bootstrap.internal.routerCreated(this);
|
||||
this.routerCreated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +98,7 @@ class StaticRoutesRouter extends ParentRouter {
|
||||
// REGISTER: static route
|
||||
this.mountRoute(this.route.value, controllers.static);
|
||||
|
||||
bootstrap.internal.routerCreated(this);
|
||||
this.routerCreated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,14 +5,13 @@ const RSSRouter = require('./RSSRouter');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const controllers = require('./controllers');
|
||||
const middlewares = require('./middlewares');
|
||||
const bootstrap = require('./bootstrap');
|
||||
|
||||
/**
|
||||
* @description Taxonomies are groupings of posts based on a common relation.
|
||||
* Taxonomies do not change the url of a resource.
|
||||
*/
|
||||
class TaxonomyRouter extends ParentRouter {
|
||||
constructor(key, permalinks, RESOURCE_CONFIG) {
|
||||
constructor(key, permalinks, RESOURCE_CONFIG, routerCreated) {
|
||||
super('Taxonomy');
|
||||
|
||||
this.taxonomyKey = key;
|
||||
@ -26,6 +25,8 @@ class TaxonomyRouter extends ParentRouter {
|
||||
return this.permalinks.value;
|
||||
};
|
||||
|
||||
this.routerCreated = routerCreated;
|
||||
|
||||
debug(this.permalinks);
|
||||
|
||||
this._registerRoutes();
|
||||
@ -58,7 +59,7 @@ class TaxonomyRouter extends ParentRouter {
|
||||
this.mountRoute(urlUtils.urlJoin(this.permalinks.value, 'edit'), this._redirectEditOption.bind(this));
|
||||
}
|
||||
|
||||
bootstrap.internal.routerCreated(this);
|
||||
this.routerCreated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
8
core/frontend/services/routing/bootstrap.js
vendored
8
core/frontend/services/routing/bootstrap.js
vendored
@ -91,25 +91,25 @@ const start = (apiVersion, routerSettings) => {
|
||||
registry.setRouter('previewRouter', previewRouter);
|
||||
|
||||
_.each(routerSettings.routes, (value, key) => {
|
||||
const staticRoutesRouter = new StaticRoutesRouter(key, value);
|
||||
const staticRoutesRouter = new StaticRoutesRouter(key, value, this.internal.routerCreated);
|
||||
siteRouter.mountRouter(staticRoutesRouter.router());
|
||||
|
||||
registry.setRouter(staticRoutesRouter.identifier, staticRoutesRouter);
|
||||
});
|
||||
|
||||
_.each(routerSettings.collections, (value, key) => {
|
||||
const collectionRouter = new CollectionRouter(key, value, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter(key, value, RESOURCE_CONFIG, this.internal.routerCreated);
|
||||
siteRouter.mountRouter(collectionRouter.router());
|
||||
registry.setRouter(collectionRouter.identifier, collectionRouter);
|
||||
});
|
||||
|
||||
const staticPagesRouter = new StaticPagesRouter(RESOURCE_CONFIG);
|
||||
const staticPagesRouter = new StaticPagesRouter(RESOURCE_CONFIG, this.internal.routerCreated);
|
||||
siteRouter.mountRouter(staticPagesRouter.router());
|
||||
|
||||
registry.setRouter('staticPagesRouter', staticPagesRouter);
|
||||
|
||||
_.each(routerSettings.taxonomies, (value, key) => {
|
||||
const taxonomyRouter = new TaxonomyRouter(key, value, RESOURCE_CONFIG);
|
||||
const taxonomyRouter = new TaxonomyRouter(key, value, RESOURCE_CONFIG, this.internal.routerCreated);
|
||||
siteRouter.mountRouter(taxonomyRouter.router());
|
||||
|
||||
registry.setRouter(taxonomyRouter.identifier, taxonomyRouter);
|
||||
|
@ -1,7 +1,6 @@
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const express = require('../../../../../core/shared/express')._express;
|
||||
const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap');
|
||||
const events = require('../../../../../core/server/lib/common/events');
|
||||
const controllers = require('../../../../../core/frontend/services/routing/controllers');
|
||||
const CollectionRouter = require('../../../../../core/frontend/services/routing/CollectionRouter');
|
||||
@ -11,11 +10,12 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
let req;
|
||||
let res;
|
||||
let next;
|
||||
let routerCreatedSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
sinon.stub(events, 'emit');
|
||||
sinon.stub(events, 'on');
|
||||
sinon.stub(bootstrap.internal, 'routerCreated');
|
||||
routerCreatedSpy = sinon.spy();
|
||||
|
||||
sinon.spy(CollectionRouter.prototype, 'mountRoute');
|
||||
sinon.spy(CollectionRouter.prototype, 'mountRouter');
|
||||
@ -35,7 +35,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
|
||||
describe('instantiate', function () {
|
||||
it('default', function () {
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
should.exist(collectionRouter.router);
|
||||
|
||||
@ -44,8 +44,8 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
collectionRouter.templates.should.eql([]);
|
||||
collectionRouter.getPermalinks().getValue().should.eql('/:slug/');
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(collectionRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(collectionRouter).should.be.true();
|
||||
|
||||
collectionRouter.mountRoute.callCount.should.eql(3);
|
||||
express.Router.param.callCount.should.eql(2);
|
||||
@ -68,9 +68,9 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
});
|
||||
|
||||
it('router name', function () {
|
||||
const collectionRouter1 = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter2 = new CollectionRouter('/podcast/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter3 = new CollectionRouter('/hello/world/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter1 = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
const collectionRouter2 = new CollectionRouter('/podcast/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
const collectionRouter3 = new CollectionRouter('/hello/world/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
collectionRouter1.routerName.should.eql('index');
|
||||
collectionRouter2.routerName.should.eql('podcast');
|
||||
@ -82,7 +82,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
});
|
||||
|
||||
it('collection lives under /blog/', function () {
|
||||
const collectionRouter = new CollectionRouter('/blog/', {permalink: '/blog/:year/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/blog/', {permalink: '/blog/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
should.exist(collectionRouter.router);
|
||||
|
||||
@ -91,8 +91,8 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
collectionRouter.templates.should.eql([]);
|
||||
collectionRouter.getPermalinks().getValue().should.eql('/blog/:year/:slug/');
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(collectionRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(collectionRouter).should.be.true();
|
||||
|
||||
collectionRouter.mountRoute.callCount.should.eql(3);
|
||||
|
||||
@ -114,13 +114,13 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
});
|
||||
|
||||
it('with custom filter', function () {
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/', filter: 'featured:true'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/', filter: 'featured:true'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
collectionRouter.getFilter().should.eql('featured:true');
|
||||
});
|
||||
|
||||
it('with templates', function () {
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/', templates: ['home', 'index']}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/', templates: ['home', 'index']}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
// they are getting reversed because we unshift the templates in the helper
|
||||
collectionRouter.templates.should.eql(['index', 'home']);
|
||||
@ -129,7 +129,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
|
||||
describe('fn: _prepareEntriesContext', function () {
|
||||
it('index collection', function () {
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
collectionRouter._prepareEntriesContext(req, res, next);
|
||||
|
||||
@ -157,7 +157,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
|
||||
order: 'published asc',
|
||||
limit: 19,
|
||||
templates: ['home', 'index']
|
||||
}, RESOURCE_CONFIG);
|
||||
}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
|
||||
collectionRouter._prepareEntriesContext(req, res, next);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap');
|
||||
const controllers = require('../../../../../core/frontend/services/routing/controllers');
|
||||
const StaticRoutesRouter = require('../../../../../core/frontend/services/routing/StaticRoutesRouter');
|
||||
const configUtils = require('../../../../utils/configUtils');
|
||||
@ -9,13 +8,14 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
let req;
|
||||
let res;
|
||||
let next;
|
||||
let routerCreatedSpy;
|
||||
|
||||
afterEach(function () {
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
sinon.stub(bootstrap.internal, 'routerCreated');
|
||||
routerCreatedSpy = sinon.spy();
|
||||
|
||||
sinon.spy(StaticRoutesRouter.prototype, 'mountRoute');
|
||||
sinon.spy(StaticRoutesRouter.prototype, 'mountRouter');
|
||||
@ -33,7 +33,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
|
||||
describe('static routes', function () {
|
||||
it('instantiate: default', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/about/', {templates: ['test']});
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/about/', {templates: ['test']}, routerCreatedSpy);
|
||||
should.exist(staticRoutesRouter.router);
|
||||
|
||||
should.not.exist(staticRoutesRouter.getFilter());
|
||||
@ -41,8 +41,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
|
||||
staticRoutesRouter.templates.should.eql(['test']);
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(staticRoutesRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(staticRoutesRouter).should.be.true();
|
||||
|
||||
staticRoutesRouter.mountRoute.callCount.should.eql(1);
|
||||
|
||||
@ -55,7 +55,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/about/', {
|
||||
data: {query: {}, router: {}},
|
||||
filter: 'tag:test'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
should.exist(staticRoutesRouter.router);
|
||||
|
||||
@ -63,8 +63,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
should.not.exist(staticRoutesRouter.getFilter());
|
||||
staticRoutesRouter.templates.should.eql([]);
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(staticRoutesRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(staticRoutesRouter).should.be.true();
|
||||
|
||||
staticRoutesRouter.mountRoute.callCount.should.eql(1);
|
||||
|
||||
@ -74,7 +74,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
});
|
||||
|
||||
it('fn: _prepareStaticRouteContext', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/about/', {templates: []});
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/about/', {templates: []}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareStaticRouteContext(req, res, next);
|
||||
next.called.should.be.true();
|
||||
@ -91,7 +91,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
});
|
||||
|
||||
it('fn: _prepareStaticRouteContext', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/', {templates: []});
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/', {templates: []}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareStaticRouteContext(req, res, next);
|
||||
next.called.should.be.true();
|
||||
@ -114,7 +114,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
controller: 'channel',
|
||||
data: {query: {}, router: {}},
|
||||
filter: 'tag:test'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
should.exist(staticRoutesRouter.router);
|
||||
|
||||
@ -123,8 +123,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
staticRoutesRouter.templates.should.eql([]);
|
||||
should.exist(staticRoutesRouter.data);
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(staticRoutesRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(staticRoutesRouter).should.be.true();
|
||||
|
||||
staticRoutesRouter.mountRoute.callCount.should.eql(2);
|
||||
|
||||
@ -141,7 +141,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/channel/', {
|
||||
controller: 'channel',
|
||||
filter: 'tag:test'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
should.exist(staticRoutesRouter.router);
|
||||
|
||||
@ -150,8 +150,8 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
|
||||
staticRoutesRouter.templates.should.eql([]);
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(staticRoutesRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(staticRoutesRouter).should.be.true();
|
||||
|
||||
staticRoutesRouter.mountRoute.callCount.should.eql(2);
|
||||
|
||||
@ -168,7 +168,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/channel/', {
|
||||
controller: 'channel',
|
||||
data: {query: {}, router: {}}
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
should.not.exist(staticRoutesRouter.getFilter());
|
||||
});
|
||||
@ -180,7 +180,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
controller: 'channel',
|
||||
data: {query: {}, router: {}},
|
||||
filter: 'author:michi'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter.mountRoute.callCount.should.eql(2);
|
||||
|
||||
@ -200,7 +200,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
controller: 'channel',
|
||||
data: {query: {}, router: {}},
|
||||
filter: 'tag:test'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareChannelContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
@ -220,7 +220,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/nothingcomparestoyou/', {
|
||||
controller: 'channel',
|
||||
data: {query: {type: 'read'}, router: {}}
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareChannelContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
@ -240,7 +240,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
const staticRoutesRouter = new StaticRoutesRouter('/channel/', {
|
||||
controller: 'channel',
|
||||
filter: 'tag:test'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareChannelContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
@ -262,7 +262,7 @@ describe('UNIT - services/routing/StaticRoutesRouter', function () {
|
||||
filter: 'tag:test',
|
||||
limit: 2,
|
||||
order: 'published_at asc'
|
||||
});
|
||||
}, routerCreatedSpy);
|
||||
|
||||
staticRoutesRouter._prepareChannelContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
|
@ -1,7 +1,6 @@
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const settingsCache = require('../../../../../core/shared/settings-cache');
|
||||
const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap');
|
||||
const controllers = require('../../../../../core/frontend/services/routing/controllers');
|
||||
const TaxonomyRouter = require('../../../../../core/frontend/services/routing/TaxonomyRouter');
|
||||
const RESOURCE_CONFIG_V2 = require('../../../../../core/frontend/services/routing/config/v2');
|
||||
@ -12,11 +11,12 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
let req;
|
||||
let res;
|
||||
let next;
|
||||
let routerCreatedSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
sinon.stub(settingsCache, 'get').withArgs('permalinks').returns('/:slug/');
|
||||
|
||||
sinon.stub(bootstrap.internal, 'routerCreated');
|
||||
routerCreatedSpy = sinon.spy();
|
||||
|
||||
sinon.spy(TaxonomyRouter.prototype, 'mountRoute');
|
||||
sinon.spy(TaxonomyRouter.prototype, 'mountRouter');
|
||||
@ -33,7 +33,7 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
});
|
||||
|
||||
it('instantiate', function () {
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/');
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', {}, routerCreatedSpy);
|
||||
|
||||
should.exist(taxonomyRouter.router);
|
||||
should.exist(taxonomyRouter.rssRouter);
|
||||
@ -41,8 +41,8 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
taxonomyRouter.taxonomyKey.should.eql('tag');
|
||||
taxonomyRouter.getPermalinks().getValue().should.eql('/tag/:slug/');
|
||||
|
||||
bootstrap.internal.routerCreated.calledOnce.should.be.true();
|
||||
bootstrap.internal.routerCreated.calledWith(taxonomyRouter).should.be.true();
|
||||
routerCreatedSpy.calledOnce.should.be.true();
|
||||
routerCreatedSpy.calledWith(taxonomyRouter).should.be.true();
|
||||
|
||||
taxonomyRouter.mountRouter.callCount.should.eql(1);
|
||||
taxonomyRouter.mountRouter.args[0][0].should.eql('/tag/:slug/');
|
||||
@ -64,7 +64,7 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
});
|
||||
|
||||
it('v2:fn: _prepareContext', function () {
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V2);
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V2, routerCreatedSpy);
|
||||
taxonomyRouter._prepareContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
|
||||
@ -82,7 +82,7 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
});
|
||||
|
||||
it('canary:fn: _prepareContext', function () {
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_CANARY);
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_CANARY, routerCreatedSpy);
|
||||
taxonomyRouter._prepareContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
|
||||
@ -100,7 +100,7 @@ describe('UNIT - services/routing/TaxonomyRouter', function () {
|
||||
});
|
||||
|
||||
it('v3:fn: _prepareContext', function () {
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V3);
|
||||
const taxonomyRouter = new TaxonomyRouter('tag', '/tag/:slug/', RESOURCE_CONFIG_V3, routerCreatedSpy);
|
||||
taxonomyRouter._prepareContext(req, res, next);
|
||||
next.calledOnce.should.eql(true);
|
||||
|
||||
|
@ -8,9 +8,10 @@ const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}
|
||||
|
||||
describe('UNIT: services/routing/bootstrap', function () {
|
||||
let routesUpdatedStub;
|
||||
let routerCreatedSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
sinon.stub(bootstrap.internal, 'routerCreated').returns();
|
||||
routerCreatedSpy = sinon.spy();
|
||||
routesUpdatedStub = sinon.stub(bootstrap.internal, 'routerUpdated').returns();
|
||||
});
|
||||
|
||||
@ -21,7 +22,7 @@ describe('UNIT: services/routing/bootstrap', function () {
|
||||
describe('timezone changes', function () {
|
||||
describe('no dated permalink', function () {
|
||||
it('default', function () {
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
||||
|
||||
bootstrap.handleTimezoneEdit({
|
||||
@ -33,7 +34,7 @@ describe('UNIT: services/routing/bootstrap', function () {
|
||||
});
|
||||
|
||||
it('tz has not changed', function () {
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
||||
|
||||
bootstrap.handleTimezoneEdit({
|
||||
@ -47,7 +48,7 @@ describe('UNIT: services/routing/bootstrap', function () {
|
||||
|
||||
describe('with dated permalink', function () {
|
||||
it('default', function () {
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
||||
|
||||
bootstrap.handleTimezoneEdit({
|
||||
@ -59,7 +60,7 @@ describe('UNIT: services/routing/bootstrap', function () {
|
||||
});
|
||||
|
||||
it('tz has not changed', function () {
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
|
||||
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG, routerCreatedSpy);
|
||||
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
|
||||
|
||||
bootstrap.handleTimezoneEdit({
|
||||
|
Loading…
Reference in New Issue
Block a user