2021-02-24 04:19:22 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const cheerio = require('cheerio');
|
2022-01-21 23:37:48 +03:00
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const localUtils = require('./utils');
|
|
|
|
const configUtils = require('../../utils/configUtils');
|
|
|
|
const urlUtils = require('../../utils/urlUtils');
|
2021-10-20 12:10:50 +03:00
|
|
|
|
2022-01-21 23:37:48 +03:00
|
|
|
const routeSettingsService = require('../../../core/server/services/route-settings');
|
|
|
|
const themeEngine = require('../../../core/frontend/services/theme-engine');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-08-03 14:10:50 +03:00
|
|
|
describe('Frontend beharior tests', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
let app;
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
before(localUtils.urlService.resetGenerators);
|
2021-02-24 04:19:22 +03:00
|
|
|
before(testUtils.teardownDb);
|
|
|
|
before(testUtils.setup('users:roles', 'posts'));
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
let postSpy;
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('default routes.yaml', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-08-06 16:16:23 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
|
2022-07-04 11:27:55 +03:00
|
|
|
const postsAPI = require('../../../core/server/api/endpoints/posts-public');
|
2021-02-24 04:32:03 +03:00
|
|
|
postSpy = sinon.spy(postsAPI.browse, 'query');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
postSpy.restore();
|
2021-08-06 16:16:23 +03:00
|
|
|
sinon.restore();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-08-03 14:10:50 +03:00
|
|
|
describe('beharior: default cases', function () {
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('post');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-01-14 19:55:48 +03:00
|
|
|
describe('AMP enabled', function () {
|
|
|
|
it('serve amp', function () {
|
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/amp/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.match(/amp\.hbs/);
|
|
|
|
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-01-14 19:55:48 +03:00
|
|
|
describe('AMP disabled', function () {
|
|
|
|
it('serve amp', function () {
|
|
|
|
localUtils.defaultMocks(sinon, {amp: false});
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/amp/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('post not found', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/not-found/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve static page', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/static-page-test/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('page');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve author', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/author/joe-bloggs/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('author');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-01-25 14:38:03 +03:00
|
|
|
const bodyClasses = response.body.match(/<body[^>]*class="([^"]*?)">/)[1].split(' ');
|
|
|
|
bodyClasses.should.containEql('author-template');
|
|
|
|
bodyClasses.should.containEql('author-joe-bloggs');
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/tag/bacon/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('tag');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+type:post');
|
|
|
|
postSpy.args[0][0].options.page.should.eql(1);
|
|
|
|
postSpy.args[0][0].options.limit.should.eql(2);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve tag rss', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/tag/bacon/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
$('.post-card').length.should.equal(2);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
should.exist(response.res.locals.context);
|
|
|
|
should.exist(response.res.locals.version);
|
|
|
|
should.exist(response.res.locals.safeVersion);
|
|
|
|
should.exist(response.res.locals.safeVersion);
|
|
|
|
should.exist(response.res.locals.relativeUrl);
|
|
|
|
should.exist(response.res.routerOptions);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection: page 2', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/page/2/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
$('.post-card').length.should.equal(2);
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve theme asset', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2022-01-25 14:38:03 +03:00
|
|
|
url: '/assets/built/screen.css',
|
2021-02-24 04:32:03 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-03 14:10:50 +03:00
|
|
|
describe('beharior: prettify', function () {
|
2021-02-24 04:32:03 +03:00
|
|
|
it('url without slash', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/prettify-me',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('/prettify-me/');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-08-03 14:10:50 +03:00
|
|
|
describe('beharior: url redirects', function () {
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('pagination', function () {
|
|
|
|
it('redirect /page/1/ to /', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
host: 'example.com',
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/page/1/'
|
2021-02-24 04:19:22 +03:00
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
2021-02-24 04:32:03 +03:00
|
|
|
response.headers.location.should.eql('/');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('rss', function () {
|
|
|
|
it('redirect /feed/ to /rss/', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
secure: false,
|
2021-02-24 04:32:03 +03:00
|
|
|
host: 'example.com',
|
2021-02-24 04:19:22 +03:00
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/feed/'
|
2021-02-24 04:19:22 +03:00
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
2021-02-24 04:32:03 +03:00
|
|
|
response.headers.location.should.eql('/rss/');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2022-05-11 16:53:23 +03:00
|
|
|
describe('https site: http requests redirect to https', function () {
|
2021-02-24 04:32:03 +03:00
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'https://example.com');
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
urlUtils.restore();
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('protocol', function () {
|
|
|
|
it('blog is https, request is http', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
host: 'example.com',
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/html-ipsum/');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('blog is https, request is http, trailing slash exists already', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/html-ipsum/');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('assets', function () {
|
|
|
|
it('blog is https, request is http', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/favicon.png',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/favicon.png');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('blog is https, request is http', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/assets/css/main.css',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/assets/css/main.css');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('extended routes.yaml: collections', function () {
|
2021-09-27 15:38:48 +03:00
|
|
|
describe('2 collections', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {
|
|
|
|
'/': {templates: ['home']}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/podcast/': {
|
|
|
|
permalink: '/podcast/:slug/',
|
|
|
|
filter: 'featured:true'
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
'/something/': {
|
|
|
|
permalink: '/something/:slug/',
|
|
|
|
filter: 'featured:false'
|
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {
|
|
|
|
tag: '/categories/:slug/',
|
|
|
|
author: '/authors/:slug/'
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve static route', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('home');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve rss', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/podcast/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/something/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('post');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection: podcast with default template', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/podcast/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
$('.post-card').length.should.equal(2);
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection: something with custom template', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/something/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('something');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('no collections', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {
|
|
|
|
'/something/': {
|
|
|
|
templates: ['something']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
collections: {},
|
|
|
|
taxonomies: {}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve route', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/something/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('something');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('static permalink route', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/podcast/': {
|
|
|
|
permalink: '/featured/',
|
|
|
|
filter: 'featured:true'
|
2021-02-24 04:19:22 +03:00
|
|
|
},
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/'
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
2021-02-24 04:32:03 +03:00
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
2022-05-11 16:53:23 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
method: 'GET',
|
|
|
|
url: '/featured/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
// We can't find a post with the slug "featured"
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('post');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve author', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/author/joe-bloggs/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/tag/bacon/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('primary author permalink', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/something/': {
|
|
|
|
permalink: '/:primary_author/:slug/'
|
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/joe-bloggs/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('post');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('post without author', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('page', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/static-page-test/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('page');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('primary tag permalink', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/something/': {
|
|
|
|
permalink: '/something/:primary_tag/:slug/'
|
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve post', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/something/kitchen-sink/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('post');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('post without tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/something/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('post without tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
response.template.should.eql('error-404');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('page', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/static-page-test/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('page');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('collection/routes with data key', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {
|
|
|
|
'/my-page/': {
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
page: {
|
|
|
|
controller: 'pagesPublic',
|
|
|
|
resource: 'pages',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'static-page-test'
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:32:03 +03:00
|
|
|
router: {
|
|
|
|
pages: [{redirect: true, slug: 'static-page-test'}]
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:32:03 +03:00
|
|
|
templates: ['page']
|
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/food/': {
|
|
|
|
permalink: '/food/:slug/',
|
|
|
|
filter: 'tag:bacon+tag:-chorizo',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
tag: {
|
|
|
|
controller: 'tagsPublic',
|
|
|
|
resource: 'tags',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'bacon'
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:32:03 +03:00
|
|
|
},
|
|
|
|
router: {
|
|
|
|
tags: [{redirect: true, slug: 'bacon'}]
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
2021-02-24 04:32:03 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'/sport/': {
|
|
|
|
permalink: '/sport/:slug/',
|
|
|
|
filter: 'tag:chorizo+tag:-bacon',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
apollo: {
|
|
|
|
controller: 'tagsPublic',
|
|
|
|
resource: 'tags',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'chorizo'
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:32:03 +03:00
|
|
|
},
|
|
|
|
router: {
|
|
|
|
tags: [{redirect: false, slug: 'chorizo'}]
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:32:03 +03:00
|
|
|
}
|
|
|
|
},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {
|
|
|
|
tag: '/categories/:slug/',
|
|
|
|
author: '/authors/:slug/'
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:32:03 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve /food/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/food/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve bacon tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/categories/bacon/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve /sport/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/sport/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve chorizo tag', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/categories/chorizo/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve my-page', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/my-page/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('extended routes.yaml: templates', function () {
|
|
|
|
describe('default template, no template', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/',
|
|
|
|
templates: ['default']
|
|
|
|
},
|
|
|
|
'/magic/': {
|
|
|
|
permalink: '/magic/:slug/'
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('default');
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve second collectiom', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/magic/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('two templates', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/',
|
|
|
|
templates: ['something', 'default']
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon);
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve collection', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('default');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
describe('home.hbs priority', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {},
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
collections: {
|
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/',
|
|
|
|
templates: ['something', 'default']
|
|
|
|
},
|
|
|
|
'/magic/': {
|
|
|
|
permalink: '/magic/:slug/',
|
|
|
|
templates: ['something', 'default']
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve collection', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('home');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve second page collection: should use index.hbs', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/magic/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('something');
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('extended routes.yaml: routes', function () {
|
|
|
|
describe('channels', function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
before(localUtils.urlService.resetGenerators);
|
2021-02-24 04:32:03 +03:00
|
|
|
before(testUtils.teardownDb);
|
|
|
|
before(testUtils.setup('users:roles', 'posts'));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.defaultMocks(sinon, {theme: 'test-theme-channels'});
|
2021-02-24 04:32:03 +03:00
|
|
|
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:19:22 +03:00
|
|
|
routes: {
|
2021-02-24 04:32:03 +03:00
|
|
|
'/channel1/': {
|
|
|
|
controller: 'channel',
|
|
|
|
filter: 'tag:kitchen-sink',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
tag: {
|
|
|
|
controller: 'tagsPublic',
|
|
|
|
resource: 'tags',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'kitchen-sink'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
router: {
|
|
|
|
tags: [{redirect: true, slug: 'kitchen-sink'}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'/channel2/': {
|
|
|
|
controller: 'channel',
|
|
|
|
filter: 'tag:bacon',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
tag: {
|
|
|
|
controller: 'tagsPublic',
|
|
|
|
resource: 'tags',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'bacon'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
router: {
|
|
|
|
tags: [{redirect: true, slug: 'bacon'}]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
templates: ['default']
|
|
|
|
},
|
|
|
|
|
|
|
|
'/channel3/': {
|
|
|
|
controller: 'channel',
|
|
|
|
filter: 'author:joe-bloggs',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
joe: {
|
|
|
|
controller: 'authorsPublic',
|
|
|
|
resource: 'authors',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'joe-bloggs',
|
|
|
|
redirect: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
router: {
|
|
|
|
authors: [{redirect: false, slug: 'joe-bloggs'}]
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:19:22 +03:00
|
|
|
},
|
2021-02-24 04:32:03 +03:00
|
|
|
|
|
|
|
'/channel4/': {
|
|
|
|
controller: 'channel',
|
|
|
|
filter: 'author:joe-bloggs'
|
|
|
|
},
|
|
|
|
|
|
|
|
'/channel5/': {
|
2021-02-24 04:19:22 +03:00
|
|
|
controller: 'channel',
|
2021-02-24 04:32:03 +03:00
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
tag: {
|
|
|
|
controller: 'authorsPublic',
|
|
|
|
resource: 'authors',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'joe-bloggs',
|
|
|
|
redirect: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
router: {
|
|
|
|
authors: [{redirect: false, slug: 'joe-bloggs'}]
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:19:22 +03:00
|
|
|
},
|
2021-02-24 04:32:03 +03:00
|
|
|
|
|
|
|
'/channel6/': {
|
|
|
|
controller: 'channel',
|
|
|
|
data: {
|
|
|
|
query: {
|
|
|
|
post: {
|
|
|
|
controller: 'postsPublic',
|
|
|
|
resource: 'posts',
|
|
|
|
type: 'read',
|
|
|
|
options: {
|
|
|
|
slug: 'html-ipsum',
|
|
|
|
redirect: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
router: {
|
|
|
|
posts: [{redirect: true, slug: 'html-ipsum'}]
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 04:19:22 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
collections: {
|
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
taxonomies: {
|
|
|
|
tag: '/tag/:slug/',
|
|
|
|
author: '/author/:slug/'
|
|
|
|
}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:19:22 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-10-20 12:10:50 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 1', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel1/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:32:03 +03:00
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
|
2021-02-24 04:19:22 +03:00
|
|
|
response.statusCode.should.eql(200);
|
2021-02-24 04:32:03 +03:00
|
|
|
response.template.should.eql('index');
|
|
|
|
|
|
|
|
$('.post-card').length.should.equal(2);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 1: rss', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel1/rss/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:32:03 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.headers['content-type'].should.eql('text/xml; charset=UTF-8');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 2', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel2/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:32:03 +03:00
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('default');
|
|
|
|
|
|
|
|
// default template does not list posts
|
|
|
|
$('.post-card').length.should.equal(0);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 3', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel3/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:32:03 +03:00
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
|
2021-02-24 04:19:22 +03:00
|
|
|
response.statusCode.should.eql(200);
|
2021-02-24 04:32:03 +03:00
|
|
|
response.template.should.eql('channel3');
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 4', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel4/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:32:03 +03:00
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
|
2021-02-24 04:19:22 +03:00
|
|
|
response.statusCode.should.eql(200);
|
2021-02-24 04:32:03 +03:00
|
|
|
response.template.should.eql('index');
|
|
|
|
|
|
|
|
$('.post-card').length.should.equal(4);
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
it('serve channel 5', function () {
|
2021-02-24 04:19:22 +03:00
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
2021-02-24 04:32:03 +03:00
|
|
|
url: '/channel5/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
|
|
|
|
2021-12-02 18:58:14 +03:00
|
|
|
$('.post-card').length.should.equal(10);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve channel 6', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/channel6/',
|
2021-02-24 04:19:22 +03:00
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:19:22 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
2021-02-24 04:32:03 +03:00
|
|
|
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('index');
|
|
|
|
|
2021-12-02 18:58:14 +03:00
|
|
|
$('.post-card').length.should.equal(10);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve kitching-sink: redirect', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/tag/kitchen-sink/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('/channel1/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve html-ipsum: redirect', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/html-ipsum/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('/channel6/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve chorizo: no redirect', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/tag/chorizo/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve joe-bloggs', function () {
|
|
|
|
const req = {
|
2022-05-11 16:53:23 +03:00
|
|
|
|
2021-02-24 04:32:03 +03:00
|
|
|
method: 'GET',
|
|
|
|
url: '/author/joe-bloggs/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
2021-02-24 04:19:22 +03:00
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:32:03 +03:00
|
|
|
|
|
|
|
describe('extended routes.yaml (5): rss override', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-12-02 15:10:05 +03:00
|
|
|
sinon.stub(routeSettingsService, 'loadRouteSettings').get(() => () => ({
|
2021-02-24 04:32:03 +03:00
|
|
|
routes: {
|
|
|
|
'/podcast/rss/': {
|
|
|
|
templates: ['podcast/rss'],
|
|
|
|
content_type: 'text/xml'
|
|
|
|
},
|
|
|
|
'/cooking/': {
|
|
|
|
controller: 'channel',
|
|
|
|
rss: false
|
|
|
|
},
|
|
|
|
'/flat/': {
|
|
|
|
controller: 'channel'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
collections: {
|
|
|
|
'/podcast/': {
|
|
|
|
permalink: '/:slug/',
|
|
|
|
filter: 'featured:true',
|
|
|
|
templates: ['home'],
|
|
|
|
rss: false
|
|
|
|
},
|
|
|
|
'/music/': {
|
|
|
|
permalink: '/:slug/',
|
|
|
|
rss: false
|
|
|
|
},
|
|
|
|
'/': {
|
|
|
|
permalink: '/:slug/'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
taxonomies: {}
|
2021-11-23 14:21:55 +03:00
|
|
|
}));
|
2021-02-24 04:32:03 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {theme: 'test-theme'});
|
2021-02-24 04:32:03 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /rss/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /music/rss/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/music/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /cooking/rss/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/cooking/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /flat/rss/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/flat/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /podcast/rss/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/podcast/rss/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
response.template.should.eql('podcast/rss');
|
|
|
|
response.headers['content-type'].should.eql('text/xml; charset=utf-8');
|
|
|
|
response.body.match(/<link>/g).length.should.eql(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('serve /podcast/', function () {
|
|
|
|
const req = {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/podcast/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 04:32:03 +03:00
|
|
|
.then(function (response) {
|
|
|
|
const $ = cheerio.load(response.body);
|
|
|
|
response.statusCode.should.eql(200);
|
2022-05-11 16:53:23 +03:00
|
|
|
$('head link')[1].attribs.href.should.eql('http://127.0.0.1:2369/rss/');
|
2021-02-24 04:32:03 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-24 04:19:22 +03:00
|
|
|
});
|