feat: foundations for the manager conversion (platform-v2 step 6.1)
- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes, texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read; bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions. - Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them, tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make set-state-in-effect an error. - src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now uses it. - Dead manager files removed (3.1k lines unreachable from main.jsx). - Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live bell check passed on a rerun). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,3 +97,30 @@ def test_unknown_order_on_real_api(client, make_user, login): # plan step 1.2 "
|
||||
assert r.status_code == 404
|
||||
assert r.json()["error"] == {"code": "order.not_found", "params": {"order_id": 999999},
|
||||
"message": "Order 999999 not found."}
|
||||
|
||||
|
||||
def test_backend_code_raises_codes_not_http_exceptions():
|
||||
"""Step 6.1: every error the app raises is a registered code (XeniaError) with texts in
|
||||
both languages; a plain HTTPException would reach the apps as an untranslated `http.<status>`."""
|
||||
import pathlib
|
||||
import re
|
||||
root = pathlib.Path(__file__).resolve().parents[1]
|
||||
found = [f"{p.relative_to(root)}:{n}" for d in ("routers", "services", "core", "modules")
|
||||
for p in (root / d).rglob("*.py") if p.name != "errors.py"
|
||||
for n, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
||||
if re.search(r"\bHTTPException\s*\(", line)]
|
||||
assert found == [], "use XeniaError (core/errors.py) instead: " + ", ".join(found)
|
||||
|
||||
|
||||
def test_a_code_can_keep_a_v1_shaped_detail():
|
||||
app = FastAPI()
|
||||
install_error_handlers(app)
|
||||
|
||||
@app.get("/x")
|
||||
def x():
|
||||
raise XeniaError("business_day.orders_open", open_orders=2, partially_paid=1,
|
||||
detail={"message": "2 tables open", "open_orders": 2, "partially_paid": 1})
|
||||
|
||||
body = TestClient(app).get("/x").json()
|
||||
assert body["error"]["code"] == "business_day.orders_open" and body["error"]["params"] == {"open_orders": 2, "partially_paid": 1}
|
||||
assert body["detail"]["open_orders"] == 2
|
||||
|
||||
@@ -182,7 +182,7 @@ def test_discount_over_limit_needs_approval(client, db, venue, make_user, login)
|
||||
token = approve(client, v["waiter_h"], "pricing.discounts.over_limit", v["manager"].username).json()["override_token"]
|
||||
r = client.post(url, headers=dict(v["waiter_h"], **{"X-Xenia-Override": token}),
|
||||
json={"item_ids": [v["items"][2].id], "discount_percent": 20})
|
||||
assert r.status_code == 403 and r.json()["detail"] == "Discounts are globally disabled"
|
||||
assert r.status_code == 403 and r.json()["error"]["code"] == "order.discounts_off"
|
||||
|
||||
|
||||
# ── check() with a token (require() routes) ──────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user