From 09a51fe90ca596a0e6c96bc1f6769bd289699c4d Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Mon, 5 Jun 2023 21:17:51 +0200 Subject: [PATCH] fix(apps.helpers): make required boolean field pass with false value --- src/server/services/apps/apps.helpers.test.ts | 2 +- src/server/services/apps/apps.helpers.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/services/apps/apps.helpers.test.ts b/src/server/services/apps/apps.helpers.test.ts index c8be7b5e..c74ffa23 100644 --- a/src/server/services/apps/apps.helpers.test.ts +++ b/src/server/services/apps/apps.helpers.test.ts @@ -183,7 +183,7 @@ describe('Test: generateEnvFile()', () => { const app = await insertApp({}, appConfig, db); // act & assert - expect(() => generateEnvFile(Object.assign(app, { config: { TEST_FIELD: undefined } }))).toThrowError('Variable TEST_FIELD is required'); + expect(() => generateEnvFile(Object.assign(app, { config: { TEST_FIELD: undefined } }))).toThrowError('Variable test is required'); }); it('Should throw an error if app does not exist', async () => { diff --git a/src/server/services/apps/apps.helpers.ts b/src/server/services/apps/apps.helpers.ts index b2dab717..6b6def1c 100644 --- a/src/server/services/apps/apps.helpers.ts +++ b/src/server/services/apps/apps.helpers.ts @@ -197,8 +197,8 @@ export const generateEnvFile = (app: App) => { const formValue = castAppConfig(app.config)[field.env_variable]; const envVar = field.env_variable; - if (formValue) { - envFile += `${envVar}=${formValue}\n`; + if (formValue || typeof formValue === 'boolean') { + envFile += `${envVar}=${String(formValue)}\n`; } else if (field.type === 'random') { if (envMap.has(envVar)) { envFile += `${envVar}=${envMap.get(envVar)}\n`; @@ -209,7 +209,7 @@ export const generateEnvFile = (app: App) => { envFile += `${envVar}=${randomString}\n`; } } else if (field.required) { - throw new Error(`Variable ${field.env_variable} is required`); + throw new Error(`Variable ${field.label || field.env_variable} is required`); } });