Ghost/core/test/utils/configUtils.js
Hannah Wolfe bc97de5fe9 Unify usage of config in unit tests
no issue

- provide a single point for accessing config in unit tests
- create a single way to set and restore config
- ensure that restore deletes top level optional keys that are now undefined
- use this._config in check deprecations, otherwise the config gets cached
- solves issues with interdependent tests
2015-12-15 10:48:24 +00:00

27 lines
747 B
JavaScript

var _ = require('lodash'),
config = require('../../server/config'),
origConfig = _.cloneDeep(config),
configUtils = {};
configUtils.config = config;
configUtils.defaultConfig = _.cloneDeep(config.get());
configUtils.set = function (newConfig) {
config.set(newConfig);
};
configUtils.restore = function () {
var topLevelOptional = ['mail', 'updateCheck', 'storage', 'forceAdminSSL', 'urlSSL', 'compress', 'privacy'];
config.set(_.merge({}, origConfig, configUtils.defaultConfig));
// @TODO make this horror go away
_.each(topLevelOptional, function (option) {
if (origConfig[option] === undefined) {
delete config[option];
}
});
};
module.exports = configUtils;