0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/test/unit/services/settings/settings.test.js
Naz 4a47e8d0a8 Changed settings loader module API signature
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- It was not clear from the module signature/usages that the default method is executing synchronously. The change makes it explicit. Knowing if the method is synchronous is helpful to stop possible pefr bottlenecks!
2021-09-28 04:59:41 +13:00

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.loadSettingsSync', 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.loadSettingsSync', 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();
}
});
});
});