fix(cloudcmd) --console, --config-dialog: defaults

This commit is contained in:
coderaiser 2016-11-30 17:19:53 +02:00
parent e8f91f4908
commit eddb8bec4a
4 changed files with 44 additions and 9 deletions

View file

@ -49,9 +49,9 @@ const args = require('minimist')(argv.slice(2), {
root : config('root') || '/',
prefix : config('prefix') || '',
progress : config('progress'),
console : defaultTrue(config('console')),
console : config('console'),
'config-dialog': defaultTrue(config('configDialog')),
'config-dialog': config('configDialog'),
'one-panel-mode': config('onePanelMode'),
},
alias: {
@ -116,13 +116,6 @@ if (args.version) {
});
}
function defaultTrue(value) {
if (typeof value === 'undefined')
return true;
return value;
}
function validateRoot(root) {
const validate = require('../lib/server/validate');
validate.root(root, console.log);

View file

@ -78,12 +78,22 @@ module.exports = function(params) {
config(name, value);
});
config('console', defaultTrue(options.console));
config('configDialog', defaultTrue(options.configDialog));
if (p.socket)
listen(prefix, p.socket);
return cloudcmd(prefix);
};
function defaultTrue(value) {
if (typeof value === 'undefined')
return true;
return value;
}
function authCheck(socket, success) {
if (!config('auth'))
return success();

View file

@ -5,6 +5,19 @@ const io = require('socket.io-client');
const before = require('./before');
test('cloudcmd: console: enabled by default', (t) => {
before({}, (port, after) => {
const socket = io(`http://localhost:${port}/console`)
socket.once('data', (data) => {
socket.close();
t.equal(data, 'client #1 console connected\n', 'should emit data event');
after();
t.end();
});
});
});
test('cloudcmd: console: enabled', (t) => {
const config = {console: true};

View file

@ -99,3 +99,22 @@ test('cloudcmd: rest: config: patch: no configDialog: statusCode', (t) => {
});
});
test('cloudcmd: rest: config: enabled by default', (t) => {
before({}, (port, after) => {
const json = {
auth: false,
};
patch(`http://localhost:${port}/api/v1/config`, json)
.then(warp(_pullout, 'string'))
.then((result) => {
t.equal(result, 'config: ok("auth")', 'should patch config');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});