Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
test: add unit tests
johaven3717339058e2
diff --git a/backend/src/app.service.spec.ts b/backend/src/app.service.spec.tsindex c9090f1a..9c3dff53 100644--- a/backend/src/app.service.spec.ts+++ b/backend/src/app.service.spec.ts@@ -6,8 +6,13 @@import { Logger } from '@nestjs/common'import cluster from 'node:cluster'+import fs from 'node:fs'+import os from 'node:os'+import path from 'node:path'+import process from 'node:process'import { AppService } from './app.service'-import { configuration } from './configuration/config.environment'+import { ENVIRONMENT_PREFIX } from './configuration/config.constants'+import { configuration, exportConfiguration } from './configuration/config.environment'describe(AppService.name, () => {let appService: AppService@@ -42,4 +47,29 @@ describe(AppService.name, () => {expect(callBack).toHaveBeenCalledTimes(1)spyExit.mockClear()})++ it(`should use ${ENVIRONMENT_PREFIX} environment variables to override the configuration`, () => {+ let conf = exportConfiguration()+ expect(conf.applications.files.onlyoffice.secret).toBe(undefined)+ expect(conf.logger.stdout).toBe(true)+ expect(conf.logger.colorize).toBe(true)+ const tmpSecretFile = path.join(os.tmpdir(), 'secret')+ fs.writeFileSync(tmpSecretFile, 'foobar8888')+ process.env[`${ENVIRONMENT_PREFIX}APPLICATIONS_FILES_ONLYOFFICE_SECRET`] = 'foobar'+ process.env[`${ENVIRONMENT_PREFIX}LOGGER_STDOUT`] = 'false'+ process.env[`${ENVIRONMENT_PREFIX}LOGGER_COLORIZE`] = '"false"'+ process.env[`${ENVIRONMENT_PREFIX}APPLICATIONS_FILES_MAXUPLOADSIZE`] = '8888'+ // docker compose secret file+ process.env[`${ENVIRONMENT_PREFIX}AUTH_TOKEN_ACCESS_SECRET_FILE`] = tmpSecretFile+ conf = exportConfiguration(true)+ expect(conf.applications.files.onlyoffice.secret).toBe('foobar')+ expect(conf.logger.stdout).toBe(false)+ expect(conf.logger.colorize).toBe(false)+ expect(conf.applications.files.maxUploadSize).toBe(8888)+ expect(conf.auth.token.access.secret).toBe('foobar8888')+ // cleanup secret file+ fs.promises.rm(tmpSecretFile, { force: true }).catch((e) => {+ console.error(e)+ })+ })})diff --git a/backend/src/configuration/config.environment.ts b/backend/src/configuration/config.environment.tsindex 3236e3f5..2c18d632 100755--- a/backend/src/configuration/config.environment.ts+++ b/backend/src/configuration/config.environment.ts@@ -10,7 +10,7 @@ import { configLoader } from './config.loader'import { Configuration } from './config.validation'export const configuration: Configuration = loadConfiguration()-export const exportConfiguration: () => Configuration = () => configuration+export const exportConfiguration: (reload?: boolean) => Configuration = (reload = false) => (reload ? loadConfiguration() : configuration)function loadConfiguration(): Configuration {const config: Configuration = configLoader()diff --git a/backend/src/configuration/config.loader.ts b/backend/src/configuration/config.loader.tsindex 6e9359d9..fcd6f745 100644--- a/backend/src/configuration/config.loader.ts+++ b/backend/src/configuration/config.loader.ts@@ -85,7 +85,7 @@ function setObjectPropertyFromString(obj: any, property: string, value: any): vo* Returns a new object containing only the env-var overrides* that match existing keys in `config`, nested and cased properly.*/-export function getEnvOverrides(config: Record<string, any>): Record<string, any> {+function getEnvOverrides(config: Record<string, any>): Record<string, any> {const result: Record<string, any> = {}for (const [envKey, rawValue] of Object.entries(process.env)) {diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yamlindex ec101e4d..6aa0d401 100755--- a/environment/environment.dist.yaml+++ b/environment/environment.dist.yaml@@ -12,7 +12,7 @@ server:restartOnFailure: truelogger:# level: trace | debug | info | warn | error | fatal- level: trace+ level: info# stdout : if false logs are written to the run directory (default: true)stdout: true# colorize output