-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,111 @@ | ||
process.env.NODE_ENV = 'test' | ||
|
||
const { assert } = require('chai'); | ||
const fs = require('fs'); | ||
const { | ||
getConfig, | ||
setConfig, | ||
configAction, | ||
stringify, | ||
configPath, | ||
fetchConfig, | ||
configMessages | ||
configMessages, | ||
} = require('../config'); | ||
|
||
const fetchConfigJSON = () => fetchConfig().configJSON; | ||
|
||
const setConfigErr = 'INVALID: setConfig takes two arguments: "keys" and "value"'; | ||
const invalidConfigActionErr = 'INVALID: non-existent action given to ballin_config'; | ||
const currentConfigJSON = fetchConfigJSON(); | ||
|
||
const setTest = (keys, value) => { | ||
setConfig(keys, value); | ||
assert.deepEqual(value, getConfig(keys, value)) | ||
} | ||
|
||
assert.deepEqual(value, getConfig(keys)); | ||
}; | ||
|
||
describe('config', () => { | ||
|
||
let savedConfig; | ||
before('fetchConfigJSON should return a String', () => { | ||
assert.typeOf(fetchConfigJSON(), 'String'); | ||
}) | ||
}); | ||
after('tests shouldn\'t alter config', () => { | ||
assert.equal(currentConfigJSON, fetchConfigJSON()); | ||
}) | ||
}); | ||
beforeEach('Save config', () => { | ||
savedConfig = fetchConfigJSON(); | ||
assert.typeOf(savedConfig, 'String'); | ||
}) | ||
}); | ||
afterEach('Reset config', () => { | ||
fs.writeFileSync(configPath, savedConfig, 'utf8'); | ||
}) | ||
}); | ||
|
||
describe('getConfig', () => { | ||
it('("theme") should return an Object', () => { | ||
assert.isObject(getConfig('theme')) | ||
}) | ||
assert.isObject(getConfig('theme')); | ||
}); | ||
it('("theme.dark") should return an Array', () => { | ||
assert.isArray(getConfig('theme.dark')) | ||
}) | ||
assert.isArray(getConfig('theme.dark')); | ||
}); | ||
it('("gu.id") should return a String', () => { | ||
assert.isString(getConfig('gu.id')) | ||
}) | ||
assert.isString(getConfig('gu.id')); | ||
}); | ||
it('("up.cleanup") should return a Boolean', () => { | ||
assert.isBoolean(getConfig('up.cleanup')) | ||
}) | ||
assert.isBoolean(getConfig('up.cleanup')); | ||
}); | ||
it('() should return a String', () => { | ||
assert.isString(getConfig()) | ||
}) | ||
assert.isString(getConfig()); | ||
}); | ||
it('should return an error if given keys that don\'t exist', () => { | ||
assert.equal(getConfig('wrong'), '"wrong" doesn\'t exist in config') | ||
}) | ||
assert.equal(getConfig('wrong'), '"wrong" doesn\'t exist in config'); | ||
}); | ||
}); | ||
|
||
|
||
describe('setConfig', () => { | ||
let savedConfig = ''; | ||
const initialConfig = fetchConfigJSON(); | ||
|
||
after('setConfig tests shouldn\'t alter config', () => { | ||
assert.equal(fetchConfigJSON(), initialConfig) | ||
}) | ||
assert.equal(fetchConfigJSON(), initialConfig); | ||
}); | ||
|
||
it('should set theme.dark', () => { | ||
setTest('theme.dark', ['rainbow', 'rainbow-lite']) | ||
}) | ||
setTest('theme.dark', ['rainbow', 'rainbow-lite']); | ||
}); | ||
it('should set up.cleanup', () => { | ||
setTest('up.cleanup', 'test'); | ||
}) | ||
}); | ||
it('should set gu.id', () => { | ||
setTest('gu.id', '123'); | ||
}) | ||
}); | ||
it('should give error if given no arguments', () => { | ||
assert.equal(setConfig(), setConfigErr) | ||
}) | ||
assert.equal(setConfig(), configMessages.setArgsErr); | ||
}); | ||
it('should give error if given 3 arguments', () => { | ||
assert.equal(setConfig('a','b','c'), setConfigErr) | ||
}) | ||
assert.equal(setConfig('a', 'b', 'c'), configMessages.setArgsErr); | ||
}); | ||
it('should return the keys/value it set', () => { | ||
const keys = 'theme.light'; | ||
const val = 'new theme'; | ||
assert.equal(setConfig(keys, val), `"${keys}" set to: "${val}"`) | ||
}) | ||
}) | ||
assert.equal(setConfig(keys, val), `"${keys}" set to: "${val}"`); | ||
}); | ||
}); | ||
|
||
describe('configAction', () => { | ||
it('() should return a String', () => { | ||
assert.typeOf(configAction('get'), 'string'); | ||
}) | ||
}); | ||
it('("get") should return a String', () => { | ||
assert.typeOf(configAction('get'), 'string'); | ||
}) | ||
}); | ||
it('("set") should return a setConfig error', () => { | ||
assert.equal(configAction('set'), setConfigErr) | ||
}) | ||
assert.equal(configAction('set'), configMessages.setArgsErr); | ||
}); | ||
it('("get", "gu.id") should return a Number', () => { | ||
assert.typeOf(configAction('get', 'gu.id'), 'string') | ||
}) | ||
assert.typeOf(configAction('get', 'gu.id'), 'string'); | ||
}); | ||
it('("get", "theme.light") should return an Array', () => { | ||
assert.isArray(configAction('get', 'theme.light')) | ||
}) | ||
assert.isArray(configAction('get', 'theme.light')); | ||
}); | ||
it('("wrong") should return an invalid error', () => { | ||
assert.equal(configAction('wrong'), invalidConfigActionErr); | ||
}) | ||
assert.equal(configAction('wrong'), configMessages.actionErr); | ||
}); | ||
it('("set", "gu.id", "123") should set gu.id to "123"', () => { | ||
setTest('gu.id', '123', configAction); | ||
}) | ||
}) | ||
|
||
}) | ||
}); | ||
}); | ||
}); |