Files
Ten31-Portal/backend/tests/test_rollup.py
Jonathan Kirkwood 8247c28243 Implement adjudicated DO items across backend, frontend, deploy
From the ROADMAP adjudication (12 of 13 DO items; D2 is a commit action).

Backend:
- B3: pytest suite (auth, entity CRUD, rollup) + dev deps + pytest config
- B4: cap document uploads at TEN31_MAX_UPLOAD_SIZE (default 50MB), stream-
  checked with partial-file cleanup, 413 on overflow
- B7: type AuditLog.detail as dict|list|str|None to match the JSON column
- B10: index foreign-key columns (migration a7b8c9d0e1f2 + index=True)
- B11: cli delete-user logs file-removal errors instead of swallowing them

Frontend:
- F2: distinguish "server unreachable" from "logged out"; retry prompt
- F4: confirm before destructive holdings-replace on import; step progress
- F6: expandable audit-log detail with full JSON
- F7: empty-state on the Investments page
- F8: shared role helpers (WRITER_ROLES/canEditRound/isApprover), used by
  EntitiesList, AuditLog, Import, ValuationWorkflow

Deploy:
- D5: run tsc --noEmit before packaging (build script)
- D6: TEN31_LOG_LEVEL env var (defaults to info)

Verified: 8/8 backend tests pass; alembic upgrades to head with 13 FK
indexes; upload limit rejects oversized + cleans up; frontend tsc + vite
build clean; dev server serves and proxies to the API.
2026-07-01 13:33:40 -05:00

49 lines
1.5 KiB
Python

"""The entity rollup aggregates invested cost and the latest signed valuation correctly."""
from datetime import date
from ten31portal.models import (
Entity, EntityType, Holding, Position, RoundStatus, Valuation, ValuationRound,
)
def test_rollup_sums_cost_and_latest_signed_value(auth_client, session):
entity = Entity(name="Rollup Fund", type=EntityType.fund)
session.add(entity)
session.commit()
session.refresh(entity)
holding = Holding(entity_id=entity.id, company_name="Acme")
session.add(holding)
session.commit()
session.refresh(holding)
position = Position(
holding_id=holding.id,
security_name="Acme Series A",
investment_date=date(2025, 1, 15),
cost_cents=100_000,
)
session.add(position)
session.commit()
session.refresh(position)
rnd = ValuationRound(
entity_id=entity.id,
quarter_end=date(2026, 3, 31),
status=RoundStatus.approved,
)
session.add(rnd)
session.commit()
session.refresh(rnd)
session.add(Valuation(round_id=rnd.id, position_id=position.id, value_cents=150_000))
session.commit()
resp = auth_client.get("/api/entities/rollup")
assert resp.status_code == 200, resp.text
row = next(r for r in resp.json() if r["id"] == entity.id)
assert row["invested_cents"] == 100_000
assert row["last_signed_value_cents"] == 150_000
assert row["committed_cents"] == 0 # no capital-account statements added