fix: qualify corporate-action ledger reads (#36)
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import time
|
||||
from contextlib import ExitStack
|
||||
from datetime import UTC, datetime
|
||||
from datetime import UTC, date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
@@ -977,6 +977,62 @@ def test_unified_ledger_includes_dividend_fields() -> None:
|
||||
assert item["profit_buffer_after"] == created.json()["profit_buffer_after"]
|
||||
|
||||
|
||||
def test_unified_ledger_includes_corporate_action_fields() -> None:
|
||||
repo = _FakeRepo(_portfolio())
|
||||
repo.entries.append(
|
||||
LedgerEntry(
|
||||
ledger_entry_id=7,
|
||||
portfolio_id=_PORTFOLIO_ID,
|
||||
source="corporate_action",
|
||||
side="stock_consolidation",
|
||||
quantity=10,
|
||||
price=200,
|
||||
recorded_at=datetime(2026, 9, 2, tzinfo=UTC),
|
||||
corporate_action={
|
||||
"corporate_action_id": "ca-7",
|
||||
"action_type": "stock_consolidation",
|
||||
"effective_date": date(2026, 9, 2),
|
||||
"quantity_before": Decimal(20),
|
||||
"quantity_after": Decimal(10),
|
||||
"average_price_before": Decimal(100),
|
||||
"average_price_after": Decimal(200),
|
||||
"total_cost_basis": Decimal(2000),
|
||||
"cash_balance": Decimal(1000),
|
||||
"profit_buffer": Decimal(500),
|
||||
"evidence_ref": "notice://ca-7",
|
||||
"actor_user_id": _USER_ID,
|
||||
},
|
||||
)
|
||||
)
|
||||
client = _make_client(repo)
|
||||
|
||||
response = client.get(
|
||||
f"/v1/portfolios/{_PORTFOLIO_ID}/ledger?source=corporate_action",
|
||||
headers=_auth(),
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
item = response.json()["items"][0]
|
||||
assert item == {
|
||||
"ledger_entry_id": 7,
|
||||
"portfolio_id": _PORTFOLIO_ID,
|
||||
"source": "corporate_action",
|
||||
"event_id": "ca-7",
|
||||
"event_type": "stock_consolidation",
|
||||
"effective_date": "2026-09-02",
|
||||
"quantity_before": "20",
|
||||
"quantity_after": "10",
|
||||
"average_price_before": "100",
|
||||
"average_price_after": "200",
|
||||
"total_cost_basis": "2000",
|
||||
"cash_balance": "1000",
|
||||
"profit_buffer": "500",
|
||||
"evidence_ref": "notice://ca-7",
|
||||
"actor_user_id": _USER_ID,
|
||||
"recorded_at": "2026-09-02T00:00:00Z",
|
||||
}
|
||||
|
||||
|
||||
def test_unified_ledger_openapi_contains_nullable_amount() -> None:
|
||||
repo = _FakeRepo(_portfolio())
|
||||
client = _make_client(repo)
|
||||
|
||||
Reference in New Issue
Block a user