from __future__ import annotations from pathlib import Path ROOT = Path(__file__).resolve().parent.parent EXT = ROOT / "extension" WIDGET = ROOT / "app" / "static" / "widget.js" BLOCK = EXT / "extensions" / "chat-widget" / "blocks" / "chat.liquid" APP_TOML = EXT / "shopify.app.toml" def test_widget_js_supports_signed_proxy_mode(): js = WIDGET.read_text(encoding="utf-8") assert 'searchParams.get("proxy")' in js # proxy-mode switch (Shopify embed) assert '"/apps/chat"' in js # signed App Proxy base assert "message:" in js and "session_id:" in js assert "localStorage" in js def test_block_is_app_embed_loading_widget_in_proxy_mode(): liquid = BLOCK.read_text(encoding="utf-8") assert "{% schema %}" in liquid assert '"target": "body"' in liquid # app embed (whole storefront) assert "proxy=1" in liquid # loads the widget in signed-proxy mode assert "widget.js" in liquid def test_app_toml_scopes_and_proxy(): toml = APP_TOML.read_text(encoding="utf-8") assert "read_orders" in toml and "read_products" in toml and "read_customers" in toml assert "[app_proxy]" in toml assert 'subpath = "chat"' in toml assert 'prefix = "apps"' in toml # Uninstall + billing webhooks must be SUBSCRIBED, not just handled. assert "app/uninstalled" in toml assert "app_subscriptions/update" in toml