Skip to main content

max / makenotwork

2.2 KB · 65 lines History Blame Raw
1 # MNW Server Tests
2
3 ## Prerequisites
4
5 - PostgreSQL running locally (default: `postgres://localhost/postgres`)
6 - Set `TEST_DATABASE_URL` if using a non-default admin connection
7
8 ## Test Types
9
10 ### Unit Tests (`cargo test --lib`)
11
12 986 tests covering pure logic: pricing, validation, formatting, enums, error handling, CSRF, RSS, file scanning, import parsing, etc. No database required.
13
14 ### Integration Tests (`cargo test --test integration`)
15
16 679 tests across 78 workflow modules. Each test gets an isolated PostgreSQL database cloned from a shared template (migrations applied once per test run).
17
18 **Harness features:**
19 - In-process Axum app (no network, uses `tower::ServiceExt::oneshot`)
20 - Cookie-aware HTTP client with automatic CSRF token management
21 - Mock Stripe (`MockPaymentProvider`) — captures checkout sessions, supports webhook signing
22 - Mock email (`MockEmailTransport`) — captures all sent emails for assertion
23 - Mock S3 (`InMemoryStorage`) — in-memory file storage
24 - Direct SQL helpers for test setup (`grant_creator`, `grant_tier`, `connect_stripe`, etc.)
25
26 **Harness constructors:**
27 - `TestHarness::new()` — DB only (fastest, for auth/CRUD tests)
28 - `with_storage()` — adds in-memory S3
29 - `with_mocks()` — mock Stripe + email (for payment flow tests)
30 - `with_stripe()` — real Stripe SDK with test keys
31 - `with_admin()` — pre-created admin user
32 - `with_storage_and_scanner()` — file scanning pipeline
33 - `with_git_repos(path)` — git repository support
34
35 ### Load Tests (`cargo test --test load -- --ignored --nocapture`)
36
37 Multi-scenario virtual user simulation. Requires `--ignored` flag. Configurable via env vars:
38 - `LOAD_VUS` — virtual users (default: 20)
39 - `LOAD_DURATION_SECS` — duration (default: 30)
40 - `LOAD_RAMP_SECS` — ramp-up (default: 5)
41
42 ### Health Tests (`cargo test --test health`)
43
44 External HTTP tests against a running server at `http://localhost:3000`. Skips gracefully if server is not running.
45
46 ## Running
47
48 ```bash
49 # Unit tests only (fast, no DB)
50 cargo test --lib
51
52 # Integration tests (requires PostgreSQL)
53 cargo test --test integration
54
55 # Specific workflow
56 cargo test --test integration sandbox
57
58 # All tests
59 cargo test
60 ```
61
62 ## Fixtures
63
64 Test media files in `tests/fixtures/`: `.mp3`, `.mp4`, `.flac`, `.webm`, `.ogg`, `.wav`, `.m4a`
65