Regression: Override via env for string settings not working (#17576)

pull/17655/head^2
Rodrigo Nascimento 5 years ago committed by GitHub
parent 615fa8c283
commit 2ebfcd492b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 107
      app/settings/server/functions/settings.tests.ts
  2. 4
      app/settings/server/functions/settings.ts

@ -73,7 +73,7 @@ describe('Settings', () => {
expect(Settings.findOne({ _id: 'my_setting2' }).value).to.be.equal(false);
});
it('should respect override via environment', () => {
it('should respect override via environment as int', () => {
process.env.OVERWRITE_SETTING_my_setting = '1';
settings.addGroup('group', function() {
@ -125,6 +125,111 @@ describe('Settings', () => {
expect(Settings.findOne({ _id: 'my_setting' })).to.include(expectedSetting);
});
it('should respect override via environment as boolean', () => {
process.env.OVERWRITE_SETTING_my_setting_bool = 'true';
settings.addGroup('group', function() {
this.section('section', function() {
this.add('my_setting_bool', false, {
type: 'boolean',
sorter: 0,
});
});
});
const expectedSetting = {
value: true,
processEnvValue: true,
valueSource: 'processEnvValue',
type: 'boolean',
sorter: 0,
group: 'group',
section: 'section',
packageValue: false,
hidden: false,
blocked: false,
secret: false,
i18nLabel: 'my_setting_bool',
i18nDescription: 'my_setting_bool_Description',
autocomplete: true,
};
expect(Settings.data.size).to.be.equal(2);
expect(Settings.upsertCalls).to.be.equal(2);
expect(Settings.findOne({ _id: 'my_setting_bool' })).to.include(expectedSetting);
process.env.OVERWRITE_SETTING_my_setting_bool = 'false';
settings.addGroup('group', function() {
this.section('section', function() {
this.add('my_setting_bool', false, {
type: 'boolean',
sorter: 0,
});
});
});
expectedSetting.value = false;
expectedSetting.processEnvValue = false;
expect(Settings.data.size).to.be.equal(2);
expect(Settings.upsertCalls).to.be.equal(3);
expect(Settings.findOne({ _id: 'my_setting_bool' })).to.include(expectedSetting);
});
it('should respect override via environment as string', () => {
process.env.OVERWRITE_SETTING_my_setting_str = 'hey';
settings.addGroup('group', function() {
this.section('section', function() {
this.add('my_setting_str', '', {
type: 'string',
sorter: 0,
});
});
});
const expectedSetting = {
value: 'hey',
processEnvValue: 'hey',
valueSource: 'processEnvValue',
type: 'string',
sorter: 0,
group: 'group',
section: 'section',
packageValue: '',
hidden: false,
blocked: false,
secret: false,
i18nLabel: 'my_setting_str',
i18nDescription: 'my_setting_str_Description',
autocomplete: true,
};
expect(Settings.data.size).to.be.equal(2);
expect(Settings.upsertCalls).to.be.equal(2);
expect(Settings.findOne({ _id: 'my_setting_str' })).to.include(expectedSetting);
process.env.OVERWRITE_SETTING_my_setting_str = 'hey ho';
settings.addGroup('group', function() {
this.section('section', function() {
this.add('my_setting_str', 'hey', {
type: 'string',
sorter: 0,
});
});
});
expectedSetting.value = 'hey ho';
expectedSetting.processEnvValue = 'hey ho';
expectedSetting.packageValue = 'hey';
expect(Settings.data.size).to.be.equal(2);
expect(Settings.upsertCalls).to.be.equal(3);
expect(Settings.findOne({ _id: 'my_setting_str' })).to.include(expectedSetting);
});
it('should respect initial value via environment', () => {
process.env.my_setting = '1';

@ -24,6 +24,8 @@ const overrideSetting = (_id: string, value: SettingValue, options: ISettingAddO
value = false;
} else if (options.type === 'int') {
value = parseInt(envValue);
} else {
value = envValue;
}
options.processEnvValue = value;
options.valueSource = 'processEnvValue';
@ -41,6 +43,8 @@ const overrideSetting = (_id: string, value: SettingValue, options: ISettingAddO
value = false;
} else if (options.type === 'int') {
value = parseInt(overwriteValue);
} else {
value = overwriteValue;
}
options.value = value;
options.processEnvValue = value;

Loading…
Cancel
Save