fix(config) config dialog: save changes

This commit is contained in:
coderaiser 2017-01-17 14:23:04 +02:00
parent 7a9f50c0da
commit ffa8a44320
2 changed files with 42 additions and 10 deletions

View file

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