Skip to main content

max / makenotwork

3.8 KB · 87 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 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.
13
14 ### Integration Tests (`cargo test --test integration`)
15
16 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`.
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 - `with_admin_storage_and_scanner()`: admin user + in-memory S3 + scanner
35 - `with_synckit_storage()`: SyncKit in-memory bucket (OTA tests)
36 - `with_creator_tier_checkout()`: mock Stripe + a configured Everything-tier price
37 - `with_postmark()`: Postmark webhook tokens configured
38
39 Anything not covered by a constructor goes through `TestHarness::build(BuildOptions { .. })`
40 directly; add a documented `BuildOptions` field rather than a constructor per calling test.
41
42 **Seeding:** `harness/seed.rs` provides `seed_user` and `seed_project` for the
43 `db_*_layer.rs` contract tests, which run against a bare `TestDb` with no router
44 and so cannot use `signup`. Prefer the harness methods (`signup`, `create_creator`,
45 `create_creator_with_item`) anywhere a session or HTTP flow is in play.
46
47 ### Seal Tests
48
49 Ratchets over the repo itself, each its own binary. No database.
50
51 - `assumptions.rs` — the business assumptions TOML parses, validates, and still resolves every marker in the site-docs corpus.
52 - `migration_hygiene.rs` — new migrations use `CONCURRENTLY` / `IF NOT EXISTS` and opt out of the per-migration transaction correctly.
53 - `frontend_globals.rs` — the `window.*` global count only goes down.
54 - `test_hygiene.rs` — test-suite conventions: doc headers, `#[ignore]` reasons, and `HIGH_WATER` counts for loose status assertions, `test_` prefixes, and oversized modules.
55 - `workflows/enum_drift.rs` — every domain enum's variants match its Postgres `CHECK` list (needs a DB; runs inside the integration binary).
56
57 ### Load Tests (`cargo test --test load -- --ignored --nocapture`)
58
59 Multi-scenario virtual user simulation. Requires `--ignored` flag. Configurable via env vars:
60 - `LOAD_VUS`: virtual users (default: 20)
61 - `LOAD_DURATION_SECS`: duration (default: 30)
62 - `LOAD_RAMP_SECS`: ramp-up (default: 5)
63
64 ### Health Tests (`cargo test --test health`)
65
66 External HTTP tests against a running server at `http://localhost:3000`. Skips gracefully if server is not running.
67
68 ## Running
69
70 ```bash
71 # Unit tests only (fast, no DB)
72 cargo test --lib
73
74 # Integration tests (requires PostgreSQL)
75 cargo test --test integration
76
77 # Specific workflow
78 cargo test --test integration sandbox
79
80 # All tests
81 cargo test
82 ```
83
84 ## Fixtures
85
86 Test media files in `tests/fixtures/`: `.mp3`, `.mp4`, `.flac`, `.webm`, `.ogg`, `.wav`, `.m4a`
87