Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(e2e): isolate the auth/audit (main) DB too, so e2e api-keys don't pollute the dev DB (#418)

Yudhi Armyndharis428b8e88ecbd
diff --git a/src/config/configuration.ts b/src/config/configuration.ts
index dedc02152..73d7f6f6b 100644
--- a/src/config/configuration.ts
+++ b/src/config/configuration.ts
@@ -21,7 +21,9 @@ export default () => ({
// Main Database configuration (always SQLite for boot config)
database: {
type: 'sqlite' as const,
- database: './data/main.sqlite',
+ // SQLite file for the auth/audit DB. Overridable (e.g. e2e points it at a temp file) so tests
+ // never write api keys into the developer's ./data/main.sqlite.
+ database: process.env.MAIN_DATABASE_NAME || './data/main.sqlite',
// Schema management for the auth/audit DB. Default ON (zero-config first boot).
// Set MAIN_DATABASE_SYNCHRONIZE=false to manage schema via the main-owned migrations
// instead (migrationsRun then creates api_keys/audit_logs). When disabled, run the
diff --git a/test/setup-e2e.ts b/test/setup-e2e.ts
index 917c95a8e..aad54b026 100644
--- a/test/setup-e2e.ts
+++ b/test/setup-e2e.ts
@@ -12,6 +12,10 @@ process.env.DATABASE_TYPE = 'sqlite';
const e2eDataDb = join(tmpdir(), `openwa-e2e-${process.pid}.sqlite`);
rmSync(e2eDataDb, { force: true });
process.env.DATABASE_NAME = e2eDataDb;
+// Likewise isolate the auth/audit (main) DB, so e2e api-keys don't accumulate in ./data/main.sqlite.
+const e2eMainDb = join(tmpdir(), `openwa-e2e-main-${process.pid}.sqlite`);
+rmSync(e2eMainDb, { force: true });
+process.env.MAIN_DATABASE_NAME = e2eMainDb;
process.env.QUEUE_ENABLED = 'false';
process.env.AUTO_START_SESSIONS = 'false';
// Keep the auth/audit + data schema zero-config for the test boot.