Files
aurum/backend/tests
ZProger 4ea83a9cda feat: crypto portfolio analytics (history chart, allocation, P&L, cost basis)
Adds the analytics half of the CoinMarketCap reference: a value-over-time
chart (GET /crypto/history, forward-filled from AssetValuation like Net
Worth's own series but scoped to crypto assets), an allocation breakdown by
coin, and stat tiles for all-time profit, total invested (cost basis), and
best/worst performer.

Deliberately no "24h" range — history is only as dense as the sync cadence
(button or once/day), so a 24h chart would be one or two points, not a
smooth intraday line. Cost basis / all-time profit / best-worst performer
aren't separate endpoints: they're trivial to derive client-side from
fields already in GET /crypto/holdings, so no redundant backend logic.

Allocation card follows the dataviz skill's categorical rule: top 7 coins
by value get a fixed-order color from the app's already-validated 8-slot
ramp, an 8th+ folds into "Other" rather than generating a new hue.

82/82 backend tests passing (3 new for /crypto/history). Verified live
against the real CoinGecko API — and caught a real holding the user had
already added directly through the UI between messages, which the smoke
test correctly left untouched while cleaning up only its own test data.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01855PiW5Wd8n4aRW4n9kByY
2026-08-30 04:38:51 +03:00
..

Backend tests

Real integration tests against a real Postgres database — a dedicated aurum_test database created fresh, migrated, and dropped again on every run. They never touch the real aurum database or its data: the app's lifespan startup (which seeds against the real DB) is never triggered, and every route's DB dependency is overridden to point at aurum_test instead.

Running

The stack must already be up (docker compose up -d). Test dependencies aren't baked into the production image, so install them once per container lifetime, then run pytest inside the running backend container — it's the only place with network access to Postgres:

docker compose exec backend pip install -r requirements-dev.txt
docker compose exec backend pytest -v

Re-run just pytest -v for subsequent runs; the pip install only needs repeating after a container restart/rebuild.

Adding a test

  • Use the client fixture (an httpx.AsyncClient wired to the app) to hit the API the same way the frontend does — prefer this over reaching into services/models directly, so tests keep verifying the actual contract.
  • account_id and categories fixtures give you the same default account/categories a real fresh install seeds.
  • Every table is truncated and reseeded before each test (see conftest.py::_clean_database), so tests don't need to worry about leftover state or guess at IDs from a previous test.