MOBILE-3833 config: Fix patching in tests
parent
1db5b85e40
commit
faec9c4a8e
|
@ -153,6 +153,7 @@ export class CoreConstants {
|
||||||
static enableDevTools(): boolean {
|
static enableDevTools(): boolean {
|
||||||
// @todo [4.0] This is not the proper way to check for development tools, we should rely only on the BUILD variable.
|
// @todo [4.0] This is not the proper way to check for development tools, we should rely only on the BUILD variable.
|
||||||
return this.BUILD.isDevelopment
|
return this.BUILD.isDevelopment
|
||||||
|
|| this.BUILD.isTesting
|
||||||
|| this.CONFIG.versionname.includes('-dev');
|
|| this.CONFIG.versionname.includes('-dev');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,15 +164,21 @@ export class CoreConfigProvider {
|
||||||
* Update config with the given values.
|
* Update config with the given values.
|
||||||
*
|
*
|
||||||
* @param config Config updates.
|
* @param config Config updates.
|
||||||
* @param reset Whether to reset environment before applying the patch.
|
* @param options Patching options.
|
||||||
|
* - reset: Whether to reset environment before applying the patch.
|
||||||
|
* - patchDefault: Whether to patch default values as well.
|
||||||
*/
|
*/
|
||||||
patchEnvironment(config: Partial<EnvironmentConfig>, reset: boolean = false): void {
|
patchEnvironment(config: Partial<EnvironmentConfig>, options: Partial<{ reset: boolean; patchDefault: boolean }> = {}): void {
|
||||||
this.defaultEnvironment = this.defaultEnvironment ?? { ...CoreConstants.CONFIG };
|
this.defaultEnvironment = this.defaultEnvironment ?? { ...CoreConstants.CONFIG };
|
||||||
|
|
||||||
if (reset) {
|
if (options.reset) {
|
||||||
this.resetEnvironmentSilently();
|
this.resetEnvironmentSilently();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.patchDefault) {
|
||||||
|
Object.assign(this.defaultEnvironment, config);
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(CoreConstants.CONFIG, config);
|
Object.assign(CoreConstants.CONFIG, config);
|
||||||
CoreEvents.trigger(CoreConfigProvider.ENVIRONMENT_UPDATED, CoreConstants.CONFIG);
|
CoreEvents.trigger(CoreConfigProvider.ENVIRONMENT_UPDATED, CoreConstants.CONFIG);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +205,7 @@ export class CoreConfigProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}'));
|
this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}'), { patchDefault: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue