0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/test/unit/frontend/services/routing/bootstrap.test.js
Naz 18344a16e2 Removed event chain caused by settings date update
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events

- The 'settings.timezone.edited' event triggers a roundtrip chain of calls in the frontend routing to the url services. It was all handled by event listeners and handler that clearly don't belong there.
- Extracted event realted listeners/handlers into methods and moved most of the logic to the "bootstrap" module, which soon is going to become a "RoutesManger"
- The result of this refactor - no more events going back and forth between frontend routing and the backend!
2021-10-19 07:29:09 +13:00

74 lines
3.1 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const CollectionRouter = require('../../../../../core/frontend/services/routing/CollectionRouter');
const bootstrap = require('../../../../../core/frontend/services/routing/bootstrap');
const registry = require('../../../../../core/frontend/services/routing/registry');
const RESOURCE_CONFIG = {QUERY: {post: {controller: 'posts', resource: 'posts'}}};
describe('UNIT: services/routing/bootstrap', function () {
let routesUpdatedStub;
beforeEach(function () {
sinon.stub(bootstrap.internal, 'routerCreated').returns();
routesUpdatedStub = sinon.stub(bootstrap.internal, 'routerUpdated').returns();
});
afterEach(function () {
sinon.restore();
});
describe('timezone changes', function () {
describe('no dated permalink', function () {
it('default', function () {
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
bootstrap.handleTimezoneEdit({
attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'Europe/London'}
});
routesUpdatedStub.called.should.be.false();
});
it('tz has not changed', function () {
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/'}, RESOURCE_CONFIG);
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
bootstrap.handleTimezoneEdit({
attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'America/Los_Angeles'}
});
routesUpdatedStub.called.should.be.false();
});
});
describe('with dated permalink', function () {
it('default', function () {
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
bootstrap.handleTimezoneEdit({
attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'Europe/London'}
});
routesUpdatedStub.called.should.be.true();
});
it('tz has not changed', function () {
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:year/:slug/'}, RESOURCE_CONFIG);
sinon.stub(registry, 'getRouterByName').withArgs('CollectionRouter').returns(collectionRouter);
bootstrap.handleTimezoneEdit({
attributes: {value: 'America/Los_Angeles'},
_previousAttributes: {value: 'America/Los_Angeles'}
});
routesUpdatedStub.called.should.be.false();
});
});
});
});