0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/test/unit/web/parent/middleware/ghost-locals_spec.js
Hannah Wolfe 213f0a4785 Moved ghost-locals mw into parent app
- Moved ghost-locals from shared to parent as it is not shared
- This file is only used in one place, this updates the code structure to reflect this
- This is one of many similar changes needed to make it easier to refactor to the existing setup
- This allows shared middleware to be unhooked from the parent app
2020-04-21 18:50:46 +01:00

42 lines
1.2 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const ghostLocals = require('../../../../../core/server/web/parent/middleware/ghost-locals');
const themeService = require('../../../../../core/frontend/services/themes');
describe('Theme Handler', function () {
let req, res, next;
beforeEach(function () {
req = sinon.spy();
res = sinon.spy();
next = sinon.spy();
sinon.stub(themeService, 'getActive').callsFake(() => {
return {
engine() {
return 'v3';
}
};
});
});
afterEach(function () {
sinon.restore();
});
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);
should.exist(res.locals.apiVersion);
res.locals.relativeUrl.should.equal(req.path);
res.locals.apiVersion.should.equal('v3');
next.called.should.be.true();
});
});
});