0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00
ghost/core/test/unit/services/labs_spec.js
Hannah Wolfe 7a36200e24 🐛 Ensure deprecated labs flags are unset
fixes #11343

- solves the case where themes depends on old labs flags that are now always false, but the DB still has the feature set to true
- add concept of deprecated labs flags to the labs service
- make sure that the labs service gets used in our theme middleware
- added tests and other small fixes
2019-11-06 14:42:39 +07:00

52 lines
1.5 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const settingsCache = require('../../../server/services/settings/cache');
const labs = require('../../../server/services/labs');
describe('Labs Service', function () {
let labsCacheStub;
beforeEach(function () {
labsCacheStub = sinon.stub(settingsCache, 'get').withArgs('labs');
});
afterEach(function () {
sinon.restore();
});
it('can getAll, even if empty', function () {
labs.getAll().should.eql({});
});
it('can getAll from cache', function () {
labsCacheStub.returns({members: true, foo: 'bar'});
labs.getAll().should.eql({members: true, foo: 'bar'});
});
it('can getAll from cache, ignoring deprecated', function () {
labsCacheStub.returns({members: true, foo: 'bar', subscribers: false, publicAPI: true});
labs.getAll().should.eql({members: true, foo: 'bar'});
});
it('isSet returns true string flag', function () {
labsCacheStub.returns({foo: 'bar'});
labs.isSet('foo').should.be.true;
});
it('isSet returns false for undefined', function () {
labsCacheStub.returns({foo: 'bar'});
labs.isSet('bar').should.be.false;
});
it('isSet always returns false for deprecated', function () {
labsCacheStub.returns({subscribers: true, publicAPI: true});
labs.isSet('subscribers').should.be.false;
labs.isSet('publicAPI').should.be.false;
});
});