test(cloudcmd) getPrefix

This commit is contained in:
coderaiser 2017-11-08 17:40:14 +02:00
parent 10255164d5
commit 016b5c79f9
2 changed files with 22 additions and 8 deletions

View file

@ -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();

View file

@ -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();