SDA-4606 Setting programmatically default values of new config fields (#2171)

* SDA-4606 Setting programmatically default values of new config fields

* Upgrade electron to patch reported file picker issue
This commit is contained in:
Salah Benmoussati 2024-07-15 09:31:54 +02:00 committed by GitHub
parent afef6e77c1
commit defcd1a90a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 2 deletions

View File

@ -178,7 +178,7 @@
"builder-util-runtime": "^9.0.3",
"cross-env": "7.0.3",
"del": "3.0.0",
"electron": "31.1.0",
"electron": "31.2.0",
"electron-builder": "^24.13.2",
"electron-devtools-installer": "^3.2.0",
"electron-icon-maker": "0.0.5",

View File

@ -1,7 +1,11 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { IConfig, IGlobalConfig } from '../src/app/config-handler';
import {
ConfigFieldsDefaultValues,
IConfig,
IGlobalConfig,
} from '../src/app/config-handler';
jest.mock('electron-log');
jest.mock('../src/app/auto-update-handler', () => {
@ -88,6 +92,32 @@ describe('config', () => {
expect(configField).toEqual({});
});
it('should retrieve default values when field not present in either user or global config', () => {
const fieldMock: string[] = [
'isPodUrlEditable',
'forceAutoUpdate',
'enableBrowserLogin',
'browserLoginAutoConnect',
'latestAutoUpdateChannelEnabled',
'betaAutoUpdateChannelEnabled',
];
const globalConfig: object = { url: 'test' };
const userConfig: object = { configVersion: '4.0.1' };
// creating temp file
writeConfigFile(globalConfig);
writeUserFile(userConfig);
// changing path from /Users/.../SymphonyElectron/config/Symphony.config to temp path
configInstance.globalConfigPath = globalConfigDir;
configInstance.userConfigPath = userConfigDir;
configInstance.readGlobalConfig();
configInstance.readUserConfig();
const configField: IConfig = configInstance.getConfigFields(fieldMock);
expect(configField).toEqual({ ...ConfigFieldsDefaultValues });
});
it('should succeed when only present in user config', () => {
const fieldMock: string[] = ['url'];
const globalConfig: object = { url: 'something' };

View File

@ -31,6 +31,15 @@ export enum CloudConfigDataTypes {
DISABLED = 'DISABLED',
}
export const ConfigFieldsDefaultValues: Partial<IConfig> = {
isPodUrlEditable: true,
forceAutoUpdate: false,
enableBrowserLogin: false,
browserLoginAutoConnect: false,
latestAutoUpdateChannelEnabled: true,
betaAutoUpdateChannelEnabled: true,
};
export const ConfigFieldsToRestart = new Set([
'permissions',
'disableThrottling',
@ -284,6 +293,7 @@ class Config {
*/
public getConfigFields(fields: string[]): IConfig {
const configFields: IConfig = {
...this.getConfigfromDefaultFields(fields),
...this.getGlobalConfigFields(fields),
...this.getUserConfigFields(fields),
...this.getFilteredCloudConfigFields(fields),
@ -313,6 +323,23 @@ class Config {
return userConfigData;
}
/**
* Returns default value of specified fields
*
* @param fields {Array}
*/
public getConfigfromDefaultFields(fields: string[]): IGlobalConfig {
const defaultConfigData = pick(
ConfigFieldsDefaultValues,
fields,
) as IGlobalConfig;
logger.info(
`config-handler: getting default config values for the fields ${fields}`,
defaultConfigData,
);
return defaultConfigData;
}
/**
* Returns the specified fields from global config file
*