test(chats): ensure saved chat delete clears history only
Some checks failed
CI / test (push) Failing after 1m28s

This commit is contained in:
2026-03-08 20:27:33 +03:00
parent f57e254bcc
commit 362098b954
2 changed files with 35 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ Legend:
2. User Profile - `DONE` (username, name, avatar, bio, update) 2. User Profile - `DONE` (username, name, avatar, bio, update)
3. User Status - `PARTIAL` (online/last seen/offline; "recently" heuristic limited) 3. User Status - `PARTIAL` (online/last seen/offline; "recently" heuristic limited)
4. Contacts - `PARTIAL` (list/search/add/remove/block/unblock; `add by email` flow covered by integration tests including `success/not found/blocked conflict`; UX moved to menu) 4. Contacts - `PARTIAL` (list/search/add/remove/block/unblock; `add by email` flow covered by integration tests including `success/not found/blocked conflict`; UX moved to menu)
5. Chat List - `DONE` (all/pinned/archive/sort/unread) 5. Chat List - `DONE` (all/pinned/archive/sort/unread; saved-messages delete behavior covered: clear history without deleting chat)
6. Chat Types - `DONE` (private/group/channel) 6. Chat Types - `DONE` (private/group/channel)
7. Chat Creation - `DONE` (private/group/channel) 7. Chat Creation - `DONE` (private/group/channel)
8. Messages (base) - `DONE` (send/read/edit/delete/delete for all; 7-day edit window enforced and covered by integration tests; group UI shows sender names over bubbles + sender avatars on incoming message clusters) 8. Messages (base) - `DONE` (send/read/edit/delete/delete for all; 7-day edit window enforced and covered by integration tests; group UI shows sender names over bubbles + sender avatars on incoming message clusters)

View File

@@ -101,6 +101,40 @@ async def test_edit_message_older_than_7_days_is_forbidden(client, db_session):
assert "7 days" in edit_message_response.json().get("detail", "") assert "7 days" in edit_message_response.json().get("detail", "")
async def test_delete_saved_messages_chat_clears_messages_but_keeps_chat(client, db_session):
user = await _create_verified_user(
client,
db_session,
"saved_clear_user@example.com",
"saved_clear_user",
"strongpass123",
)
auth = {"Authorization": f"Bearer {user['access_token']}"}
saved_chat_response = await client.get("/api/v1/chats/saved", headers=auth)
assert saved_chat_response.status_code == 200
saved_chat = saved_chat_response.json()
saved_chat_id = saved_chat["id"]
send_message_response = await client.post(
"/api/v1/messages",
headers=auth,
json={"chat_id": saved_chat_id, "type": "text", "text": "saved note"},
)
assert send_message_response.status_code == 201
delete_chat_response = await client.delete(f"/api/v1/chats/{saved_chat_id}", headers=auth)
assert delete_chat_response.status_code == 204
saved_chat_after_delete = await client.get("/api/v1/chats/saved", headers=auth)
assert saved_chat_after_delete.status_code == 200
assert saved_chat_after_delete.json()["id"] == saved_chat_id
messages_after_delete = await client.get(f"/api/v1/messages/{saved_chat_id}", headers=auth)
assert messages_after_delete.status_code == 200
assert messages_after_delete.json() == []
async def test_private_chat_respects_contacts_only_policy(client, db_session): async def test_private_chat_respects_contacts_only_policy(client, db_session):
u1 = await _create_verified_user(client, db_session, "pm_u1@example.com", "pm_user_one", "strongpass123") u1 = await _create_verified_user(client, db_session, "pm_u1@example.com", "pm_user_one", "strongpass123")
u2 = await _create_verified_user(client, db_session, "pm_u2@example.com", "pm_user_two", "strongpass123") u2 = await _create_verified_user(client, db_session, "pm_u2@example.com", "pm_user_two", "strongpass123")