From faec9c4a8e44f2e74a36252170293514f5758b8e Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 15 Mar 2022 10:36:51 +0100 Subject: [PATCH] MOBILE-3833 config: Fix patching in tests --- src/core/constants.ts | 1 + src/core/services/config.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/constants.ts b/src/core/constants.ts index 0fcd0ddd3..cabb5585f 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -153,6 +153,7 @@ export class CoreConstants { 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. return this.BUILD.isDevelopment + || this.BUILD.isTesting || this.CONFIG.versionname.includes('-dev'); } diff --git a/src/core/services/config.ts b/src/core/services/config.ts index 012e7c7bd..eb2221487 100644 --- a/src/core/services/config.ts +++ b/src/core/services/config.ts @@ -164,15 +164,21 @@ export class CoreConfigProvider { * Update config with the given values. * * @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, reset: boolean = false): void { + patchEnvironment(config: Partial, options: Partial<{ reset: boolean; patchDefault: boolean }> = {}): void { this.defaultEnvironment = this.defaultEnvironment ?? { ...CoreConstants.CONFIG }; - if (reset) { + if (options.reset) { this.resetEnvironmentSilently(); } + if (options.patchDefault) { + Object.assign(this.defaultEnvironment, config); + } + Object.assign(CoreConstants.CONFIG, config); CoreEvents.trigger(CoreConfigProvider.ENVIRONMENT_UPDATED, CoreConstants.CONFIG); } @@ -199,7 +205,7 @@ export class CoreConfigProvider { return; } - this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}')); + this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}'), { patchDefault: true }); } /**