mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(config) config dialog: save changes
This commit is contained in:
parent
7a9f50c0da
commit
ffa8a44320
2 changed files with 42 additions and 10 deletions
|
|
@ -29,6 +29,8 @@ const readjsonSync = (name) => jju.parse(fs.readFileSync(name, 'utf8'), {
|
|||
mode: 'json'
|
||||
});
|
||||
|
||||
const key = (a) => Object.keys(a).pop();
|
||||
|
||||
let config;
|
||||
let error = tryCatch(() => {
|
||||
config = readjsonSync(ConfigHome);
|
||||
|
|
@ -95,12 +97,13 @@ function connection(socket) {
|
|||
return socket.emit('err', 'Error: Wrong data type!');
|
||||
|
||||
cryptoPass(json);
|
||||
traverse(json);
|
||||
|
||||
save((error) => {
|
||||
if (error)
|
||||
return socket.emit('err', error.message);
|
||||
|
||||
const data = traverse(json);
|
||||
const data = CloudFunc.formatMsg('config', key(json));
|
||||
|
||||
socket.broadcast.send(json);
|
||||
socket.send(json);
|
||||
|
|
@ -158,14 +161,15 @@ function patch(req, res, callback) {
|
|||
|
||||
if (error)
|
||||
return callback(error);
|
||||
|
||||
|
||||
cryptoPass(json);
|
||||
traverse(json);
|
||||
|
||||
save((error) => {
|
||||
if (error)
|
||||
return ponse.sendError(error, options);
|
||||
|
||||
const data = traverse(json);
|
||||
const data = CloudFunc.formatMsg('config', key(json));
|
||||
|
||||
ponse.send(data, options);
|
||||
});
|
||||
|
|
@ -173,14 +177,9 @@ function patch(req, res, callback) {
|
|||
}
|
||||
|
||||
function traverse(json) {
|
||||
let data;
|
||||
|
||||
Object.keys(json).forEach((name) => {
|
||||
data = CloudFunc.formatMsg('config', name);
|
||||
manage(name, json[name]);
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function cryptoPass(json) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const test = require('tape');
|
||||
const promisify = require('es6-promisify');
|
||||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
const manageConfig = require('../../server/config');
|
||||
const readjson = require('readjson');
|
||||
const writejson = require('writejson');
|
||||
|
||||
const manageConfig = require('../../server/config');
|
||||
const before = require('../before');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
const pathConfig = path.join(os.homedir(), '.cloudcmd.json');
|
||||
|
||||
const get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
});
|
||||
|
|
@ -114,7 +121,7 @@ test('cloudcmd: rest: config: enabled by default', (t) => {
|
|||
patch(`http://localhost:${port}/api/v1/config`, json)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then((result) => {
|
||||
t.equal(result, 'config: ok("auth")', 'should patch config');
|
||||
t.equal(result, 'config: ok("auth")', 'should send message');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
|
|
@ -124,3 +131,29 @@ test('cloudcmd: rest: config: enabled by default', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: config: patch: save config', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const json = {
|
||||
editor: 'dword',
|
||||
};
|
||||
|
||||
let originalConfig = readjson.sync.try(pathConfig);
|
||||
|
||||
patch(`http://localhost:${port}/api/v1/config`, json)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(() => {
|
||||
const config = readjson.sync(pathConfig);
|
||||
t.equal(config.editor, 'dword', 'should change config file on patch');
|
||||
t.end();
|
||||
|
||||
if (originalConfig)
|
||||
writejson.sync(pathConfig, originalConfig);
|
||||
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue