2018-10-17 09:23:57 +02:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-10-06 11:12:21 +01:00
|
|
|
const ghostLocals = require('../../../../../../core/server/web/parent/middleware/ghost-locals');
|
|
|
|
const bridge = require('../../../../../../core/bridge');
|
2016-10-10 20:14:32 +01:00
|
|
|
|
|
|
|
describe('Theme Handler', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
let req;
|
|
|
|
let res;
|
|
|
|
let next;
|
2016-10-10 20:14:32 +01:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
req = sinon.spy();
|
|
|
|
res = sinon.spy();
|
|
|
|
next = sinon.spy();
|
2018-10-17 09:23:57 +02:00
|
|
|
|
2021-04-23 14:19:18 +01:00
|
|
|
sinon.stub(bridge, 'getActiveTheme').callsFake(() => {
|
2019-08-19 12:41:09 +01:00
|
|
|
return {
|
|
|
|
engine() {
|
2019-09-18 10:27:23 +02:00
|
|
|
return 'v3';
|
2019-08-19 12:41:09 +01:00
|
|
|
}
|
|
|
|
};
|
2018-10-17 09:23:57 +02:00
|
|
|
});
|
2017-03-21 08:24:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
2016-10-10 20:14:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('ghostLocals', function () {
|
|
|
|
it('sets all locals', function () {
|
|
|
|
req.path = '/awesome-post';
|
|
|
|
|
|
|
|
ghostLocals(req, res, next);
|
|
|
|
|
|
|
|
res.locals.should.be.an.Object();
|
|
|
|
should.exist(res.locals.version);
|
|
|
|
should.exist(res.locals.safeVersion);
|
2018-10-17 09:23:57 +02:00
|
|
|
should.exist(res.locals.apiVersion);
|
2016-10-10 20:14:32 +01:00
|
|
|
res.locals.relativeUrl.should.equal(req.path);
|
2019-09-18 10:27:23 +02:00
|
|
|
res.locals.apiVersion.should.equal('v3');
|
2016-10-10 20:14:32 +01:00
|
|
|
next.called.should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|