mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
90 lines
2.5 KiB
JavaScript
90 lines
2.5 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const path = require('path');
|
|
const configUtils = require('../../../utils/configUtils');
|
|
const themeEngine = require('../../../../core/frontend/services/theme-engine');
|
|
const privateController = require('../../../../core/frontend/apps/private-blogging/lib/router');
|
|
|
|
describe('Private Controller', function () {
|
|
let res;
|
|
let req;
|
|
let defaultPath;
|
|
let hasTemplateStub;
|
|
|
|
// Helper function to prevent unit tests
|
|
// from failing via timeout when they
|
|
// should just immediately fail
|
|
function failTest(done) {
|
|
return function (err) {
|
|
done(err);
|
|
};
|
|
}
|
|
|
|
beforeEach(function () {
|
|
hasTemplateStub = sinon.stub().returns(false);
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
sinon.stub(themeEngine, 'getActive').returns({
|
|
hasTemplate: hasTemplateStub
|
|
});
|
|
|
|
res = {
|
|
locals: {version: ''},
|
|
render: sinon.spy()
|
|
};
|
|
|
|
req = {
|
|
route: {path: '/private/?r=/'},
|
|
query: {r: ''},
|
|
params: {}
|
|
};
|
|
|
|
defaultPath = path.join(configUtils.config.get('paths').appRoot, '/core/frontend/apps/private-blogging/lib/views/private.hbs');
|
|
|
|
configUtils.set({
|
|
theme: {
|
|
permalinks: '/:slug/'
|
|
}
|
|
});
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
configUtils.restore();
|
|
});
|
|
|
|
it('Should render default password page when theme has no password template', function (done) {
|
|
res.render = function (view, context) {
|
|
view.should.eql(defaultPath);
|
|
should.exist(context);
|
|
done();
|
|
};
|
|
|
|
privateController.renderer(req, res, failTest(done));
|
|
});
|
|
|
|
it('Should render theme password page when it exists', function (done) {
|
|
hasTemplateStub.withArgs('private').returns(true);
|
|
|
|
res.render = function (view, context) {
|
|
view.should.eql('private');
|
|
should.exist(context);
|
|
done();
|
|
};
|
|
|
|
privateController.renderer(req, res, failTest(done));
|
|
});
|
|
|
|
it('Should render with error when error is passed in', function (done) {
|
|
res.error = 'Test Error';
|
|
|
|
res.render = function (view, context) {
|
|
view.should.eql(defaultPath);
|
|
context.should.eql({error: 'Test Error'});
|
|
done();
|
|
};
|
|
|
|
privateController.renderer(req, res, failTest(done));
|
|
});
|
|
});
|