feat(analytics): 管理层指标呈现——首响回复率上墙/客户资产总览/自定义日期/排行五新列
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -147,3 +147,51 @@ async def test_overview_unmapped_rollup(make_client, monkeypatch):
|
||||
body = r.json()
|
||||
assert body["cards"]["active_staff"] == 2
|
||||
assert body["cards"]["unmapped_accounts"] == 1
|
||||
|
||||
|
||||
async def test_overview_custom_scope_api(make_client, monkeypatch):
|
||||
"""C1 自定义日期:正常窗 200 + customer_assets 恒在;缺参/start>end/
|
||||
跨度超 366 天/非法日历 全 422;闰年整 366 天放行。"""
|
||||
monkeypatch.setattr(metrics, "today_key", lambda: _TODAY)
|
||||
|
||||
async def seed(session):
|
||||
session.add(MsgDailyStats(channel="wechat", owner_account_id="wx1",
|
||||
peer_kind="friend", peer_id="t1", day=20260815,
|
||||
send_cnt=10, recv_cnt=0, last_ts=1786000000000,
|
||||
last_is_send=True))
|
||||
await session.commit()
|
||||
|
||||
client = await make_client(seed)
|
||||
r = await client.get("/api/analytics/overview", params={
|
||||
"channel": "wechat", "scope": "custom",
|
||||
"start": 20260801, "end": 20260827,
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["scope"] == "custom"
|
||||
assert len(body["days"]) == 27
|
||||
assert body["cards"]["msg_total"] == 10
|
||||
# B1 客户资产总览恒在(全库快照,不随 scope)
|
||||
assert body["customer_assets"]["total"] >= 0
|
||||
|
||||
# 缺 start/end → 422(不让静默落到空窗)
|
||||
r2 = await client.get("/api/analytics/overview",
|
||||
params={"scope": "custom"})
|
||||
assert r2.status_code == 422
|
||||
# start > end → 422
|
||||
r3 = await client.get("/api/analytics/overview", params={
|
||||
"scope": "custom", "start": 20260827, "end": 20260801})
|
||||
assert r3.status_code == 422
|
||||
# 跨度 367 天 → 422(2024-01-01..2025-01-01 含端点 367 天)
|
||||
r4 = await client.get("/api/analytics/overview", params={
|
||||
"scope": "custom", "start": 20240101, "end": 20250101})
|
||||
assert r4.status_code == 422
|
||||
# 非法日历(2 月 30)→ 422——Query ge/le 只拦数值范围不拦日历
|
||||
r5 = await client.get("/api/analytics/overview", params={
|
||||
"scope": "custom", "start": 20260230, "end": 20260301})
|
||||
assert r5.status_code == 422
|
||||
# 闰年整年 366 天(含端点)→ 放行
|
||||
r6 = await client.get("/api/analytics/overview", params={
|
||||
"scope": "custom", "start": 20240101, "end": 20241231})
|
||||
assert r6.status_code == 200
|
||||
assert len(r6.json()["days"]) == 366
|
||||
|
||||
Reference in New Issue
Block a user