fix(portfolio): default new workspaces to 100 oz
This commit is contained in:
@@ -254,3 +254,58 @@ def test_hedge_page_upgrades_cached_gld_quote_and_uses_converted_spot(tmp_path,
|
||||
assert portfolio["spot_price"] == 4041.9
|
||||
assert portfolio["gold_value"] == 889218.0
|
||||
assert portfolio["net_equity"] == 667218.0
|
||||
|
||||
|
||||
def test_hedge_page_upgrades_legacy_default_workspace_footprint(tmp_path, monkeypatch) -> None:
|
||||
import asyncio
|
||||
|
||||
from app.pages import hedge as hedge_module
|
||||
from app.services import runtime as runtime_module
|
||||
|
||||
_install_workspace_repo(tmp_path, monkeypatch)
|
||||
workspace_id = str(uuid4())
|
||||
workspace_path = tmp_path / "workspaces" / workspace_id
|
||||
workspace_path.mkdir(parents=True, exist_ok=True)
|
||||
(workspace_path / "portfolio_config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schema_version": 2,
|
||||
"portfolio": {
|
||||
"gold_value": {"value": "215000.0", "currency": "USD"},
|
||||
"entry_price": {"value": "215.0", "currency": "USD", "per_weight_unit": "ozt"},
|
||||
"gold_ounces": {"value": "1000.0", "unit": "ozt"},
|
||||
"entry_basis_mode": "value_price",
|
||||
"loan_amount": {"value": "145000.0", "currency": "USD"},
|
||||
"margin_threshold": {"value": "0.75", "unit": "ratio"},
|
||||
"monthly_budget": {"value": "8000.0", "currency": "USD"},
|
||||
"ltv_warning": {"value": "0.70", "unit": "ratio"},
|
||||
"primary_source": "yfinance",
|
||||
"fallback_source": "yfinance",
|
||||
"refresh_interval": {"value": 5, "unit": "seconds"},
|
||||
"volatility_spike": {"value": "0.25", "unit": "ratio"},
|
||||
"spot_drawdown": {"value": "7.5", "unit": "percent"},
|
||||
"email_alerts": False,
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
class _CacheStub:
|
||||
async def get_json(self, key: str): # type: ignore[override]
|
||||
if key == "quote:GLD":
|
||||
return {"symbol": "GLD", "price": 404.19, "quote_unit": "share", "source": "cache"}
|
||||
return None
|
||||
|
||||
async def set_json(self, key: str, value): # type: ignore[override]
|
||||
return True
|
||||
|
||||
data_service = DataService(cache=_CacheStub()) # type: ignore[arg-type]
|
||||
monkeypatch.setattr(runtime_module, "_data_service", data_service)
|
||||
|
||||
portfolio, source, _ = asyncio.run(hedge_module._resolve_hedge_spot(workspace_id))
|
||||
|
||||
assert source == "cache"
|
||||
assert portfolio["gold_units"] == 100.0
|
||||
assert portfolio["margin_call_price"] == 1933.3333333333333
|
||||
assert portfolio["gold_value"] == 404190.0
|
||||
assert portfolio["net_equity"] == 259190.0
|
||||
|
||||
Reference in New Issue
Block a user