# MNW Server Tests ## Prerequisites - PostgreSQL running locally (default: `postgres://localhost/postgres`) - Set `TEST_DATABASE_URL` if using a non-default admin connection ## Test Types ### Unit Tests (`cargo test --lib`) 986 tests covering pure logic: pricing, validation, formatting, enums, error handling, CSRF, RSS, file scanning, import parsing, etc. No database required. ### Integration Tests (`cargo test --test integration`) 679 tests across 78 workflow modules. Each test gets an isolated PostgreSQL database cloned from a shared template (migrations applied once per test run). **Harness features:** - In-process Axum app (no network, uses `tower::ServiceExt::oneshot`) - Cookie-aware HTTP client with automatic CSRF token management - Mock Stripe (`MockPaymentProvider`) — captures checkout sessions, supports webhook signing - Mock email (`MockEmailTransport`) — captures all sent emails for assertion - Mock S3 (`InMemoryStorage`) — in-memory file storage - Direct SQL helpers for test setup (`grant_creator`, `grant_tier`, `connect_stripe`, etc.) **Harness constructors:** - `TestHarness::new()` — DB only (fastest, for auth/CRUD tests) - `with_storage()` — adds in-memory S3 - `with_mocks()` — mock Stripe + email (for payment flow tests) - `with_stripe()` — real Stripe SDK with test keys - `with_admin()` — pre-created admin user - `with_storage_and_scanner()` — file scanning pipeline - `with_git_repos(path)` — git repository support ### Load Tests (`cargo test --test load -- --ignored --nocapture`) Multi-scenario virtual user simulation. Requires `--ignored` flag. Configurable via env vars: - `LOAD_VUS` — virtual users (default: 20) - `LOAD_DURATION_SECS` — duration (default: 30) - `LOAD_RAMP_SECS` — ramp-up (default: 5) ### Health Tests (`cargo test --test health`) External HTTP tests against a running server at `http://localhost:3000`. Skips gracefully if server is not running. ## Running ```bash # Unit tests only (fast, no DB) cargo test --lib # Integration tests (requires PostgreSQL) cargo test --test integration # Specific workflow cargo test --test integration sandbox # All tests cargo test ``` ## Fixtures Test media files in `tests/fixtures/`: `.mp3`, `.mp4`, `.flac`, `.webm`, `.ogg`, `.wav`, `.m4a`