From 016b5c79f927f0e63ec48511f5b68fce4dc38b47 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 8 Nov 2017 17:40:14 +0200 Subject: [PATCH] test(cloudcmd) getPrefix --- server/cloudcmd.js | 16 +++++++++------- test/server/cloudcmd.js | 14 +++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/server/cloudcmd.js b/server/cloudcmd.js index 3c9e712c..636998a5 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -41,13 +41,6 @@ const clean = (a) => a.filter(notEmpty); const isDev = process.env.NODE_ENV === 'development'; -function getPrefix(prefix) { - if (typeof prefix === 'function') - return prefix() || ''; - - return prefix || ''; -} - module.exports = (params) => { const p = params || {}; const options = p.config || {}; @@ -99,6 +92,15 @@ function defaultValue(name, options) { return value; } +module.exports._getPrefix = getPrefix; +function getPrefix(prefix) { + if (typeof prefix === 'function') + return prefix() || ''; + + return prefix || ''; +} + + function authCheck(socket, success) { if (!config('auth')) return success(); diff --git a/test/server/cloudcmd.js b/test/server/cloudcmd.js index 661cd97c..0f0868d4 100644 --- a/test/server/cloudcmd.js +++ b/test/server/cloudcmd.js @@ -8,7 +8,10 @@ const currify = require('currify'); const DIR = '../../server/'; const cloudcmd = require(DIR + 'cloudcmd'); const config = require(DIR + 'config'); -const {_authenticate} = cloudcmd; +const { + _authenticate, + _getPrefix, +} = cloudcmd; test('cloudcmd: args: no', (t) => { const fn = () => cloudcmd(); @@ -49,6 +52,15 @@ test('cloudcmd: defaults: console', (t) => { t.end(); }); +test('cloudcmd: getPrefix', (t) => { + const value = 'hello'; + const fn = () => value; + const result = _getPrefix(fn); + + t.equal(result, value, 'should equal') + t.end(); +}); + test('cloudcmd: authenticate: reject', (t) => { const success = sinon.stub(); const emit = sinon.stub();