Files
shaguabijia-app-server/tests/test_h5_hosting.py
T
guke ddfe955e9c fix(h5): 补领券看广告金币到账 toast 的金币堆图标(welfare 漏拷致 404)
showCouponAdRewardToast(home/index.html:8841,领券奖励已到账 toast)引用 assets/welfare/index/checkin-coins-600.png,同属抽取时漏本地化的 welfare 子树。从原型 checkin-popup/reward-coins-600.png 补回该图。test: 断言 200。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 11:09:26 +08:00

102 lines
4.5 KiB
Python

"""H5 静态托管冒烟:/h5 同源服务页面 + .html no-cache(热更核心)。"""
from __future__ import annotations
def test_h5_shared_bridge_served(client) -> None:
resp = client.get("/h5/shared/bridge.js")
assert resp.status_code == 200
def test_h5_html_no_cache(client) -> None:
# records 迁入前,先用已在仓库的 mine 页验证 .html 的 no-cache 响应头
resp = client.get("/h5/mine/index.html")
assert resp.status_code == 200
assert resp.headers.get("cache-control") == "no-cache"
def test_h5_html_no_cache_via_dir_url(client) -> None:
# 目录式 URL(WebView 规范入口)经 html=True 回落 index.html,也必须带 no-cache
resp = client.get("/h5/mine/")
assert resp.status_code == 200
assert resp.headers.get("cache-control") == "no-cache"
def test_h5_records_served_and_migrated(client) -> None:
resp = client.get("/h5/records/index.html")
assert resp.status_code == 200
assert resp.headers.get("cache-control") == "no-cache"
body = resp.text
assert "SGBridge" in body # 已切到新桥
assert "NativeBridge" not in body # 旧桥名清零
assert "getApiBase" not in body # 同源:绝对地址拼接已移除
assert "../shared/bridge.js" in body
def test_h5_home_served(client) -> None:
resp = client.get("/h5/home/index.html")
assert resp.status_code == 200
assert resp.headers.get("cache-control") == "no-cache"
body = resp.text
assert 'id="home"' in body
assert "data-cc-id" not in body # 原型编辑器留痕已剥
assert "../../assets/" not in body # 素材路径已本地化
assert "/api/v1/platform/stats" in body # 已接同源数据
assert body.count('class="screen') == 1 # 只剩首页一屏
def test_h5_home_asset_served(client) -> None:
resp = client.get("/h5/home/assets/shared/logos/sb-brand.png")
assert resp.status_code == 200
def test_h5_bridge_has_get_location(client) -> None:
# H2b: 首页 feed 需经纬度, bridge 暴露同步 getLocation()(无桥 mock 北京)
resp = client.get("/h5/shared/bridge.js")
assert resp.status_code == 200
body = resp.text
assert "getLocation" in body
assert "116.404" in body and "39.928" in body # 浏览器 mock 北京兜底
def test_h5_home_feed_wired(client) -> None:
# H2b: 首页 feed 接真实美团端点 + 抢换链;mock 静态卡已移除
resp = client.get("/h5/home/index.html")
assert resp.status_code == 200
body = resp.text
assert "/api/v1/meituan/feed" in body # rec/distance
assert "/api/v1/meituan/top-sales" in body # 销量最高
assert "/api/v1/meituan/referral-link" in body # 抢
assert "HomeFeed" in body # feed 模块已挂
assert "茶百道" not in body # 写死的 mock 卡(店名)已移除
assert "chabaidao.png" not in body # 写死的 mock 头图已移除
assert "比团购省 5.5 元" not in body # 随原生:mock 卡的「比团购省」标签已删(渲染只用 price_label/rank_label)
def test_h5_home_last_compare_wired(client) -> None:
# 「上次比价」横幅改接真实 /api/v1/compare/records + 4 分钟新鲜窗口;原写死 mock 默认值已移除
resp = client.get("/h5/home/index.html")
assert resp.status_code == 200
body = resp.text
assert "/api/v1/compare/records" in body # 接真实比价记录端点
assert "pickFreshLastCompare" in body # 4 分钟新鲜窗口逻辑
assert "DEFAULT_LAST_COMPARE_RECORD" not in body # 写死 mock 默认已移除
assert 'id="lastCompareShop">窑鸡王' not in body # 横幅店名静态 mock 占位已清空
def test_compare_records_requires_auth(client) -> None:
# 横幅靠 Bearer token 才拿得到数据;无鉴权必须 401(无桥/未登录时横幅隐藏)
resp = client.get("/api/v1/compare/records?limit=5")
assert resp.status_code == 401
def test_h5_home_coupon_popup_coin_icon_served(client) -> None:
# 「去领取」弹窗右上角金币图标:welfare 资源子树曾漏本地化 → 404 不显示;补齐后须 200
resp = client.get("/h5/home/assets/welfare/index/coin-icon.png")
assert resp.status_code == 200
def test_h5_home_coupon_ad_reward_coins_served(client) -> None:
# 领券「看广告赚金币」到账 toast(showCouponAdRewardToast)的金币堆图标:同属漏拷的 welfare 子树,补齐后须 200
resp = client.get("/h5/home/assets/welfare/index/checkin-coins-600.png")
assert resp.status_code == 200