diff --git a/yunke-server/app/api/routers/customer.py b/yunke-server/app/api/routers/customer.py index 6d42e55..a65a0cc 100644 --- a/yunke-server/app/api/routers/customer.py +++ b/yunke-server/app/api/routers/customer.py @@ -71,7 +71,6 @@ async def list_customers( list_stmt = list_stmt.where(*conditions) list_stmt = ( list_stmt.order_by( - sa.nullslast(Customer.last_chat_time.desc()), Customer.friend_id.asc(), ) .limit(page_size) diff --git a/yunke-server/app/api/routers/groups.py b/yunke-server/app/api/routers/groups.py index b5c2e69..8717bcc 100644 --- a/yunke-server/app/api/routers/groups.py +++ b/yunke-server/app/api/routers/groups.py @@ -61,7 +61,6 @@ async def list_groups( list_stmt = list_stmt.where(*conditions) list_stmt = ( list_stmt.order_by( - sa.nullslast(ChatGroup.last_chat_time.desc()), ChatGroup.room_id.asc(), ) .limit(page_size) diff --git a/yunke-server/tests/test_api_customer.py b/yunke-server/tests/test_api_customer.py index 32308ea..6cffc0f 100644 --- a/yunke-server/tests/test_api_customer.py +++ b/yunke-server/tests/test_api_customer.py @@ -205,19 +205,17 @@ async def test_pagination_page_size_one(client: AsyncClient): assert len(body["items"]) == 1 -async def test_order_is_last_chat_time_desc_nulls_last(client: AsyncClient): - """Order: ``last_chat_time desc`` (nulls last), then ``friend_id``. +async def test_order_is_friend_id_asc(client: AsyncClient): + """Order: ``friend_id ASC`` (natural API/云客 order). - Seeded rows have last_chat_time 2000 / 1000 / None -> expected order - ``[wx_a, wx_b, wa_c]`` (the whatsapp row with NULL last_chat_time lands - last even though it has no timestamp). + Seeded IDs wa_c < wx_a < wx_b → expected order ``[wa_c, wx_a, wx_b]``. """ r = await client.get( "/api/customers", params={"page": 1, "page_size": 20} ) assert r.status_code == 200 ids = [it["friend_id"] for it in r.json()["items"]] - assert ids == ["wx_a", "wx_b", "wa_c"] + assert ids == ["wa_c", "wx_a", "wx_b"] async def test_filter_by_owner_account_id(client: AsyncClient):