mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Moved custom routes test to e2e frontend suite
https://github.com/TryGhost/Toolbox/issues/140 - This test was bloating the regression/site suite and was using hacks (calling the Admin API) to create a custom redirects state - It suits way better in e2e frontend test suite with less hacky approach to start the Ghsot instance - using custom routes file path to initialize the instance
This commit is contained in:
parent
961c29dc72
commit
6e395291fe
2 changed files with 82 additions and 122 deletions
81
test/e2e-frontend/custom_routes.test.js
Normal file
81
test/e2e-frontend/custom_routes.test.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
const should = require('should');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const supertest = require('supertest');
|
||||||
|
const path = require('path');
|
||||||
|
const moment = require('moment');
|
||||||
|
const testUtils = require('../utils');
|
||||||
|
const configUtils = require('../utils/configUtils');
|
||||||
|
|
||||||
|
function assertCorrectFrontendHeaders(res) {
|
||||||
|
should.not.exist(res.headers['x-cache-invalidate']);
|
||||||
|
should.not.exist(res.headers['X-CSRF-Token']);
|
||||||
|
should.not.exist(res.headers['set-cookie']);
|
||||||
|
should.exist(res.headers.date);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Custom Frontend routing', function () {
|
||||||
|
let request;
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
const routesFilePath = path.join(configUtils.config.get('paths:appRoot'), 'test/utils/fixtures/settings/newroutes.yaml');
|
||||||
|
|
||||||
|
await testUtils.startGhost({
|
||||||
|
forceStart: true,
|
||||||
|
routesFilePath
|
||||||
|
});
|
||||||
|
request = supertest.agent(configUtils.config.get('url'));
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
return testUtils.stopGhost();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve welcome post with old permalink structure', function () {
|
||||||
|
return request.get('/welcome/')
|
||||||
|
.expect(404)
|
||||||
|
.expect(assertCorrectFrontendHeaders);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve welcome post with new permalink structure', function () {
|
||||||
|
const year = moment().year();
|
||||||
|
return request.get(`/blog/${year}/welcome/`)
|
||||||
|
.expect(200)
|
||||||
|
.expect(assertCorrectFrontendHeaders);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve welcome post with new permalink structure and old date', function () {
|
||||||
|
return request.get('/blog/2016/welcome/')
|
||||||
|
.expect(301)
|
||||||
|
.expect(assertCorrectFrontendHeaders);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve rss', function () {
|
||||||
|
return request.get('/blog/rss/')
|
||||||
|
.expect(200)
|
||||||
|
.expect(assertCorrectFrontendHeaders)
|
||||||
|
.then(function (res) {
|
||||||
|
const content = res.text;
|
||||||
|
const todayMoment = moment();
|
||||||
|
const year = todayMoment.format('YYYY');
|
||||||
|
const postLink = `/blog/${year}/welcome/`;
|
||||||
|
|
||||||
|
content.indexOf(postLink).should.be.above(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve collection index', function () {
|
||||||
|
return request.get('/blog/')
|
||||||
|
.expect(200)
|
||||||
|
.expect(assertCorrectFrontendHeaders);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serve tag', function () {
|
||||||
|
return request.get('/category/getting-started/')
|
||||||
|
.expect(200)
|
||||||
|
.expect(assertCorrectFrontendHeaders);
|
||||||
|
});
|
||||||
|
});
|
|
@ -6,13 +6,10 @@ const should = require('should');
|
||||||
const supertest = require('supertest');
|
const supertest = require('supertest');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const path = require('path');
|
|
||||||
const testUtils = require('../../utils');
|
const testUtils = require('../../utils');
|
||||||
const configUtils = require('../../utils/configUtils');
|
const configUtils = require('../../utils/configUtils');
|
||||||
const urlServiceUtils = require('../../utils/url-service-utils');
|
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
const config = require('../../../core/shared/config');
|
const config = require('../../../core/shared/config');
|
||||||
const api = require('../../../core/server/api');
|
|
||||||
const settingsCache = require('../../../core/shared/settings-cache');
|
const settingsCache = require('../../../core/shared/settings-cache');
|
||||||
|
|
||||||
let request;
|
let request;
|
||||||
|
@ -464,7 +461,7 @@ describe('Dynamic Routing', function () {
|
||||||
// Add enough posts to trigger pages
|
// Add enough posts to trigger pages
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
testUtils.clearData().then(function () {
|
testUtils.clearData().then(function () {
|
||||||
// we initialise data, but not a user. No user should be required for navigating the frontend
|
// we initialize data, but not a user. No user should be required for navigating the frontend
|
||||||
return testUtils.initData();
|
return testUtils.initData();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return testUtils.fixtures.insertPostsAndTags();
|
return testUtils.fixtures.insertPostsAndTags();
|
||||||
|
@ -546,122 +543,4 @@ describe('Dynamic Routing', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Reload routes.yaml', function () {
|
|
||||||
before(async function () {
|
|
||||||
await testUtils.clearData();
|
|
||||||
// we initialize data, but not a user. No user should be required for navigating the frontend
|
|
||||||
await testUtils.initData();
|
|
||||||
await testUtils.fixtures.overrideOwnerUser('ghost-owner');
|
|
||||||
await testUtils.initFixtures('settings');
|
|
||||||
});
|
|
||||||
|
|
||||||
after(testUtils.teardownDb);
|
|
||||||
after(function () {
|
|
||||||
return testUtils.stopGhost();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('confirm current routing pattern', function (done) {
|
|
||||||
request.get('/welcome/')
|
|
||||||
.expect(200)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('simulate upload of routes.yaml', function () {
|
|
||||||
return api.settings.upload.query({
|
|
||||||
context: testUtils.context.internal.context,
|
|
||||||
file: {
|
|
||||||
path: path.join(config.get('paths:appRoot'), 'test', 'utils', 'fixtures', 'settings', 'newroutes.yaml')
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
return urlServiceUtils.isFinished();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve welcome post with old permalink structure', function (done) {
|
|
||||||
request.get('/welcome/')
|
|
||||||
.expect(404)
|
|
||||||
.end(function (err) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve welcome post with new permalink structure', function (done) {
|
|
||||||
const year = moment().year();
|
|
||||||
request.get(`/blog/${year}/welcome/`)
|
|
||||||
.expect(200)
|
|
||||||
.end(function (err) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve welcome post with new permalink structure and old date', function (done) {
|
|
||||||
request.get('/blog/2016/welcome/')
|
|
||||||
.expect(301)
|
|
||||||
.end(function (err) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve serve rss', function (done) {
|
|
||||||
request.get('/blog/rss/')
|
|
||||||
.expect(200)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
const content = res.text;
|
|
||||||
const todayMoment = moment();
|
|
||||||
const year = todayMoment.format('YYYY');
|
|
||||||
const postLink = `/blog/${year}/welcome/`;
|
|
||||||
|
|
||||||
content.indexOf(postLink).should.be.above(0);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve collection index', function (done) {
|
|
||||||
request.get('/blog/')
|
|
||||||
.expect(200)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('serve tag', function (done) {
|
|
||||||
request.get('/category/getting-started/')
|
|
||||||
.expect(200)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue