feat(cloud): the QR menu at the table, ordering only with a table's QR code
Plan phase 3S, step S.7.
- services/qr.py: the snapshot's `qr` {ordering, tables: [{id, label, token_hash}]} (sha256
of each table's token; the cloud never holds the tokens). A table order (dine_in) needs
the venue's ordering on, the site's menu_mode "order" and a valid table token: otherwise
order.service_unavailable / 403 order.table_invalid (a forged, old or typed-in table is
refused). The order keeps the table's id and label (online_orders.table_id, migration 0006).
- Public menu: ?t=<token> → `table` {id, label} or `table_invalid`; `table_ordering`; `qr`
never leaves the cloud.
- Heartbeat returns `apps_url` (new setting PUBLIC_APPS_URL: where /menu/ and /order/ are
served) so sites can print table QR codes that open the right address.
- Menu app: the table from its QR code (kept for the visit), a "Table 5" banner, ordering
only at a real table (otherwise read-only, with a notice for an invalid code); checkout
without a typed table number; prices are the QR menu's (sales point qr_table — it showed
in-store prices since S.1 removed digital_price) and only products sold there; the
confirmation page for table orders (in the kitchen); the delivery/takeaway leftovers
removed (they have their own app since S.4); test ids for e2e.
- Tests: tests/test_qr.py (3); test_checkout's typed-table case moved there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -81,13 +81,8 @@ def test_a_tampered_order_is_refused_and_a_correct_one_stored_at_the_clouds_pric
|
||||
assert _order(client, site).status_code == 201
|
||||
|
||||
|
||||
def test_the_qr_menus_table_and_delivery_details(client, admin_h):
|
||||
site, numeric = _venue(client, admin_h)
|
||||
r = _order(client, site, "dine_in", customer_table="5", items=[{"product_id": PIE, "quantity": 1}])
|
||||
assert r.status_code == 201
|
||||
stored = next(o for o in client.get(f"/api/orders/pending/{numeric}", headers=_h(site)).json()
|
||||
if o["public_ref"] == r.json()["public_ref"])
|
||||
assert (stored["table_label"], stored["sales_point"]) == ("5", "qr_table")
|
||||
def test_delivery_details(client, admin_h):
|
||||
site, numeric = _venue(client, admin_h) # table orders: tests/test_qr.py (S.7)
|
||||
assert _code(_order(client, site, "delivery")) == "order.details_missing"
|
||||
assert _order(client, site, "delivery", customer_address="Main square 3").status_code == 201
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ def test_new_site_gets_default_preset_and_v2_token(client, admin_h):
|
||||
site = _new_site(client, admin_h)
|
||||
assert "ordering" in site["modules"]
|
||||
hb = _heartbeat(client, site)
|
||||
assert set(hb) == {"license_token", "latest_version", "waiter_domain", "site_numeric_id"}
|
||||
assert set(hb) == {"license_token", "latest_version", "waiter_domain", "site_numeric_id", "apps_url"}
|
||||
p = _decode(hb["license_token"])
|
||||
assert p["v"] == 2 and p["site_id"] == site["site_id"] and p["modules"]["kds"] == {"limits": {"devices": None}}
|
||||
assert {"active", "locked", "expires_at", "issued_at"} <= set(p)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"""The QR menu at the table (plan phase 3S, step S.7): ordering only with a table's QR token
|
||||
(checked by its hash from the snapshot), only when the venue allows it; the public menu says
|
||||
which table the token is and never shows the hashes; a forged token is refused."""
|
||||
import json
|
||||
|
||||
from services import qr
|
||||
from test_checkout import ORDERING, PIE, _code, _h, _order, _venue
|
||||
|
||||
|
||||
def _push_qr(client, site, numeric, ordering=True, tables=None):
|
||||
menu = client.get(f"/api/menu/{site['site_id']}").json()
|
||||
tables = tables if tables is not None else [{"id": 5, "label": "T5", "token_hash": qr.token_hash("tok-five")},
|
||||
{"id": 6, "label": "Garden 6", "token_hash": qr.token_hash("tok-six")}]
|
||||
snap = {"categories": menu["categories"], "ordering": ORDERING, "timezone": "Europe/Athens",
|
||||
"qr": {"ordering": ordering, "tables": tables}}
|
||||
r = client.post("/api/menu/sync", headers=_h(site), json={"site_id": numeric, "snapshot_json": json.dumps(snap)})
|
||||
assert r.status_code == 200, r.text
|
||||
|
||||
|
||||
def test_a_table_token_finds_its_table():
|
||||
snap = {"qr": {"tables": [{"id": 5, "label": "T5", "token_hash": qr.token_hash("abc")}]}}
|
||||
assert qr.table_for(snap, "abc") == {"id": 5, "label": "T5"}
|
||||
assert qr.table_for(snap, "abd") is None
|
||||
assert qr.table_for(snap, "") is None and qr.table_for(snap, None) is None
|
||||
assert qr.table_for({}, "abc") is None
|
||||
|
||||
|
||||
def test_ordering_at_the_table_needs_a_real_table_token(client, admin_h):
|
||||
site, numeric = _venue(client, admin_h)
|
||||
_push_qr(client, site, numeric)
|
||||
menu = client.get(f"/api/menu/{site['site_id']}", params={"t": "tok-five"}).json()
|
||||
assert menu["table_ordering"] is True and menu["table"] == {"id": 5, "label": "T5"} and menu["table_invalid"] is False
|
||||
assert "qr" not in menu # the hashes stay on the cloud
|
||||
forged = client.get(f"/api/menu/{site['site_id']}", params={"t": "tok-seven"}).json()
|
||||
assert forged["table"] is None and forged["table_invalid"] is True
|
||||
assert "table" not in client.get(f"/api/menu/{site['site_id']}").json()
|
||||
|
||||
r = _order(client, site, "dine_in", table_token="tok-five", items=[{"product_id": PIE, "quantity": 2}])
|
||||
assert r.status_code == 201, r.text
|
||||
stored = next(o for o in client.get(f"/api/orders/pending/{numeric}", headers=_h(site)).json() if o["public_ref"] == r.json()["public_ref"])
|
||||
assert (stored["table_id"], stored["table_label"], stored["sales_point"], stored["total"]) == (5, "T5", "qr_table", 10.0)
|
||||
# a forged token, none, or a table name typed in by hand: refused
|
||||
assert _code(_order(client, site, "dine_in", table_token="tok-seven", items=[{"product_id": PIE, "quantity": 1}])) == "order.table_invalid"
|
||||
assert _code(_order(client, site, "dine_in", items=[{"product_id": PIE, "quantity": 1}])) == "order.table_invalid"
|
||||
r = _order(client, site, "dine_in", customer_table="5", items=[{"product_id": PIE, "quantity": 1}])
|
||||
assert r.status_code == 403 and _code(r) == "order.table_invalid"
|
||||
# a new QR code for table 5: the old one stops working at the next push
|
||||
_push_qr(client, site, numeric, tables=[{"id": 5, "label": "T5", "token_hash": qr.token_hash("tok-five-new")}])
|
||||
assert _code(_order(client, site, "dine_in", table_token="tok-five", items=[{"product_id": PIE, "quantity": 1}])) == "order.table_invalid"
|
||||
assert _order(client, site, "dine_in", table_token="tok-five-new", items=[{"product_id": PIE, "quantity": 1}]).status_code == 201
|
||||
|
||||
|
||||
def test_read_only_menus_take_no_table_orders(client, admin_h):
|
||||
site, numeric = _venue(client, admin_h)
|
||||
_push_qr(client, site, numeric, ordering=False)
|
||||
assert client.get(f"/api/menu/{site['site_id']}", params={"t": "tok-five"}).json()["table_ordering"] is False
|
||||
assert _code(_order(client, site, "dine_in", table_token="tok-five", items=[{"product_id": PIE, "quantity": 1}])) == "order.service_unavailable"
|
||||
# the venue allows it, but the sysadmin set the site's menu to view only
|
||||
_push_qr(client, site, numeric, ordering=True)
|
||||
r = client.put(f"/api/sites/{site['site_id']}", headers=admin_h, json={"menu_mode": "view_only"})
|
||||
assert r.status_code == 200, r.text
|
||||
assert _code(_order(client, site, "dine_in", table_token="tok-five", items=[{"product_id": PIE, "quantity": 1}])) == "order.service_unavailable"
|
||||
Reference in New Issue
Block a user