fix(names): 会话/统计弹窗/zip 文件名的共享好友昵称读 link 快照
用户报 Lily 聊天窗口「聊天好友」列表里 A**郑 显示成 wxid_ir6uxy2li8no22 ——A**郑是 14 个员工共享的客户,档案行(customer 全局单行 last-wins)挂在 别的员工名下,按 owner 查档案查空,三个显示位回退 wxid: - sessions._meta(会话列表名字/头像/delete_flag) - staff_chat_stats._customer_names(五数字弹窗明细) - chat-html-zip 文件名 统一改为优先 customer_account_link per-owner 快照(link 未覆盖回退档案, 空表过渡安全)。staff_stats(统计分析新客户等)仍是档案口径,属分析语义 另行评估。613 测试绿(新增会话共享好友昵称 2 例)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import time
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.db.models import ChatGroup, Customer, Message
|
||||
from app.db.models import ChatGroup, Customer, CustomerAccountLink, Message
|
||||
|
||||
OWNER = "wx_owner_s"
|
||||
CH = "wechat"
|
||||
@@ -45,6 +45,40 @@ async def test_sessions_friend_and_group(make_client):
|
||||
assert g["name"] == "群一号" and g["today_count"] == 1
|
||||
|
||||
|
||||
async def test_sessions_shared_friend_name_from_link(make_client):
|
||||
"""共享好友昵称读 link 快照(2026-09-09):档案行挂在别的员工名下时,
|
||||
会话列表此前回退显示 wxid;link 表每账号一行,回填后都有昵称。
|
||||
"""
|
||||
|
||||
async def seed(session: AsyncSession) -> None:
|
||||
session.add_all([
|
||||
# OWNER 与共享好友 t_shared 有会话
|
||||
Message(msg_id="sh1", channel=CH, owner_account_id=OWNER, talker_id="t_shared",
|
||||
room_id=None, is_send=True, timestamp=_NOW, type="text", type_raw=1, text="x"),
|
||||
# 档案行(last-wins)挂在别的员工名下——按 owner 查档案必然查空
|
||||
Customer(friend_id="t_shared", channel=CH,
|
||||
owner_account_id="wx_other", friend_nickname="A**郑"),
|
||||
# OWNER 名下的 per-owner link 快照
|
||||
CustomerAccountLink(channel=CH, owner_account_id=OWNER, friend_id="t_shared",
|
||||
friend_nickname="A**郑", friend_remark=None),
|
||||
])
|
||||
await session.commit()
|
||||
|
||||
client = await make_client(seed)
|
||||
r = await client.get("/api/sessions", params={"owner_account_id": OWNER, "channel": CH})
|
||||
assert r.status_code == 200
|
||||
by = {s.get("talker_id"): s for s in r.json()["sessions"]}
|
||||
assert by["t_shared"]["name"] == "A**郑"
|
||||
|
||||
|
||||
async def test_sessions_name_falls_back_to_archive_without_link(make_client):
|
||||
"""link 未覆盖的好友回退档案路径(空表过渡安全)。"""
|
||||
client = await make_client(_seed)
|
||||
r = await client.get("/api/sessions", params={"owner_account_id": OWNER, "channel": CH})
|
||||
by = {s.get("talker_id"): s for s in r.json()["sessions"]}
|
||||
assert by["t1"]["name"] == "Alice" # 档案行在 OWNER 名下
|
||||
|
||||
|
||||
async def test_sessions_sorted_by_last_chat_time_desc(make_client):
|
||||
client = await make_client(_seed)
|
||||
body = (await client.get("/api/sessions", params={"owner_account_id": OWNER})).json()
|
||||
|
||||
Reference in New Issue
Block a user