Skip to content

Commit

Permalink
Refactored to use DI for settingsOverrides for easier e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmraible committed Jan 30, 2025
1 parent 685ccdd commit 9146c00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 5 additions & 4 deletions ghost/core/core/shared/settings-cache/CacheManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ class CacheManager {
/**
* @prop {Object} options
* @prop {Object} options.publicSettings - key/value pairs of settings which are publicly accessible
* @prop {Object} options.settingsOverrides - key/value pairs of settings which are overridden via config
*/
constructor({publicSettings, settingsOverrides}) {
constructor({publicSettings}) {
// settingsCache holds cached settings, keyed by setting.key, contains the JSON version of the model
this.settingsCache;
this.settingsOverrides;
this.publicSettings = publicSettings;
this.settingsOverrides = settingsOverrides;
this.calculatedFields = [];

this.get = this.get.bind(this);
Expand Down Expand Up @@ -186,10 +185,12 @@ class CacheManager {
* @param {Bookshelf.Collection<Settings>} settingsCollection
* @param {Array} calculatedFields
* @param {Object} cacheStore - cache storage instance base on Cache Base Adapter
* @param {Object} settingsOverrides - key/value pairs of settings which are overridden (i.e. via config)
* @return {Object} - filled out instance for Cache Base Adapter
*/
init(events, settingsCollection, calculatedFields, cacheStore) {
init(events, settingsCollection, calculatedFields, cacheStore, settingsOverrides) {
this.settingsCache = cacheStore;
this.settingsOverrides = settingsOverrides;
// First, reset the cache and
this.reset(events);

Expand Down
3 changes: 1 addition & 2 deletions ghost/core/core/shared/settings-cache/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const CacheManager = require('./CacheManager');
const publicSettings = require('./public');
const config = require('../config');

const cacheManager = new CacheManager({publicSettings, settingsOverrides: config.get('hostSettings:settingsOverrides')});
const cacheManager = new CacheManager({publicSettings});

module.exports = cacheManager;
5 changes: 2 additions & 3 deletions ghost/core/test/unit/shared/settings-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ should.equal(true, true);
function createCacheManager(settingsOverrides = {}) {
const cacheStore = new InMemoryCache();
const cache = new CacheManager({
publicSettings,
settingsOverrides
publicSettings
});
cache.init(events, {}, [], cacheStore);
cache.init(events, {}, [], cacheStore, settingsOverrides);
return cache;
}

Expand Down

0 comments on commit 9146c00

Please sign in to comment.