feat(h5): 首页「上次比价」横幅接真实 /api/v1/compare/records(4 分钟新鲜窗口)

删写死 mock(DEFAULT_LAST_COMPARE_RECORD + localStorage 读),改带 Bearer token 拉真实比价记录;取最近一条 status=success 且 created_at 在 4 分钟内才显示(对齐原生 HomeViewModel.loadLastCompare),否则/未登录/401 隐藏横幅;进页 + 回前台 visibilitychange 各拉一次;点击仍走 SGBridge.navigate('compareResult')。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
guke
2026-06-30 10:39:18 +08:00
parent 6682f9d0d4
commit 452d7fef8f
2 changed files with 61 additions and 19 deletions
+16
View File
@@ -70,3 +70,19 @@ def test_h5_home_feed_wired(client) -> None:
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 默认已移除
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