Ghost/test/unit/services/settings/validate_spec.js

2343 lines
83 KiB
JavaScript
Raw Normal View History

const should = require('should');
const sinon = require('sinon');
const errors = require('@tryghost/errors');
const themeEngine = require('../../../../core/frontend/services/theme-engine');
const validate = require('../../../../core/frontend/services/settings/validate');
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
should.equal(true, true);
describe('UNIT: services/settings/validate', function () {
let apiVersion;
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
before(function () {
sinon.stub(themeEngine, 'getActive').returns({
engine: () => {
return apiVersion;
}
});
});
after(function () {
sinon.restore();
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});
describe('v2', function () {
before(function () {
apiVersion = 'v2';
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('no type definitions / empty yaml file', function () {
const object = validate({});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
object.should.eql({collections: {}, routes: {}, taxonomies: {}});
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error when using :\w+ notiation in collection', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/magic/{slug}/'
},
'/': {
permalink: '/:slug/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when using :\w+ notiation in taxonomies', function () {
try {
validate({
taxonomies: {
tag: '/categories/:slug/'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when using an undefined taxonomy', function () {
try {
validate({
taxonomies: {
sweet_baked_good: '/patisserie/{slug}'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when permalink is missing (collection)', function () {
try {
validate({
collections: {
permalink: '/{slug}/'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
about: 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'/about': 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'about/': 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'magic/': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
magic: {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('no validation error for routes', function () {
validate({
routes: {
'/': 'home'
}
});
});
it('no validation error for / collection', function () {
validate({
collections: {
'/': {
permalink: '/{primary_tag}/{slug}/'
}
}
});
});
it('transforms {.*} notation into :\w+', function () {
const object = validate({
collections: {
'/magic/': {
permalink: '/magic/{year}/{slug}/'
},
'/': {
permalink: '/{slug}/'
}
},
taxonomies: {
tag: '/tags/{slug}/',
author: '/authors/{slug}/'
}
});
object.should.eql({
routes: {},
taxonomies: {
tag: '/tags/:slug/',
author: '/authors/:slug/'
},
collections: {
'/magic/': {
permalink: '/magic/:year/:slug/',
templates: []
},
'/': {
permalink: '/:slug/',
templates: []
}
}
});
});
describe('template definitions', function () {
it('single value', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: 'me'
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: 'test'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
it('array', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: ['me']
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: ['test']
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
});
describe('data definitions', function () {
it('shortform', function () {
const object = validate({
routes: {
'/food/': {
data: 'tag.food'
},
'/music/': {
data: 'tag.music'
},
'/ghost/': {
data: 'author.ghost'
},
'/sleep/': {
data: {
bed: 'tag.bed',
dream: 'tag.dream'
}
},
'/lala/': {
data: 'author.carsten'
}
},
collections: {
'/more/': {
permalink: '/{slug}/',
data: {
home: 'page.home'
}
},
'/podcast/': {
permalink: '/podcast/{slug}/',
data: {
something: 'tag.something'
}
},
'/': {
permalink: '/{slug}/',
data: 'tag.sport'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'food',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'food'}]
}
},
templates: []
},
'/ghost/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'ghost'
}
}
},
router: {
authors: [{redirect: true, slug: 'ghost'}]
}
},
templates: []
},
'/music/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'music',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'music'}]
}
},
templates: []
},
'/sleep/': {
data: {
query: {
bed: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'bed',
visibility: 'public'
}
},
dream: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'dream',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'bed'}, {redirect: true, slug: 'dream'}]
}
},
templates: []
},
'/lala/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'carsten'
}
}
},
router: {
authors: [{redirect: true, slug: 'carsten'}]
}
},
templates: []
}
},
collections: {
'/more/': {
permalink: '/:slug/',
data: {
query: {
home: {
controller: 'pagesPublic',
resource: 'pages',
type: 'read',
options: {
slug: 'home'
}
}
},
router: {
pages: [{redirect: true, slug: 'home'}]
}
},
templates: []
},
'/podcast/': {
permalink: '/podcast/:slug/',
data: {
query: {
something: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'something',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'something'}]
}
},
templates: []
},
'/': {
permalink: '/:slug/',
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'sport',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'sport'}]
}
},
templates: []
}
}
});
});
it('longform', function () {
const object = validate({
routes: {
'/food/': {
data: {
food: {
resource: 'posts',
type: 'browse'
}
}
},
'/wellness/': {
data: {
posts: {
resource: 'posts',
type: 'read',
redirect: false
}
}
},
'/partyparty/': {
data: {
people: {
resource: 'authors',
type: 'read',
slug: 'djgutelaune',
redirect: true
}
}
}
},
collections: {
'/yoga/': {
permalink: '/{slug}/',
data: {
gym: {
resource: 'posts',
type: 'read',
slug: 'ups',
status: 'draft'
}
}
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
food: {
controller: 'postsPublic',
resource: 'posts',
type: 'browse',
options: {}
}
},
router: {
posts: [{redirect: true}]
}
},
templates: []
},
'/wellness/': {
data: {
query: {
posts: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: '%s'
}
}
},
router: {
posts: [{redirect: false}]
}
},
templates: []
},
'/partyparty/': {
data: {
query: {
people: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'djgutelaune'
}
}
},
router: {
authors: [{redirect: true, slug: 'djgutelaune'}]
}
},
templates: []
}
},
collections: {
'/yoga/': {
permalink: '/:slug/',
data: {
query: {
gym: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: 'ups',
status: 'draft'
}
}
},
router: {
posts: [{redirect: true, slug: 'ups'}]
}
},
templates: []
}
}
});
});
it('errors: data shortform incorrect', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: 'tag:test'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform resource is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
type: 'edit'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform type is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'subscribers'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform name is author', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
author: {
resource: 'users'
}
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform does not use a custom name at all', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'users'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
});
});
describe('canary', function () {
before(function () {
apiVersion = 'canary';
});
it('no type definitions / empty yaml file', function () {
const object = validate({});
object.should.eql({collections: {}, routes: {}, taxonomies: {}});
});
it('throws error when using :\w+ notiation in collection', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/magic/{slug}/'
},
'/': {
permalink: '/:slug/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when using :\w+ notiation in taxonomies', function () {
try {
validate({
taxonomies: {
tag: '/categories/:slug/'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when using an undefined taxonomy', function () {
try {
validate({
taxonomies: {
sweet_baked_good: '/patisserie/{slug}'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when permalink is missing (collection)', function () {
try {
validate({
collections: {
permalink: '/{slug}/'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
about: 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'/about': 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'about/': 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'magic/': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
magic: {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('no validation error for routes', function () {
validate({
routes: {
'/': 'home'
}
});
});
it('no validation error for / collection', function () {
validate({
collections: {
'/': {
permalink: '/{primary_tag}/{slug}/'
}
}
});
});
it('transforms {.*} notation into :\w+', function () {
const object = validate({
collections: {
'/magic/': {
permalink: '/magic/{year}/{slug}/'
},
'/': {
permalink: '/{slug}/'
}
},
taxonomies: {
tag: '/tags/{slug}/',
author: '/authors/{slug}/'
}
});
object.should.eql({
routes: {},
taxonomies: {
tag: '/tags/:slug/',
author: '/authors/:slug/'
},
collections: {
'/magic/': {
permalink: '/magic/:year/:slug/',
templates: []
},
'/': {
permalink: '/:slug/',
templates: []
}
}
});
});
describe('template definitions', function () {
it('single value', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: 'me'
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: 'test'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
it('array', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: ['me']
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: ['test']
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
});
describe('data definitions', function () {
it('shortform', function () {
const object = validate({
routes: {
'/food/': {
data: 'tag.food'
},
'/music/': {
data: 'tag.music'
},
'/ghost/': {
data: 'author.ghost'
},
'/sleep/': {
data: {
bed: 'tag.bed',
dream: 'tag.dream'
}
},
'/lala/': {
data: 'author.carsten'
}
},
collections: {
'/more/': {
permalink: '/{slug}/',
data: {
home: 'page.home'
}
},
'/podcast/': {
permalink: '/podcast/{slug}/',
data: {
something: 'tag.something'
}
},
'/': {
permalink: '/{slug}/',
data: 'tag.sport'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'food',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'food'}]
}
},
templates: []
},
'/ghost/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'ghost'
}
}
},
router: {
authors: [{redirect: true, slug: 'ghost'}]
}
},
templates: []
},
'/music/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'music',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'music'}]
}
},
templates: []
},
'/sleep/': {
data: {
query: {
bed: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'bed',
visibility: 'public'
}
},
dream: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'dream',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'bed'}, {redirect: true, slug: 'dream'}]
}
},
templates: []
},
'/lala/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'carsten'
}
}
},
router: {
authors: [{redirect: true, slug: 'carsten'}]
}
},
templates: []
}
},
collections: {
'/more/': {
permalink: '/:slug/',
data: {
query: {
home: {
controller: 'pagesPublic',
resource: 'pages',
type: 'read',
options: {
slug: 'home'
}
}
},
router: {
pages: [{redirect: true, slug: 'home'}]
}
},
templates: []
},
'/podcast/': {
permalink: '/podcast/:slug/',
data: {
query: {
something: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'something',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'something'}]
}
},
templates: []
},
'/': {
permalink: '/:slug/',
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'sport',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'sport'}]
}
},
templates: []
}
}
});
});
it('longform', function () {
const object = validate({
routes: {
'/food/': {
data: {
food: {
resource: 'posts',
type: 'browse'
}
}
},
'/wellness/': {
data: {
posts: {
resource: 'posts',
type: 'read',
redirect: false
}
}
},
'/partyparty/': {
data: {
people: {
resource: 'authors',
type: 'read',
slug: 'djgutelaune',
redirect: true
}
}
}
},
collections: {
'/yoga/': {
permalink: '/{slug}/',
data: {
gym: {
resource: 'posts',
type: 'read',
slug: 'ups',
status: 'draft'
}
}
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
food: {
controller: 'postsPublic',
resource: 'posts',
type: 'browse',
options: {}
}
},
router: {
posts: [{redirect: true}]
}
},
templates: []
},
'/wellness/': {
data: {
query: {
posts: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: '%s'
}
}
},
router: {
posts: [{redirect: false}]
}
},
templates: []
},
'/partyparty/': {
data: {
query: {
people: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'djgutelaune'
}
}
},
router: {
authors: [{redirect: true, slug: 'djgutelaune'}]
}
},
templates: []
}
},
collections: {
'/yoga/': {
permalink: '/:slug/',
data: {
query: {
gym: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: 'ups',
status: 'draft'
}
}
},
router: {
posts: [{redirect: true, slug: 'ups'}]
}
},
templates: []
}
}
});
});
it('errors: data shortform incorrect', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: 'tag:test'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform resource is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
type: 'edit'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform type is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'subscribers'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform name is author', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
author: {
resource: 'users'
}
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform does not use a custom name at all', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'users'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
});
});
describe('v3', function () {
before(function () {
apiVersion = 'v3';
});
it('no type definitions / empty yaml file', function () {
const object = validate({});
object.should.eql({collections: {}, routes: {}, taxonomies: {}});
});
it('throws error when using :\w+ notiation in collection', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/magic/{slug}/'
},
'/': {
permalink: '/:slug/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
it('throws error when using :\w+ notiation in taxonomies', function () {
try {
validate({
taxonomies: {
tag: '/categories/:slug/'
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error when using an undefined taxonomy', function () {
try {
validate({
taxonomies: {
sweet_baked_good: '/patisserie/{slug}'
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error when permalink is missing (collection)', function () {
try {
validate({
collections: {
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
permalink: '/{slug}/'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
about: 'about'
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'/about': 'about'
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
throw new Error('should fail');
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
it('throws error without leading or trailing slashes', function () {
try {
validate({
routes: {
'about/': 'about'
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
throw new Error('should fail');
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'magic/': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
throw new Error('should fail');
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
magic: {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
throw new Error('should fail');
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic': {
permalink: '/{slug}/'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
}
throw new Error('should fail');
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error without leading or trailing slashes', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '{slug}'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('no validation error for routes', function () {
validate({
routes: {
'/': 'home'
}
});
});
it('no validation error for / collection', function () {
validate({
collections: {
'/': {
permalink: '/{primary_tag}/{slug}/'
}
}
});
});
it('transforms {.*} notation into :\w+', function () {
const object = validate({
collections: {
'/magic/': {
permalink: '/magic/{year}/{slug}/'
},
'/': {
permalink: '/{slug}/'
}
},
taxonomies: {
tag: '/tags/{slug}/',
author: '/authors/{slug}/'
}
});
object.should.eql({
routes: {},
taxonomies: {
tag: '/tags/:slug/',
author: '/authors/:slug/'
},
collections: {
'/magic/': {
permalink: '/magic/:year/:slug/',
templates: []
},
'/': {
permalink: '/:slug/',
templates: []
}
}
});
});
describe('template definitions', function () {
it('single value', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: 'me'
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: 'test'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
it('array', function () {
const object = validate({
routes: {
'/about/': 'about',
'/me/': {
template: ['me']
}
},
collections: {
'/': {
permalink: '/{slug}/',
template: ['test']
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/about/': {
templates: ['about']
},
'/me/': {
templates: ['me']
}
},
collections: {
'/': {
permalink: '/:slug/',
templates: ['test']
}
}
});
});
});
describe('data definitions', function () {
it('shortform', function () {
const object = validate({
routes: {
'/food/': {
data: 'tag.food'
},
'/music/': {
data: 'tag.music'
},
'/ghost/': {
data: 'author.ghost'
},
'/sleep/': {
data: {
bed: 'tag.bed',
dream: 'tag.dream'
}
},
'/lala/': {
data: 'author.carsten'
}
},
collections: {
'/more/': {
permalink: '/{slug}/',
data: {
home: 'page.home'
}
},
'/podcast/': {
permalink: '/podcast/{slug}/',
data: {
something: 'tag.something'
}
},
'/': {
permalink: '/{slug}/',
data: 'tag.sport'
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'food',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'food'}]
}
},
templates: []
},
'/ghost/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'ghost'
}
}
},
router: {
authors: [{redirect: true, slug: 'ghost'}]
}
},
templates: []
},
'/music/': {
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'music',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'music'}]
}
},
templates: []
},
'/sleep/': {
data: {
query: {
bed: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'bed',
visibility: 'public'
}
},
dream: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'dream',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'bed'}, {redirect: true, slug: 'dream'}]
}
},
templates: []
},
'/lala/': {
data: {
query: {
author: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'carsten'
}
}
},
router: {
authors: [{redirect: true, slug: 'carsten'}]
}
},
templates: []
}
},
collections: {
'/more/': {
permalink: '/:slug/',
data: {
query: {
home: {
controller: 'pagesPublic',
resource: 'pages',
type: 'read',
options: {
slug: 'home'
}
}
},
router: {
pages: [{redirect: true, slug: 'home'}]
}
},
templates: []
},
'/podcast/': {
permalink: '/podcast/:slug/',
data: {
query: {
something: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'something',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'something'}]
}
},
templates: []
},
'/': {
permalink: '/:slug/',
data: {
query: {
tag: {
controller: 'tagsPublic',
resource: 'tags',
type: 'read',
options: {
slug: 'sport',
visibility: 'public'
}
}
},
router: {
tags: [{redirect: true, slug: 'sport'}]
}
},
templates: []
}
}
});
});
it('longform', function () {
const object = validate({
routes: {
'/food/': {
data: {
food: {
resource: 'posts',
type: 'browse'
}
}
},
'/wellness/': {
data: {
posts: {
resource: 'posts',
type: 'read',
redirect: false
}
}
},
'/partyparty/': {
data: {
people: {
resource: 'authors',
type: 'read',
slug: 'djgutelaune',
redirect: true
}
}
}
},
collections: {
'/yoga/': {
permalink: '/{slug}/',
data: {
gym: {
resource: 'posts',
type: 'read',
slug: 'ups',
status: 'draft'
}
}
}
}
});
object.should.eql({
taxonomies: {},
routes: {
'/food/': {
data: {
query: {
food: {
controller: 'postsPublic',
resource: 'posts',
type: 'browse',
options: {}
}
},
router: {
posts: [{redirect: true}]
}
},
templates: []
},
'/wellness/': {
data: {
query: {
posts: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: '%s'
}
}
},
router: {
posts: [{redirect: false}]
}
},
templates: []
},
'/partyparty/': {
data: {
query: {
people: {
controller: 'authorsPublic',
resource: 'authors',
type: 'read',
options: {
slug: 'djgutelaune'
}
}
},
router: {
authors: [{redirect: true, slug: 'djgutelaune'}]
}
},
templates: []
}
},
collections: {
'/yoga/': {
permalink: '/:slug/',
data: {
query: {
gym: {
controller: 'postsPublic',
resource: 'posts',
type: 'read',
options: {
slug: 'ups',
status: 'draft'
}
}
},
router: {
posts: [{redirect: true, slug: 'ups'}]
}
},
templates: []
}
}
});
});
it('errors: data shortform incorrect', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: 'tag:test'
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform resource is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
type: 'edit'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform type is missing', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'subscribers'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform name is author', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
author: {
resource: 'users'
}
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('errors: data longform does not use a custom name at all', function () {
try {
validate({
collections: {
'/magic/': {
permalink: '/{slug}/',
data: {
resource: 'users'
}
}
}
});
} catch (err) {
(err instanceof errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
});
});
✨Dynamic Routing Beta (#9596) refs #9601 ### Dynamic Routing This is the beta version of dynamic routing. - we had a initial implementation of "channels" available in the codebase - we have removed and moved this implementation - there is now a centralised place for dynamic routing - server/services/routing - each routing component is represented by a router type e.g. collections, routes, static pages, taxonomies, rss, preview of posts - keep as much as possible logic of routing helpers, middlewares and controllers - ensure test coverage - connect all the things together - yaml file + validation - routing + routers - url service - sitemaps - url access - deeper implementation of yaml validations - e.g. hard require slashes - ensure routing hierarchy/order - e.g. you enable the subscriber app - you have a custom static page, which lives under the same slug /subscribe - static pages are stronger than apps - e.g. the first collection owns the post it has filtered - a post cannot live in two collections - ensure apps are still working and hook into the routers layer (or better said: and register in the routing service) - put as much as possible comments to the code base for better understanding - ensure a clean debug log - ensure we can unmount routes - e.g. you have a collection permalink of /:slug/ represented by {globals.permalink} - and you change the permalink in the admin to dated permalink - the express route get's refreshed from /:slug/ to /:year/:month/:day/:slug/ - unmount without server restart, yey - ensure we are backwards compatible - e.g. render home.hbs for collection index if collection route is / - ensure you can access your configured permalink from the settings table with {globals.permalink} ### Render 503 if url service did not finish - return 503 if the url service has not finished generating the resource urls ### Rewrite sitemaps - we have rewritten the sitemaps "service", because the url generator does no longer happen on runtime - we generate all urls on bootstrap - the sitemaps service will consume created resource and router urls - these urls will be shown on the xml pages - we listen on url events - we listen on router events - we no longer have to fetch the resources, which is nice - the urlservice pre-fetches resources and emits their urls - the urlservice is the only component who knows which urls are valid - i made some ES6 adaptions - we keep the caching logic -> only regenerate xml if there is a change - updated tests - checked test coverage (100%) ### Re-work usage of Url utility - replace all usages of `urlService.utils.urlFor` by `urlService.getByResourceId` - only for resources e.g. post, author, tag - this is important, because with dynamic routing we no longer create static urls based on the settings permalink on runtime - adapt url utility - adapt tests
2018-06-05 20:02:20 +03:00
});