2026-08-20 13:44:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
# GET /api/customers/declared-total — 云客口径合计(页脚对齐云客显示,2026-08-20)
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
async def _seed_accounts_for_declared(session):
|
|
|
|
|
from app.db.models import WechatAccount
|
|
|
|
|
|
|
|
|
|
session.add_all([
|
|
|
|
|
WechatAccount(wx_id="w1", contacts_num=100),
|
|
|
|
|
WechatAccount(wx_id="w2", contacts_num=23),
|
|
|
|
|
WechatAccount(wx_id="w3", contacts_num=None),
|
|
|
|
|
])
|
|
|
|
|
await session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_declared_total_sums_contacts_num(make_client):
|
2026-08-20 14:04:06 +08:00
|
|
|
"""分渠道 declared_total = Σ 员工账号表 contacts_num(云客含重复口径)。"""
|
|
|
|
|
from app.db.models import WhatsappAccount
|
|
|
|
|
|
|
|
|
|
async def seed_both(session):
|
|
|
|
|
await _seed_accounts_for_declared(session)
|
|
|
|
|
session.add_all([
|
|
|
|
|
WhatsappAccount(uid="a1@s.whatsapp.net", contacts_num=10),
|
|
|
|
|
WhatsappAccount(uid="a2@s.whatsapp.net", contacts_num=5),
|
|
|
|
|
])
|
|
|
|
|
await session.commit()
|
|
|
|
|
|
|
|
|
|
client = await make_client(seed_both)
|
2026-08-20 13:44:39 +08:00
|
|
|
r = await client.get("/api/customers/declared-total")
|
|
|
|
|
assert r.status_code == 200
|
|
|
|
|
body = r.json()
|
2026-08-20 14:04:06 +08:00
|
|
|
assert body["wechat"]["declared_total"] == 123
|
|
|
|
|
assert body["wechat"]["account_count"] == 2 # 只计有值的员工
|
|
|
|
|
assert body["whatsapp"]["declared_total"] == 15
|
|
|
|
|
assert body["whatsapp"]["account_count"] == 2
|