Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

refactor(tests): replace lodash merge with in house deepMerge (#1017)

Corentin Thomasset1548535f1e37
diff --git a/apps/papra-server/src/modules/config/config.test-utils.ts b/apps/papra-server/src/modules/config/config.test-utils.ts
index 875cace2..c10fa952 100644
--- a/apps/papra-server/src/modules/config/config.test-utils.ts
+++ b/apps/papra-server/src/modules/config/config.test-utils.ts
@@ -1,12 +1,30 @@
import type { DeepPartial } from '@corentinth/chisels';
import type { Config } from './config.types';
-import { merge } from 'lodash-es';
import { loadDryConfig } from './config';
-export { overrideConfig };
+function isPlainObject(value: unknown): value is Record<string, unknown> {
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
+}
+
+function deepMerge<T extends Record<string, unknown>>(target: T, source: Record<string, unknown>): T {
+ const result: Record<string, unknown> = { ...target };
+
+ for (const key of Object.keys(source)) {
+ const targetVal = result[key];
+ const sourceVal = source[key];
+
+ if (isPlainObject(targetVal) && isPlainObject(sourceVal)) {
+ result[key] = deepMerge(targetVal, sourceVal);
+ } else if (sourceVal !== undefined) {
+ result[key] = sourceVal;
+ }
+ }
+
+ return result as T;
+}
-function overrideConfig(config: DeepPartial<Config> | undefined = {}) {
+export function overrideConfig(config: DeepPartial<Config> | undefined = {}): Config {
const { config: defaultConfig } = loadDryConfig();
- return merge({}, defaultConfig, config);
+ return deepMerge(defaultConfig, config);
}