mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
6908807236
This adds a config file that's loaded very early on during startup. It enables us to save/load settings from within Grist's admin panel, that affect the startup of the FlexServer. The config file loading: - Is type-safe, - Validates the config file on startup - Provides a path to upgrade to future versions. It should be extensible from other versions of Grist (such as desktop), by overriding `getGlobalConfig` in stubs. ---- Some minor refactors needed to occur to make this possible. This includes: - Extracting config loading into its own module (out of FlexServer). - Cleaning up the `loadConfig` function in FlexServer into `loadLoginSystem` (which is what its main purpose was before).
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import * as sinon from 'sinon';
|
|
import { assert } from 'chai';
|
|
import { IGristCoreConfig, loadGristCoreConfig, loadGristCoreConfigFile } from "app/server/lib/configCore";
|
|
import { createConfigValue, Deps, IWritableConfigValue } from "app/server/lib/config";
|
|
|
|
describe('loadGristCoreConfig', () => {
|
|
afterEach(() => {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('can be used with an in-memory store if no file config is provided', async () => {
|
|
const config = loadGristCoreConfig();
|
|
await config.edition.set("enterprise");
|
|
assert.equal(config.edition.get(), "enterprise");
|
|
});
|
|
|
|
it('will function correctly when no config file is present', async () => {
|
|
sinon.replace(Deps, 'pathExists', sinon.fake.resolves(false));
|
|
sinon.replace(Deps, 'readFile', sinon.fake.resolves(""));
|
|
const writeFileFake = sinon.fake.resolves(undefined);
|
|
sinon.replace(Deps, 'writeFile', writeFileFake);
|
|
|
|
const config = await loadGristCoreConfigFile("doesntmatter.json");
|
|
assert.exists(config.edition.get());
|
|
|
|
await config.edition.set("enterprise");
|
|
// Make sure that the change was written back to the file.
|
|
assert.isTrue(writeFileFake.calledOnce);
|
|
});
|
|
|
|
it('can be extended', async () => {
|
|
// Extend the core config
|
|
type NewConfig = IGristCoreConfig & {
|
|
newThing: IWritableConfigValue<number>
|
|
};
|
|
|
|
const coreConfig = loadGristCoreConfig();
|
|
|
|
const newConfig: NewConfig = {
|
|
...coreConfig,
|
|
newThing: createConfigValue(3)
|
|
};
|
|
|
|
// Ensure that it's backwards compatible.
|
|
const gristConfig: IGristCoreConfig = newConfig;
|
|
return gristConfig;
|
|
});
|
|
});
|