harden env handling #481
3 changed files with 13 additions and 0 deletions
|
|
@ -1712,6 +1712,8 @@ mix test test/membership/member_test.exs:42
|
|||
|
||||
### 4.7 Testing Best Practices
|
||||
|
||||
**Process environment (`test/test_helper.exs`):** Vereinfacht and OIDC-related `System.get_env/1` keys are cleared at test startup so configuration comes from the test database (Membership settings) unless a test explicitly sets variables in `setup` and restores them with `on_exit`. This matches production priority (ENV over settings) while keeping the suite deterministic when `.env` is loaded (e.g. via `just`).
|
||||
|
||||
**Testing Philosophy: Focus on Business Logic, Not Framework Functionality**
|
||||
|
||||
We test our business logic and domain-specific behavior, not core framework features. Framework features (Ash validations, Ecto relationships, etc.) are already tested by their respective libraries.
|
||||
|
|
|
|||
|
|
@ -710,6 +710,10 @@ end
|
|||
|
||||
## Testing Strategy
|
||||
|
||||
### Test process environment
|
||||
|
||||
`test/test_helper.exs` clears Vereinfacht and OIDC-related environment variables at startup (same rationale as not hitting real APIs when `.env` is loaded). `Mv.Config` prefers ENV over database settings; without this, OIDC sign-in redirect tests would depend on the developer shell and become flaky. Tests that need specific OIDC env values set them in `setup` and restore with `on_exit`.
|
||||
|
||||
### Test Coverage Areas
|
||||
|
||||
#### 1. Unit Tests (Domain Logic)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@ System.delete_env("VEREINFACHT_API_URL")
|
|||
System.delete_env("VEREINFACHT_API_KEY")
|
||||
System.delete_env("VEREINFACHT_CLUB_ID")
|
||||
|
||||
# Mv.Config.oidc_* reads ENV before database Settings (see lib/mv/config.ex). If a developer
|
||||
# or CI loads .env with OIDC variables, OidcOnlySignInRedirect and oidc_configured?/0 would
|
||||
# ignore Membership settings and tests become flaky. Tests that need OIDC env (e.g. group
|
||||
# claim) set it in setup and restore via on_exit.
|
||||
~w(OIDC_CLIENT_ID OIDC_BASE_URL OIDC_REDIRECT_URI OIDC_CLIENT_SECRET OIDC_CLIENT_SECRET_FILE OIDC_ONLY OIDC_ADMIN_GROUP_NAME OIDC_GROUPS_CLAIM)
|
||||
|> Enum.each(&System.delete_env/1)
|
||||
|
||||
ExUnit.start(
|
||||
# shows 10 slowest tests at the end of the test run
|
||||
# slowest: 10
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue