diff --git a/lib/server/config.js b/lib/server/config.js index 8a9d88b1..49367ed5 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -59,15 +59,13 @@ module.exports.listen = function(socket, authCheck) { }; function manage(key, value) { - var result; + if (!key) + return; + + if (value === undefined) + return config[key]; - if (key) - if (value === undefined) - result = config[key]; - else - config[key] = value; - - return result; + config[key] = value; } function save(callback) { diff --git a/test/lib/config.js b/test/lib/config.js new file mode 100644 index 00000000..ab33aa39 --- /dev/null +++ b/test/lib/config.js @@ -0,0 +1,44 @@ +'use strict'; + +const test = require('tape'); +const root = '../../'; +const config = require(root + 'lib/server/config'); + +const promisify = require('es6-promisify'); +const pullout = require('pullout'); +const request = require('request'); + +const before = require('../before'); + +test('config: manage', (t) => { + t.equal(undefined, config(), 'should return "undefined"'); + t.end(); +}); + +test('config: manage: get', (t) => { + const editor = 'deepword'; + const conf = { + editor + }; + + before({config: conf}, (port, after) => { + t.equal(editor, config('editor'), 'should get config'); + t.end(); + after(); + }); +}); + +test('config: manage: get', (t) => { + const editor = 'deepword'; + const conf = { + editor + }; + + before({config: conf}, (port, after) => { + config('editor', 'dword'); + t.equal('dword', config('editor'), 'should set config'); + t.end(); + after(); + }); +}); +