# 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`) 1,912 tests covering pure logic: pricing, validation, formatting, enums, error handling, CSRF, RSS, file scanning, import parsing, etc. No database required. Runs in ~2.5s. ### Integration Tests (`cargo test --test integration`) 1,226 tests across 123 workflow modules. Each test gets an isolated PostgreSQL database cloned from a shared template (migrations applied once, then reused across runs while migration-current). ~433s at `--test-threads=8`. **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 - `with_admin_storage_and_scanner()`: admin user + in-memory S3 + scanner - `with_synckit_storage()`: SyncKit in-memory bucket (OTA tests) - `with_creator_tier_checkout()`: mock Stripe + a configured Everything-tier price - `with_postmark()`: Postmark webhook tokens configured Anything not covered by a constructor goes through `TestHarness::build(BuildOptions { .. })` directly; add a documented `BuildOptions` field rather than a constructor per calling test. **Seeding:** `harness/seed.rs` provides `seed_user` and `seed_project` for the `db_*_layer.rs` contract tests, which run against a bare `TestDb` with no router and so cannot use `signup`. Prefer the harness methods (`signup`, `create_creator`, `create_creator_with_item`) anywhere a session or HTTP flow is in play. ### Seal Tests Ratchets over the repo itself, each its own binary. No database. - `assumptions.rs` — the business assumptions TOML parses, validates, and still resolves every marker in the site-docs corpus. - `migration_hygiene.rs` — new migrations use `CONCURRENTLY` / `IF NOT EXISTS` and opt out of the per-migration transaction correctly. - `frontend_globals.rs` — the `window.*` global count only goes down. - `test_hygiene.rs` — test-suite conventions: doc headers, `#[ignore]` reasons, and `HIGH_WATER` counts for loose status assertions, `test_` prefixes, and oversized modules. - `workflows/enum_drift.rs` — every domain enum's variants match its Postgres `CHECK` list (needs a DB; runs inside the integration binary). ### 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`