forked from Disciplr-Org/Disciplr-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.cjs
More file actions
26 lines (23 loc) · 1.41 KB
/
Copy pathjest.setup.cjs
File metadata and controls
26 lines (23 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Global Jest setup: runs before each test file, before the test framework is
// installed. Used to seed environment defaults required by modules under test.
// Field encryption requires a key to be configured. Provide a deterministic,
// non-secret 32-byte (base64) key for the test environment so repositories that
// encrypt/decrypt reversible secrets work without each suite wiring its own key.
// Individual suites may override FIELD_ENCRYPTION_KEY / FIELD_ENCRYPTION_KEYS
// (e.g. to test rotation) and reset the cached env via _resetEnvForTesting().
// Provide a valid DATABASE_URL so env validation doesn't process.exit(1) when
// modules under test import src/config/env.ts at file-load time.
if (!process.env.DATABASE_URL) {
process.env.DATABASE_URL = 'postgres://test:test@localhost:5432/test'
}
if (!process.env.FIELD_ENCRYPTION_KEY && !process.env.FIELD_ENCRYPTION_KEYS) {
// 32 zero bytes, base64-encoded — test-only, never use in production.
process.env.FIELD_ENCRYPTION_KEY = Buffer.alloc(32, 0).toString('base64')
}
// src/middleware/auth.ts reads DOWNLOAD_SECRET directly from process.env at
// module-load time and throws if unset, which would otherwise crash every
// suite that imports it (directly or transitively via app.ts) before any
// per-test setup runs. Test-only value, never use in production.
if (!process.env.DOWNLOAD_SECRET) {
process.env.DOWNLOAD_SECRET = 'test-download-secret-at-least-16-chars'
}