Files
mercadodevida/specs/F-004-config-flags/TESTS.md
rikrdo 4851692031 feat(F-004): typed fail-fast config and feature flag module
- loadConfig: pure over env object, accumulates all problems, names var names only
- DATABASE_URL now required at startup; PORT/HOST/LOG_LEVEL/NODE_ENV/REDIS_URL defaulted
- flags module behind FeatureFlagProvider; unknown flags OFF; runtime setEnabled (no redeploy)
- buildApp decorates app.flags; server.ts fail-fast before app boot
- tests caught and fixed flag-store case-normalization bug before gates
- zero new dependencies; all gates approved; verify.sh green
2026-08-14 22:29:18 +02:00

971 B

TESTS — F-004 Typed config and feature flags

Unit — src/infrastructure/config/tests/config.test.ts

  1. Valid full env -> typed AppConfig (port number, nodeEnv enum, flags parsed)
  2. Missing DATABASE_URL -> ConfigError naming DATABASE_URL
  3. Invalid PORT (non-numeric / out of range) -> ConfigError naming PORT
  4. Invalid NODE_ENV -> ConfigError
  5. FLAG_* true/false parsed; unknown flag value -> ConfigError naming the var
  6. Multiple problems -> single ConfigError listing all of them

Unit — src/modules/flags/tests/feature-flag-store.test.ts

  1. Known flag on -> isEnabled true; known flag off -> false
  2. Unknown flag -> false (fail-safe)
  3. setEnabled flips state at runtime (no new store / no redeploy)
  4. createFlagStore seeds initial state

Composition

  1. buildApp with flags dep: guarded path skipped when flag off, runs when on

Manual / QA

  • Start server without DATABASE_URL -> clear error naming the var, non-zero exit.
  • verify.sh green.