2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
moment = require('moment'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
_ = require('lodash'),
|
2017-10-09 14:56:44 +03:00
|
|
|
|
|
|
|
// Test utils
|
|
|
|
configUtils = require('../../utils/configUtils'),
|
|
|
|
markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc,
|
|
|
|
|
|
|
|
// Server requires
|
|
|
|
api = require('../../../server/api'),
|
|
|
|
controllers = require('../../../server/controllers'),
|
2017-12-14 05:01:23 +03:00
|
|
|
themes = require('../../../server/services/themes'),
|
|
|
|
settingsCache = require('../../../server/services/settings/cache'),
|
2017-10-09 14:56:44 +03:00
|
|
|
|
2015-10-24 22:04:02 +03:00
|
|
|
sandbox = sinon.sandbox.create();
|
2013-11-12 01:35:17 +04:00
|
|
|
|
2017-10-09 14:56:44 +03:00
|
|
|
describe('Controllers', function () {
|
2017-10-12 15:36:50 +03:00
|
|
|
var adminEditPagePath = '/ghost/#/editor/',
|
2017-03-14 02:15:50 +03:00
|
|
|
localSettingsCache = {},
|
|
|
|
hasTemplateStub;
|
|
|
|
|
|
|
|
function resetLocalSettingsCache() {
|
|
|
|
localSettingsCache = {
|
|
|
|
permalinks: '/:slug/',
|
2017-04-24 20:41:00 +03:00
|
|
|
active_theme: 'casper'
|
2017-03-14 02:15:50 +03:00
|
|
|
};
|
|
|
|
}
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore();
|
2017-02-03 16:15:11 +03:00
|
|
|
});
|
|
|
|
|
2017-03-14 02:15:50 +03:00
|
|
|
// Ensure hasTemplate returns values
|
|
|
|
function setupActiveTheme() {
|
|
|
|
hasTemplateStub = sandbox.stub().returns(false);
|
|
|
|
hasTemplateStub.withArgs('default').returns(true);
|
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page').returns(true);
|
|
|
|
hasTemplateStub.withArgs('page-about').returns(true);
|
|
|
|
hasTemplateStub.withArgs('post').returns(true);
|
|
|
|
|
|
|
|
sandbox.stub(themes, 'getActive').returns({
|
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
|
2017-11-28 20:19:23 +03:00
|
|
|
sandbox.stub(settingsCache, 'get').callsFake(function (key) {
|
2017-02-03 16:15:11 +03:00
|
|
|
return localSettingsCache[key];
|
|
|
|
});
|
2017-03-14 02:15:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
resetLocalSettingsCache();
|
|
|
|
setupActiveTheme();
|
2013-12-10 07:38:25 +04:00
|
|
|
});
|
|
|
|
|
2014-07-29 07:58:39 +04:00
|
|
|
// Helper function to prevent unit tests
|
|
|
|
// from failing via timeout when they
|
|
|
|
// should just immediately fail
|
2015-10-24 22:04:02 +03:00
|
|
|
function failTest(done) {
|
|
|
|
return function (err) {
|
|
|
|
done(err);
|
2014-07-29 07:58:39 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
describe('entry', function () {
|
2017-03-14 02:15:50 +03:00
|
|
|
var req, res, mockPosts = [{
|
2017-03-21 11:24:11 +03:00
|
|
|
posts: [{
|
|
|
|
status: 'published',
|
|
|
|
id: 1,
|
|
|
|
title: 'Test static page',
|
|
|
|
slug: 'test-static-page',
|
2017-05-31 17:46:29 +03:00
|
|
|
mobiledoc: markdownToMobiledoc('Test static page content'),
|
2017-03-21 11:24:11 +03:00
|
|
|
page: 1,
|
|
|
|
published_at: new Date('2013/12/30').getTime(),
|
|
|
|
author: {
|
2014-09-10 08:06:24 +04:00
|
|
|
id: 1,
|
2017-03-21 11:24:11 +03:00
|
|
|
name: 'Test User',
|
|
|
|
slug: 'test',
|
|
|
|
email: 'test@ghost.org'
|
|
|
|
},
|
|
|
|
url: '/test-static-page/'
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
posts: [{
|
|
|
|
status: 'published',
|
|
|
|
id: 2,
|
|
|
|
title: 'Test normal post',
|
|
|
|
slug: 'test-normal-post',
|
2017-05-31 17:46:29 +03:00
|
|
|
mobiledoc: markdownToMobiledoc('The test normal post content'),
|
2017-03-21 11:24:11 +03:00
|
|
|
page: 0,
|
|
|
|
published_at: new Date('2014/1/2').getTime(),
|
|
|
|
author: {
|
|
|
|
id: 1,
|
|
|
|
name: 'Test User',
|
|
|
|
slug: 'test',
|
|
|
|
email: 'test@ghost.org'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
posts: [{
|
|
|
|
status: 'published',
|
|
|
|
id: 3,
|
|
|
|
title: 'About',
|
|
|
|
slug: 'about',
|
2017-05-31 17:46:29 +03:00
|
|
|
mobiledoc: markdownToMobiledoc('This is the about page content'),
|
2017-03-21 11:24:11 +03:00
|
|
|
page: 1,
|
|
|
|
published_at: new Date('2014/1/30').getTime(),
|
|
|
|
author: {
|
|
|
|
id: 1,
|
|
|
|
name: 'Test User',
|
|
|
|
slug: 'test',
|
|
|
|
email: 'test@ghost.org'
|
|
|
|
},
|
|
|
|
url: '/about/'
|
|
|
|
}]
|
|
|
|
}];
|
2013-12-10 07:38:25 +04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2017-11-28 20:19:23 +03:00
|
|
|
sandbox.stub(api.posts, 'read').callsFake(function (args) {
|
2015-10-10 20:51:38 +03:00
|
|
|
var post = _.find(mockPosts, function (mock) {
|
2014-04-16 14:09:03 +04:00
|
|
|
return mock.posts[0].slug === args.slug;
|
2015-10-10 20:51:38 +03:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2017-02-03 16:15:11 +03:00
|
|
|
return Promise.resolve(post || {posts: []});
|
2015-12-02 13:06:44 +03:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2015-10-21 14:51:01 +03:00
|
|
|
req = {
|
|
|
|
path: '/', params: {}, route: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
res = {
|
|
|
|
locals: {},
|
|
|
|
render: sinon.spy(),
|
|
|
|
redirect: sinon.spy()
|
|
|
|
};
|
2013-12-10 07:38:25 +04:00
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('static pages', function () {
|
2014-02-23 06:16:07 +04:00
|
|
|
describe('custom page templates', function () {
|
2015-10-21 14:51:01 +03:00
|
|
|
it('it will render a custom page-slug template if it exists', function (done) {
|
|
|
|
req.path = '/' + mockPosts[2].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('page-' + mockPosts[2].posts[0].slug);
|
|
|
|
context.post.should.equal(mockPosts[2].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
mockPosts[2].posts[0].url = req.path;
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2015-10-21 14:51:01 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('it will use page.hbs if it exists and no page-slug template is present', function (done) {
|
2017-03-14 02:15:50 +03:00
|
|
|
hasTemplateStub.withArgs('page-about').returns(false);
|
|
|
|
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[2].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('page');
|
|
|
|
context.post.should.equal(mockPosts[2].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
mockPosts[2].posts[0].url = req.path;
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2015-10-21 14:51:01 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('defaults to post.hbs without a page.hbs or page-slug template', function (done) {
|
2017-03-14 02:15:50 +03:00
|
|
|
hasTemplateStub.withArgs('page-about').returns(false);
|
|
|
|
hasTemplateStub.withArgs('page').returns(false);
|
|
|
|
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[2].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('post');
|
|
|
|
context.post.should.equal(mockPosts[2].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2015-05-20 05:00:27 +03:00
|
|
|
mockPosts[2].posts[0].url = req.path;
|
2015-10-21 14:51:01 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-23 06:16:07 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('permalink set to slug', function () {
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will render static page via /:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[0].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('page');
|
|
|
|
context.post.should.equal(mockPosts[0].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT render static page via /YYY/MM/DD/:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[0].posts[0].slug].join('/') + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
|
|
|
|
2014-10-26 04:15:24 +03:00
|
|
|
it('will NOT render static page via /:author/:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[0].posts[0].slug].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will redirect static page to admin edit page via /:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [mockPosts[0].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
res.redirect = function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-21 14:51:01 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[0].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT redirect static page to admin edit page via /YYYY/MM/DD/:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[0].posts[0].slug, 'edit'].join('/') + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-10-26 04:15:24 +03:00
|
|
|
|
|
|
|
it('will NOT redirect static page to admin edit page via /:author/:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[0].posts[0].slug, 'edit'].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('permalink set to date', function () {
|
|
|
|
beforeEach(function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.permalinks = '/:year/:month/:day/:slug/';
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will render static page via /:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[0].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('page');
|
|
|
|
context.post.should.equal(mockPosts[0].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT render static page via /YYYY/MM/DD/:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[0].posts[0].slug].join('/') + '/';
|
|
|
|
res.render = sinon.spy();
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will redirect static page to admin edit page via /:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [mockPosts[0].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
res.render = sinon.spy();
|
|
|
|
res.redirect = function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-21 14:51:01 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[0].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT redirect static page to admin edit page via /YYYY/MM/DD/:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[0].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
res.render = sinon.spy();
|
|
|
|
res.redirect = sinon.spy();
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
});
|
|
|
|
});
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('post', function () {
|
|
|
|
describe('permalink set to slug', function () {
|
|
|
|
beforeEach(function () {
|
2015-05-20 05:00:27 +03:00
|
|
|
mockPosts[1].posts[0].url = '/' + mockPosts[1].posts[0].slug + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will render post via /:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[1].posts[0].slug + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('post');
|
2016-02-08 00:27:01 +03:00
|
|
|
should.exist(context.post);
|
2015-10-21 14:51:01 +03:00
|
|
|
context.post.should.equal(mockPosts[1].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT render post via /YYYY/MM/DD/:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[1].posts[0].slug].join('/') + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-26 04:15:24 +03:00
|
|
|
it('will NOT render post via /:author/:slug', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
// Handle Edit append
|
|
|
|
it('will redirect post to admin edit page via /:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
res.redirect = function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-21 14:51:01 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[1].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-01-03 08:32:31 +04:00
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
it('will NOT redirect post to admin edit page via /YYYY/MM/DD/:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['2012/12/30', mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-10-26 04:15:24 +03:00
|
|
|
|
|
|
|
it('will NOT redirect post to admin edit page via /:author/:slug/edit', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-10-10 20:51:38 +03:00
|
|
|
|
|
|
|
it('should call next if post is not found', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/unknown/';
|
2015-10-10 20:51:38 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function (err) {
|
2015-10-21 14:51:01 +03:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2015-10-10 20:51:38 +03:00
|
|
|
should.not.exist(err);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2015-10-10 20:51:38 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('permalink set to date', function () {
|
|
|
|
beforeEach(function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.permalinks = '/:year/:month/:day/:slug/';
|
2015-05-20 05:00:27 +03:00
|
|
|
|
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD');
|
|
|
|
mockPosts[1].posts[0].url = '/' + date + '/' + mockPosts[1].posts[0].slug + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will render post via /YYYY/MM/DD/:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD');
|
|
|
|
req.path = '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('post');
|
2016-02-08 00:27:01 +03:00
|
|
|
should.exist(context.post);
|
2015-10-21 14:51:01 +03:00
|
|
|
context.post.should.equal(mockPosts[1].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[1].posts[0].slug + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:author/:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
// Handle Edit append
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will redirect post to admin edit page via /YYYY/MM/DD/:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
var dateFormat = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD');
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [dateFormat, mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
res.redirect = function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-21 14:51:01 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[1].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT redirect post to admin edit page via /:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT redirect post to admin edit page via /:author/:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('permalink set to author', function () {
|
|
|
|
beforeEach(function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.permalinks = 'author/:slug/';
|
2015-05-20 05:00:27 +03:00
|
|
|
|
|
|
|
// set post url to permalink-defined url
|
|
|
|
mockPosts[1].posts[0].url = '/test/' + mockPosts[1].posts[0].slug + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will render post via /:author/:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug].join('/') + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
res.render = function (view, context) {
|
|
|
|
view.should.equal('post');
|
|
|
|
should.exist(context.post);
|
|
|
|
context.post.should.equal(mockPosts[1].posts[0]);
|
|
|
|
done();
|
|
|
|
};
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-10-26 04:15:24 +03:00
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /YYYY/MM/DD/:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD');
|
|
|
|
req.path = '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:author/:slug/ when author does not match post author', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test-2', mockPosts[1].posts[0].slug].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:slug/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + mockPosts[1].posts[0].slug + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle Edit append
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will redirect post to admin edit page via /:author/:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + ['test', mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
|
|
|
|
|
|
|
res.redirect = function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-21 14:51:01 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[1].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
};
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-10-26 04:15:24 +03:00
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT redirect post to admin edit page via /YYYY/MM/DD/:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD');
|
|
|
|
req.path = '/' + [date, mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT redirect post to admin edit page /:slug/edit/', function (done) {
|
2015-10-21 14:51:01 +03:00
|
|
|
req.path = '/' + [mockPosts[1].posts[0].slug, 'edit'].join('/') + '/';
|
2014-10-26 04:15:24 +03:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-10-26 04:15:24 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
describe('permalink set to custom format', function () {
|
|
|
|
beforeEach(function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.permalinks = '/:year/:slug/';
|
2015-05-20 05:00:27 +03:00
|
|
|
|
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY');
|
|
|
|
mockPosts[1].posts[0].url = '/' + date + '/' + mockPosts[1].posts[0].slug + '/';
|
2014-01-01 19:27:39 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will render post via /:year/:slug/', function (done) {
|
2015-10-30 22:02:06 +03:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY');
|
|
|
|
|
|
|
|
req.path = '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/';
|
|
|
|
req.route = {path: '*'};
|
|
|
|
|
|
|
|
res = {
|
|
|
|
locals: {},
|
|
|
|
render: function (view, context) {
|
|
|
|
view.should.equal('post');
|
|
|
|
should.exist(context.post);
|
|
|
|
context.post.should.equal(mockPosts[1].posts[0]);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
2014-02-02 09:29:07 +04:00
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /YYYY/MM/DD/:slug/', function (done) {
|
2014-04-16 14:09:03 +04:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY/MM/DD'),
|
2014-02-02 09:29:07 +04:00
|
|
|
req = {
|
2015-05-20 05:00:27 +03:00
|
|
|
path: '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/'
|
2014-02-02 09:29:07 +04:00
|
|
|
},
|
|
|
|
res = {
|
2014-09-04 20:07:12 +04:00
|
|
|
locals: {},
|
2014-02-02 09:29:07 +04:00
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:year/slug/ when year does not match post year', function (done) {
|
2015-01-06 00:43:11 +03:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).subtract(1, 'years').format('YYYY'),
|
2014-02-02 09:29:07 +04:00
|
|
|
req = {
|
2015-05-20 05:00:27 +03:00
|
|
|
path: '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/'
|
2014-02-02 09:29:07 +04:00
|
|
|
},
|
|
|
|
res = {
|
2014-09-04 20:07:12 +04:00
|
|
|
locals: {},
|
2014-02-02 09:29:07 +04:00
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
});
|
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT render post via /:slug/', function (done) {
|
2014-02-02 09:29:07 +04:00
|
|
|
var req = {
|
2015-05-20 05:00:27 +03:00
|
|
|
path: '/' + mockPosts[1].posts[0].slug + '/'
|
2014-02-02 09:29:07 +04:00
|
|
|
},
|
|
|
|
res = {
|
2014-09-04 20:07:12 +04:00
|
|
|
locals: {},
|
2014-02-02 09:29:07 +04:00
|
|
|
render: sinon.spy()
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2014-02-02 09:29:07 +04:00
|
|
|
// Handle Edit append
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will redirect post to admin edit page via /:year/:slug/edit/', function (done) {
|
2014-04-16 14:09:03 +04:00
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY'),
|
2014-02-02 09:29:07 +04:00
|
|
|
req = {
|
2015-05-20 05:00:27 +03:00
|
|
|
path: '/' + [date, mockPosts[1].posts[0].slug, 'edit'].join('/') + '/'
|
2014-02-02 09:29:07 +04:00
|
|
|
},
|
|
|
|
res = {
|
2014-09-04 20:07:12 +04:00
|
|
|
locals: {},
|
2014-02-02 09:29:07 +04:00
|
|
|
render: sinon.spy(),
|
|
|
|
redirect: function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2014-04-16 14:09:03 +04:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[1].posts[0].id + '/');
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2014-02-02 09:29:07 +04:00
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
|
2015-05-20 05:00:27 +03:00
|
|
|
it('will NOT redirect post to admin edit page /:slug/edit/', function (done) {
|
2014-02-02 09:29:07 +04:00
|
|
|
var req = {
|
2015-05-20 05:00:27 +03:00
|
|
|
path: '/' + [mockPosts[1].posts[0].slug, 'edit'].join('/') + '/'
|
2014-02-02 09:29:07 +04:00
|
|
|
},
|
|
|
|
res = {
|
2014-09-04 20:07:12 +04:00
|
|
|
locals: {},
|
2014-02-02 09:29:07 +04:00
|
|
|
render: sinon.spy(),
|
|
|
|
redirect: sinon.spy()
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.false();
|
2014-02-02 09:29:07 +04:00
|
|
|
done();
|
|
|
|
});
|
2014-01-03 08:32:31 +04:00
|
|
|
});
|
|
|
|
});
|
2015-10-10 20:51:38 +03:00
|
|
|
|
|
|
|
describe('permalink set to custom format no slash', function () {
|
|
|
|
beforeEach(function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.permalinks = '/:year/:slug/';
|
2015-10-10 20:51:38 +03:00
|
|
|
|
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY');
|
|
|
|
mockPosts[1].posts[0].url = '/' + date + '/' + mockPosts[1].posts[0].slug + '/';
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle Edit append
|
|
|
|
it('will redirect post to admin edit page via /:year/:id/edit/', function (done) {
|
|
|
|
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY'),
|
|
|
|
req = {
|
|
|
|
path: '/' + [date, mockPosts[1].posts[0].slug, 'edit'].join('/') + '/'
|
|
|
|
},
|
|
|
|
res = {
|
|
|
|
locals: {},
|
|
|
|
render: sinon.spy(),
|
|
|
|
redirect: function (arg) {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.render.called.should.be.false();
|
2015-10-10 20:51:38 +03:00
|
|
|
arg.should.eql(adminEditPagePath + mockPosts[1].posts[0].id + '/');
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-08 13:00:25 +03:00
|
|
|
controllers.entry(req, res, failTest(done));
|
2015-10-10 20:51:38 +03:00
|
|
|
});
|
|
|
|
});
|
2014-01-01 19:27:39 +04:00
|
|
|
});
|
2013-12-10 07:38:25 +04:00
|
|
|
});
|
2014-09-10 08:06:24 +04:00
|
|
|
});
|