mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
Added test cases.
This commit is contained in:
parent
1905e69463
commit
152ab23104
3 changed files with 82 additions and 71 deletions
|
@ -705,8 +705,6 @@ const lookupEnvironmentVariables = (obj: MapArrayType<any>) => {
|
|||
|
||||
replaceEnvs(obj);
|
||||
|
||||
const envVars: MapArrayType<any> = {}
|
||||
|
||||
// Add plugin ENV variables
|
||||
|
||||
/**
|
||||
|
@ -720,7 +718,6 @@ const lookupEnvironmentVariables = (obj: MapArrayType<any>) => {
|
|||
if (!env.startsWith("EP")) continue
|
||||
treeEntries.set(env, envVal)
|
||||
}
|
||||
|
||||
treeEntries.forEach((value, key) => {
|
||||
let pathToKey = key.split("__")
|
||||
let currentNode = root
|
||||
|
@ -730,9 +727,9 @@ const lookupEnvironmentVariables = (obj: MapArrayType<any>) => {
|
|||
})
|
||||
|
||||
//console.log(root.collectFromLeafsUpwards())
|
||||
//const rooting = root.collectFromLeafsUpwards()
|
||||
|
||||
obj = Object.assign(obj, envVars)
|
||||
const rooting = root.collectFromLeafsUpwards()
|
||||
console.log("Rooting is", rooting.ADMIN)
|
||||
obj = Object.assign(obj, rooting)
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
|
|
@ -73,23 +73,6 @@ export class SettingsNode {
|
|||
return collected;
|
||||
}
|
||||
|
||||
|
||||
public transformObjectWithArrays() {
|
||||
function isNumeric(str: string|object) {
|
||||
if (typeof str != "string") return false // we only process strings!
|
||||
// @ts-ignore
|
||||
return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
||||
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
|
||||
}
|
||||
let collected: MapArrayType<any> = {};
|
||||
for (const key in this.children) {
|
||||
if (isNumeric(key)) {
|
||||
Object.entries(this.children).map(([key, value]) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coerceValue = (stringValue: string) => {
|
||||
// cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
|
||||
// @ts-ignore
|
||||
|
|
|
@ -7,7 +7,7 @@ import process from 'process';
|
|||
|
||||
describe(__filename, function () {
|
||||
describe('parseSettings', function () {
|
||||
let settings:any;
|
||||
let settings: any;
|
||||
const envVarSubstTestCases = [
|
||||
{name: 'true', val: 'true', var: 'SET_VAR_TRUE', want: true},
|
||||
{name: 'false', val: 'false', var: 'SET_VAR_FALSE', want: false},
|
||||
|
@ -58,4 +58,35 @@ describe(__filename, function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("Parse plugin settings", function () {
|
||||
|
||||
before(async function () {
|
||||
process.env["EP__ADMIN__PASSWORD"] = "test"
|
||||
})
|
||||
|
||||
it('should parse plugin settings', async function () {
|
||||
let settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert.equal(settings.ADMIN.PASSWORD, "test");
|
||||
})
|
||||
|
||||
it('should bundle settings with same path', async function () {
|
||||
process.env["EP__ADMIN__USERNAME"] = "test"
|
||||
let settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert.deepEqual(settings.ADMIN, {PASSWORD: "test", USERNAME: "test"});
|
||||
})
|
||||
|
||||
it("Can set the ep themes", async function () {
|
||||
process.env["EP__ep_themes__default_theme"] = "hacker"
|
||||
let settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert.deepEqual(settings.ep_themes, {"default_theme": "hacker"});
|
||||
})
|
||||
|
||||
it("can set the ep_webrtc settings", async function () {
|
||||
process.env["EP__ep_webrtc__enabled"] = "true"
|
||||
let settings = parseSettings(path.join(__dirname, 'settings.json'), true);
|
||||
assert.deepEqual(settings.ep_webrtc, {"enabled": true});
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue