estack-testing
Elixir testing
Read existing test support and configuration. Preserve working test conventions. Ordinary tests must not need live vendor credentials, real funds, or uncontrolled external services. Use the database adapter the project supports; PostgreSQL is not mandatory for every Elixir app.
Test observable behavior
Test public context functions or Ash actions for domain behavior, plus focused tests for complex pure functions and changesets when useful. Build ordinary fixtures through valid application interfaces. Direct Repo fixtures can be appropriate for constraints, legacy states, or efficient setup; make the reason explicit and preserve invariants.
For every scoped operation, exercise another tenant/user and relevant roles. Test reads, writes, deletes, preloads, aggregates, and unauthorized events. Use :not_found when resource existence is private and explicit denial where the product intentionally distinguishes it.
Vendor boundaries
Use behaviours and deterministic fakes for repeatable development/test flows when that fits the app. Preserve Mox where used; use expectations when interaction behavior matters. Prefer existing Req.Test or Bypass infrastructure for HTTP request/response assertions. Do not impose a mocking migration on an unrelated feature.
Keep fake behavior aligned with the boundary contract, including errors, timeouts, and malformed responses. Configure implementations before application startup. Do not mutate global Application env from an async test.
SQL sandbox and concurrent processes
Use the project's DataCase/ConnCase and sandbox setup. Enable async only when the database adapter and shared state permit it. Spawned processes need explicit sandbox ownership/allowance or the established caller-tracking mechanism; arrange this before queries run.