Skip to content

Commit a66204f

Browse files
author
heeho
committed
fix(positions): request sorted overview section
1 parent 17fdbf2 commit a66204f

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

src/toss_browser_bridge/daemon.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def classify_broker_reject(message: str | None, status_code: int, error: str | N
141141
"method": "POST",
142142
"url": "https://wts-cert-api.tossinvest.com/api/v2/dashboard/asset/sections/all",
143143
"path": "/api/v2/dashboard/asset/sections/all",
144-
"body": {},
144+
"body": {"types": ["SORTED_OVERVIEW"]},
145145
}
146146
QUOTE_PROBE_ENDPOINT = {
147147
"name": "quote_probe",
@@ -311,7 +311,7 @@ def classify_health_payload(
311311
logged_out = is_logged_out(current_url)
312312
account_list_ok = _endpoint_ok(results, "account_list")
313313
overview_ok = _endpoint_ok(results, "account_overview")
314-
positions_ok = _endpoint_ok(results, "asset_sections_v2")
314+
positions_ok = _positions_endpoint_ready(results)
315315
completed_orders_ok = _endpoint_ok(results, "completed_orders_us_probe")
316316
quote_ok = _endpoint_ok(results, "quote_probe")
317317
fx_rate_ok = _endpoint_ok(results, "fx_rate_probe")
@@ -368,6 +368,15 @@ def _endpoint_ok(results: list[dict[str, Any]], name: str) -> bool:
368368
return next((bool(item.get("ok")) for item in results if item.get("name") == name), False)
369369

370370

371+
def _positions_endpoint_ready(results: list[dict[str, Any]]) -> bool:
372+
item = next((item for item in results if item.get("name") == "asset_sections_v2"), None)
373+
if not item or not item.get("ok"):
374+
return False
375+
payload = item.get("json") or {}
376+
sections = ((payload.get("result") or {}).get("sections")) or []
377+
return any(section.get("type") == "SORTED_OVERVIEW" for section in sections)
378+
379+
371380
def is_logged_out(url: str | None) -> bool:
372381
if not url:
373382
return True

tests/fixtures/health-logged-in.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
"path": "/api/v2/dashboard/asset/sections/all",
2525
"status_code": 200,
2626
"ok": true,
27+
"json": {
28+
"result": {
29+
"sections": [
30+
{
31+
"type": "SORTED_OVERVIEW",
32+
"data": {
33+
"products": []
34+
}
35+
}
36+
]
37+
}
38+
},
2739
"error": null
2840
},
2941
{

tests/test_health_capabilities.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from pathlib import Path
33

4-
from toss_browser_bridge.daemon import MUTATION_CAPABILITIES, classify_health_payload
4+
from toss_browser_bridge.daemon import MUTATION_CAPABILITIES, POSITIONS_ENDPOINT, classify_health_payload
55

66

77
FIXTURES_DIR = Path(__file__).parent / "fixtures"
@@ -86,3 +86,28 @@ def test_logged_in_fixture_enables_submit_readiness_only_with_runtime_state() ->
8686
assert capability == "browser_attached"
8787
assert payload["capabilities"]["post_submit_verify_ready"] is True
8888
assert payload["capabilities"]["order_submit_ready"] is True
89+
90+
91+
def test_positions_endpoint_requests_sorted_overview_section() -> None:
92+
assert POSITIONS_ENDPOINT["body"] == {"types": ["SORTED_OVERVIEW"]}
93+
94+
95+
def test_health_does_not_mark_positions_ready_for_empty_sections() -> None:
96+
fixture = _load_fixture("health-logged-in.json")
97+
results = []
98+
for item in fixture["results"]:
99+
cloned = dict(item)
100+
if cloned["name"] == "asset_sections_v2":
101+
cloned["json"] = {"result": {"sections": []}}
102+
results.append(cloned)
103+
104+
capability, payload = classify_health_payload(
105+
results,
106+
current_url=fixture["current_url"],
107+
attached=fixture["attached"],
108+
)
109+
110+
assert capability == "browser_attached"
111+
assert payload["capabilities"]["web_session_ready"] is True
112+
assert payload["capabilities"]["positions_ready"] is False
113+
assert payload["capabilities"]["post_submit_verify_ready"] is False

0 commit comments

Comments
 (0)