feat(api): /api/customers 加 q 文本搜索(昵称/备注/ID/手机号,LIKE转义) + /api/groups 加 q 群名搜索

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-25 18:55:53 +08:00
parent 328aec80bc
commit 1b66be6a53
4 changed files with 127 additions and 8 deletions
+22
View File
@@ -303,3 +303,25 @@ async def test_groups_owner_fields_default_null(make_client):
for key in ("owner_name", "owner_wxid", "owner_alias",
"owner_avatar", "friend_count", "create_time"):
assert item[key] is None
# ---------------------------------------------------------------------------
# GET /api/groups?q= — 群名称模糊搜索(通讯录群 tab 搜索框,LIKE 通配转义)
# ---------------------------------------------------------------------------
async def test_q_room_name_substring_filter(make_client):
"""``?q=Team A`` -> 群名子串匹配(LIKE 默认大小写敏感);q 空串不过滤。"""
client = await make_client(_seed)
r = await client.get("/api/groups", params={"q": "Team A"})
assert r.status_code == 200
body = r.json()
assert body["total"] == 1
assert body["items"][0]["room_id"] == "room_a@chatroom"
# 子串跨行命中: "Team" 同时出现在 Team A / Team B / WA Team
r2 = await client.get("/api/groups", params={"q": "Team"})
assert {it["room_id"] for it in r2.json()["items"]} == {
"room_a@chatroom", "room_b@chatroom", "wa_room_x@s.whatsapp.net",
}
# 空串 -> 不过滤
r3 = await client.get("/api/groups", params={"q": ""})
assert r3.json()["total"] == 3