mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - 'knowSettings' was based on a "configurable" array of settings that might be configured in Ghost. The multitude never happened! The only setting the frontend takes care of is routes.yaml file (redirects is also kind of a setting but is a separate concept for now). - Having just one type of file to deal with allows to simplify implementation significantly, which helps before a big refactor
55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
const sinon = require('sinon');
|
|
const should = require('should');
|
|
const rewire = require('rewire');
|
|
const errors = require('@tryghost/errors');
|
|
const settings = rewire('../../../../core/frontend/services/settings');
|
|
|
|
describe('UNIT > Settings Service:', function () {
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('get', function () {
|
|
let settingsLoaderStub;
|
|
|
|
const settingsStubFile = {
|
|
routes: null,
|
|
collections: {
|
|
'/': {
|
|
permalink: '/{slug}/',
|
|
template: ['home', 'index']
|
|
}
|
|
},
|
|
resources: {tag: '/tag/{slug}/', author: '/author/{slug}/'}
|
|
};
|
|
|
|
beforeEach(function () {
|
|
settingsLoaderStub = sinon.stub();
|
|
});
|
|
|
|
it('returns settings object for `routes`', function () {
|
|
settingsLoaderStub.returns(settingsStubFile);
|
|
settings.__set__('SettingsLoader', settingsLoaderStub);
|
|
|
|
const result = settings.get();
|
|
should.exist(result);
|
|
result.should.be.an.Object().with.properties('routes', 'collections', 'resources');
|
|
settingsLoaderStub.calledOnce.should.be.true();
|
|
});
|
|
|
|
it('passes SettingsLoader error through', function (done) {
|
|
settingsLoaderStub.throws(new errors.GhostError({message: 'oops'}));
|
|
settings.__set__('SettingsLoader', settingsLoaderStub);
|
|
|
|
try {
|
|
settings.get();
|
|
done(new Error('SettingsLoader should fail'));
|
|
} catch (err) {
|
|
should.exist(err);
|
|
err.message.should.be.eql('oops');
|
|
settingsLoaderStub.calledOnce.should.be.true();
|
|
done();
|
|
}
|
|
});
|
|
});
|
|
});
|