"""Admin Investor View reconstructs what one investor sees, read-only.""" from datetime import date from tests.conftest import make_user from ten31portal.models import ( CapitalAccountStatement, Entity, EntityAccess, EntityType, UserRole, ) def test_investor_view_reconstructs(auth_client, session): inv = make_user(session, username="lp1", role=UserRole.investor) ent = Entity(name="LTPF I", type=EntityType.fund) other = Entity(name="Not Theirs", type=EntityType.fund) session.add(ent) session.add(other) session.commit() session.refresh(ent) session.refresh(other) session.add(EntityAccess(user_id=inv.id, entity_id=ent.id)) session.add(CapitalAccountStatement( entity_id=ent.id, investor_user_id=inv.id, as_of_date=date(2026, 3, 31), commitment_cents=500_000, ending_balance_cents=600_000, )) session.commit() resp = auth_client.get(f"/api/users/{inv.id}/investor-view") assert resp.status_code == 200, resp.text body = resp.json() assert body["user"]["username"] == "lp1" # Only the granted entity is visible, not the other one. assert [e["id"] for e in body["entities"]] == [ent.id] assert len(body["capital_accounts"]) == 1 assert body["capital_accounts"][0]["ending_balance_cents"] == 600_000 def test_investor_view_rejects_non_investor(auth_client, session): staff = make_user(session, username="ops", role=UserRole.operations) assert auth_client.get(f"/api/users/{staff.id}/investor-view").status_code == 400