2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const path = require('path');
|
|
|
|
const configUtils = require('../../../utils/configUtils');
|
2021-04-20 15:34:51 +01:00
|
|
|
const themeService = require('../../../../core/frontend/services/themes');
|
2020-04-29 16:44:27 +01:00
|
|
|
const privateController = require('../../../../core/frontend/apps/private-blogging/lib/router');
|
2016-04-11 08:58:41 -05:00
|
|
|
|
|
|
|
describe('Private Controller', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
let res;
|
|
|
|
let req;
|
|
|
|
let defaultPath;
|
|
|
|
let hasTemplateStub;
|
2016-04-11 08:58:41 -05:00
|
|
|
|
|
|
|
// 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 () {
|
2019-01-21 17:53:44 +01:00
|
|
|
hasTemplateStub = sinon.stub().returns(false);
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplateStub.withArgs('index').returns(true);
|
|
|
|
|
2021-04-20 15:34:51 +01:00
|
|
|
sinon.stub(themeService, 'getActive').returns({
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplate: hasTemplateStub
|
|
|
|
});
|
|
|
|
|
2016-04-11 08:58:41 -05:00
|
|
|
res = {
|
|
|
|
locals: {version: ''},
|
2019-01-21 17:53:44 +01:00
|
|
|
render: sinon.spy()
|
2016-04-11 08:58:41 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
req = {
|
|
|
|
route: {path: '/private/?r=/'},
|
|
|
|
query: {r: ''},
|
|
|
|
params: {}
|
|
|
|
};
|
|
|
|
|
2019-06-19 11:30:28 +02:00
|
|
|
defaultPath = path.join(configUtils.config.get('paths').appRoot, '/core/frontend/apps/private-blogging/lib/views/private.hbs');
|
2016-04-11 08:58:41 -05:00
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
theme: {
|
|
|
|
permalinks: '/:slug/'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
2016-04-11 08:58:41 -05:00
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render default password page when theme has no password template', function (done) {
|
2017-03-13 23:15:50 +00:00
|
|
|
res.render = function (view, context) {
|
2016-04-11 08:58:41 -05:00
|
|
|
view.should.eql(defaultPath);
|
2017-03-13 23:15:50 +00:00
|
|
|
should.exist(context);
|
2016-04-11 08:58:41 -05:00
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-11-05 12:45:43 +00:00
|
|
|
privateController.renderer(req, res, failTest(done));
|
2016-04-11 08:58:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render theme password page when it exists', function (done) {
|
2017-03-13 23:15:50 +00:00
|
|
|
hasTemplateStub.withArgs('private').returns(true);
|
2016-04-11 08:58:41 -05:00
|
|
|
|
2017-03-13 23:15:50 +00:00
|
|
|
res.render = function (view, context) {
|
2016-04-11 08:58:41 -05:00
|
|
|
view.should.eql('private');
|
2017-03-13 23:15:50 +00:00
|
|
|
should.exist(context);
|
2016-04-11 08:58:41 -05:00
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2017-11-05 12:45:43 +00:00
|
|
|
privateController.renderer(req, res, failTest(done));
|
2016-04-11 08:58:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2017-11-05 12:45:43 +00:00
|
|
|
privateController.renderer(req, res, failTest(done));
|
2016-04-11 08:58:41 -05:00
|
|
|
});
|
|
|
|
});
|