test.cb('expose configue handler with a custom name', t => { const configue = new Configue({defaults: {r: 2, d: 2}}); const middleware = configue.middleware('conf'); const req = {}, res = {}; middleware(req, res, () => { t.deepEqual(res, {}); t.assert(_.isFunction(req.conf)); t.assert(_.isFunction(req.conf.get)); t.assert(_.isFunction(req.conf.t)); t.is(req.conf('r'), 2); t.end(); }); });
test.cb('hapi should register correctly', t => { t.plan(6); const server = { log() {}, decorate(type, decorateName, configGetter) { t.assert(/server|request/.test(type)); t.is(decorateName, 'configue'); t.true(_.isFunction(configGetter)); } }; const plugin = new Configue().plugin(); plugin(server, {}, t.end); });
// TODO (maybe) List of key!! (filter) -> its a getALL!! /** * Load the configue into one object, eventually based on a model * * "model" is either: * - a (nested) object whose leafes are keys to be replaced by their associated value * - a function taking a config getter as argument and returning the object * * @param model eventual model to load * @returns {*} all the config or a partial model */ function load(model) { return model ? _.isFunction(model) ? model(makeConfigGetter(this)) : populateObj(this, model, getPaths(model)) : this.nconf.load(); }
test.cb('expose configue handler', t => { const configue = new Configue({defaults: {r: 2, d: 2}}); const middleware = configue.middleware(); const req = {}, res = {}; middleware(req, res, () => { t.deepEqual(res, {}); t.assert(_.isFunction(req.configue)); t.assert(_.isFunction(req.configue.get)); t.assert(_.isFunction(req.configue.t)); t.is(req.configue('r'), 2); t.end(); }); });
test.cb('hapi should register with a custom name correctly', t => { t.plan(6); const server = { log() {}, decorate(type, decorateName, configGetter) { t.assert(/server|request/.test(type)); t.is(decorateName, 'conf'); t.true(_.isFunction(configGetter)); } }; const plugin = new Configue().plugin('conf'); plugin(server, {}, t.end); });