Skip to content

Commit

Permalink
Added tests for reloading routes.yaml
Browse files Browse the repository at this point in the history
refs #9744
  • Loading branch information
kirrg001 committed Aug 16, 2018
1 parent 8bb7088 commit 0379bc4
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 4 deletions.
124 changes: 122 additions & 2 deletions core/test/functional/routes/dynamic_routing_spec.js
Expand Up @@ -6,18 +6,19 @@ const should = require('should'),
supertest = require('supertest'),
sinon = require('sinon'),
moment = require('moment'),
path = require('path'),
testUtils = require('../../utils'),
cheerio = require('cheerio'),
config = require('../../../../core/server/config'),
urlService = require('../../../../core/server/services/url'),
api = require('../../../../core/server/api'),
settingsCache = require('../../../server/services/settings/cache'),
ghost = testUtils.startGhost,
sandbox = sinon.sandbox.create();

let request;

describe('Dynamic Routing', function () {
var ghostServer;
let ghostServer;

function doEnd(done) {
return function (err, res) {
Expand Down Expand Up @@ -692,4 +693,123 @@ describe('Dynamic Routing', function () {
});
});
});

describe('Reload routes.yaml', function () {
before(function (done) {
testUtils.clearData().then(function () {
// we initialise data, but not a user. No user should be required for navigating the frontend
return testUtils.initData();
}).then(function () {
return testUtils.fixtures.overrideOwnerUser('ghost-owner');
}).then(function () {
done();
}).catch(done);
});

after(testUtils.teardown);
after(function () {
return ghostServer.stop();
});

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({
context: testUtils.context.internal.context,
path: path.join(config.get('paths:appRoot'), 'core', 'test', 'utils', 'fixtures', 'settings', 'newroutes.yaml')
}).then(() => {
return testUtils.integrationTesting.urlService.waitTillFinished({dbIsReady: true});
});
});

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();
});
});
});
});
11 changes: 11 additions & 0 deletions core/test/utils/fixtures/settings/newroutes.yaml
@@ -0,0 +1,11 @@
routes:

collections:
/blog/:
permalink: /blog/{year}/{slug}/
template:
- index

taxonomies:
tag: /category/{slug}/
author: /author/{slug}/
6 changes: 4 additions & 2 deletions core/test/utils/index.js
Expand Up @@ -1032,10 +1032,12 @@ module.exports = {
},

urlService: {
waitTillFinished: function () {
waitTillFinished: function (options = {dbIsReady: false}) {
let timeout;

common.events.emit('db.ready');
if (!options.dbIsReady) {
common.events.emit('db.ready');
}

return new Promise(function (resolve) {
(function retry() {
Expand Down

0 comments on commit 0379bc4

Please sign in to comment.