From cb8553896f9cae21488a817490f621d0668034c3 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 30 Jul 2023 14:40:54 +0200 Subject: [PATCH] Fixing settings setting tests #683 --- src/backend/Environment.ts | 1 + src/common/config/private/Config.ts | 4 ++++ test/backend/unit/middlewares/admin/SettingsMWs.ts | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/Environment.ts b/src/backend/Environment.ts index 3a059b94..9325a3a3 100644 --- a/src/backend/Environment.ts +++ b/src/backend/Environment.ts @@ -1,4 +1,5 @@ /** * Keeps the environment context + * Only use it in the Config constructor */ export const ServerEnvironment: { sendMailAvailable?: boolean } = {}; diff --git a/src/common/config/private/Config.ts b/src/common/config/private/Config.ts index 7f1f01b7..00cda39e 100644 --- a/src/common/config/private/Config.ts +++ b/src/common/config/private/Config.ts @@ -7,6 +7,7 @@ import {IConfigClass} from 'typeconfig/common'; import {PasswordHelper} from '../../../backend/model/PasswordHelper'; import {TAGS} from '../public/ClientConfig'; import {ServerEnvironment} from '../../../backend/Environment'; +import {EmailMessagingType} from './MessagingConfig'; declare const process: any; @@ -82,6 +83,9 @@ export class PrivateConfigClass extends ServerConfig { this.Environment.isDocker = !!process.env.PI_DOCKER; if (typeof ServerEnvironment.sendMailAvailable !== 'undefined') { this.Environment.sendMailAvailable = ServerEnvironment.sendMailAvailable; + if(!this.Environment.sendMailAvailable){ //onNewValue is not yet available as a callback + this.Messaging.Email.type = EmailMessagingType.SMTP; + } } } diff --git a/test/backend/unit/middlewares/admin/SettingsMWs.ts b/test/backend/unit/middlewares/admin/SettingsMWs.ts index f7bd0973..de55023f 100644 --- a/test/backend/unit/middlewares/admin/SettingsMWs.ts +++ b/test/backend/unit/middlewares/admin/SettingsMWs.ts @@ -6,6 +6,8 @@ import {SettingsMWs} from '../../../../../src/backend/middlewares/admin/Settings import {ServerUserConfig} from '../../../../../src/common/config/private/PrivateConfig'; import {Config} from '../../../../../src/common/config/private/Config'; import {UserRoles} from '../../../../../src/common/entities/UserDTO'; +import {ConfigClassBuilder} from '../../../../../node_modules/typeconfig/node'; +import {ServerEnvironment} from '../../../../../src/backend/Environment'; declare const describe: any; @@ -19,6 +21,8 @@ describe('Settings middleware', () => { }); it('should save empty enforced users settings', (done: (err?: any) => void) => { + + ServerEnvironment.sendMailAvailable = false; const req: any = { session: {}, sessionOptions: {}, @@ -26,12 +30,13 @@ describe('Settings middleware', () => { params: {}, body: { settingsPath: 'Users', - settings: new ServerUserConfig() + settings: ConfigClassBuilder.attachPrivateInterface(new ServerUserConfig()).toJSON() } }; req.body.settings.enforcedUsers = []; const next: any = (err: ErrorDTO) => { try { + expect(err).to.be.undefined; expect(Config.Users.enforcedUsers.length).to.be.equal(0); done(); } catch (err) {