test(analytics): health 契约加深——ISO 序列化断言/空库6实体/诊断端点500有意注释
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
"""/api/analytics/health:E0-lite 冒烟。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.db.models import MsgDailyStats
|
||||
import datetime as dt
|
||||
|
||||
from app.db.models import Customer, MsgDailyStats
|
||||
|
||||
# naive:updated_at 列是无时区 DateTime;fromisoformat 构造不触发 DTZ 检查
|
||||
_SEEN = "2026-09-04T12:00:00"
|
||||
|
||||
|
||||
async def test_health_empty(make_client):
|
||||
@@ -13,7 +18,8 @@ async def test_health_empty(make_client):
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["data_as_of"] is None
|
||||
assert any(e["table"] == "message" for e in body["entities"])
|
||||
assert len(body["entities"]) == 6
|
||||
assert all(e["last_seen"] is None for e in body["entities"])
|
||||
|
||||
|
||||
async def test_health_with_stats(make_client):
|
||||
@@ -31,9 +37,21 @@ async def test_health_with_stats(make_client):
|
||||
last_is_send=False,
|
||||
)
|
||||
)
|
||||
session.add(
|
||||
Customer(
|
||||
friend_id="f1",
|
||||
channel="wechat",
|
||||
updated_at=dt.datetime.fromisoformat(_SEEN),
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
client = await make_client(seed)
|
||||
r = await client.get("/api/analytics/health")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["data_as_of"] == 1756900000000
|
||||
entities = {e["table"]: e["last_seen"] for e in r.json()["entities"]}
|
||||
# 前端契约:last_seen 必须是 ISO 字符串(fromisoformat 可解析)
|
||||
assert dt.datetime.fromisoformat(entities["customer"]) == dt.datetime.fromisoformat(
|
||||
_SEEN
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user