refactor(config) manageConfig

This commit is contained in:
coderaiser 2017-11-20 17:43:50 +02:00
parent 9c050b3c6e
commit 0d48c6b1e9
3 changed files with 50 additions and 10 deletions

View file

@ -0,0 +1,3 @@
{
"password": "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043"
}

View file

@ -9,9 +9,11 @@ const readjson = require('readjson');
const root = '../../';
const dir = root + 'server/';
const config = require(dir + 'config');
const {_cryptoPass} = config;
const pathHomeConfig = path.join(os.homedir(), '.cloudcmd.json');
const pathConfig = path.join(__dirname, '..', '..', 'json', 'config.json');
const fixture = require('./config.fixture');
const clean = (name) => {
delete require.cache[require.resolve(name)];
@ -76,3 +78,31 @@ test('config: listen: authCheck: not function', (t) => {
t.end();
});
test('config: cryptoPass: no password', (t) => {
const json = {
hello: 'world',
};
const result = _cryptoPass(json);
t.equal(result, json, 'should not change json');
t.end();
});
test('config: cryptoPass', (t) => {
const json = {
password: 'hello',
};
const {password} = fixture;
const expected = {
password,
};
const result = _cryptoPass(json);
t.deepEqual(result, expected, 'should crypt password');
t.end();
});