From c19197a9609a63c9419f08d222a1685cb20269aa Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 2 Apr 2025 00:56:20 +0000 Subject: [PATCH] test: port test_multidevice_sync_seen to JSON-RPC --- .../tests/test_multidevice.py | 55 ++++++++++++++++++ python/tests/test_0_complex_or_slow.py | 57 ------------------- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/deltachat-rpc-client/tests/test_multidevice.py b/deltachat-rpc-client/tests/test_multidevice.py index 1e9898b87..663542aa0 100644 --- a/deltachat-rpc-client/tests/test_multidevice.py +++ b/deltachat-rpc-client/tests/test_multidevice.py @@ -1,6 +1,7 @@ from imap_tools import AND from deltachat_rpc_client import EventType +from deltachat_rpc_client.const import MessageState def test_one_account_send_bcc_setting(acfactory, log, direct_imap): @@ -53,3 +54,57 @@ def test_one_account_send_bcc_setting(acfactory, log, direct_imap): ac1_direct_imap.connect() ac1_direct_imap.select_folder("Inbox") assert len(list(ac1_direct_imap.conn.fetch(AND(seen=True)))) == 1 + + +def test_multidevice_sync_seen(acfactory, log): + """Test that message marked as seen on one device is marked as seen on another.""" + ac1, ac2 = acfactory.get_online_accounts(2) + ac1_clone = ac1.clone() + ac1_clone.bring_online() + + ac1.set_config("bcc_self", "1") + ac1_clone.set_config("bcc_self", "1") + + ac1_chat = ac1.create_chat(ac2) + ac1_clone_chat = ac1_clone.create_chat(ac2) + ac2_chat = ac2.create_chat(ac1) + + log.section("Send a message from ac2 to ac1 and check that it's 'fresh'") + ac2_chat.send_text("Hi") + ac1_message = ac1.wait_for_incoming_msg() + ac1_clone_message = ac1_clone.wait_for_incoming_msg() + assert ac1_chat.get_fresh_message_count() == 1 + assert ac1_clone_chat.get_fresh_message_count() == 1 + assert ac1_message.get_snapshot().state == MessageState.IN_FRESH + assert ac1_clone_message.get_snapshot().state == MessageState.IN_FRESH + + log.section("ac1 marks message as seen on the first device") + ac1.mark_seen_messages([ac1_message]) + assert ac1_message.get_snapshot().state == MessageState.IN_SEEN + + log.section("ac1 clone detects that message is marked as seen") + ev = ac1_clone.wait_for_event(EventType.MSGS_NOTICED) + assert ev.chat_id == ac1_clone_chat.id + + log.section("Send an ephemeral message from ac2 to ac1") + ac2_chat.set_ephemeral_timer(60) + ac1.wait_for_event(EventType.CHAT_EPHEMERAL_TIMER_MODIFIED) + ac1.wait_for_incoming_msg() + ac1_clone.wait_for_event(EventType.CHAT_EPHEMERAL_TIMER_MODIFIED) + ac1_clone.wait_for_incoming_msg() + + ac2_chat.send_text("Foobar") + ac1_message = ac1.wait_for_incoming_msg() + ac1_clone_message = ac1_clone.wait_for_incoming_msg() + assert "Ephemeral timer: 60\n" in ac1_message.get_info() + assert "Expires: " not in ac1_clone_message.get_info() + assert "Ephemeral timer: 60\n" in ac1_message.get_info() + assert "Expires: " not in ac1_clone_message.get_info() + + ac1_message.mark_seen() + assert "Expires: " in ac1_message.get_info() + ev = ac1_clone.wait_for_event(EventType.MSGS_NOTICED) + assert ev.chat_id == ac1_clone_chat.id + assert ac1_clone_message.get_snapshot().state == MessageState.IN_SEEN + # Test that the timer is started on the second device after synchronizing the seen status. + assert "Expires: " in ac1_clone_message.get_info() diff --git a/python/tests/test_0_complex_or_slow.py b/python/tests/test_0_complex_or_slow.py index f98b7cd5a..276c4c46e 100644 --- a/python/tests/test_0_complex_or_slow.py +++ b/python/tests/test_0_complex_or_slow.py @@ -331,63 +331,6 @@ def test_ephemeral_timer(acfactory, lp): assert chat1.get_ephemeral_timer() == 0 -def test_multidevice_sync_seen(acfactory, lp): - """Test that message marked as seen on one device is marked as seen on another.""" - ac1 = acfactory.new_online_configuring_account() - ac2 = acfactory.new_online_configuring_account() - ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1) - acfactory.bring_accounts_online() - - ac1.set_config("bcc_self", "1") - ac1_clone.set_config("bcc_self", "1") - - ac1_chat = ac1.create_chat(ac2) - ac1_clone_chat = ac1_clone.create_chat(ac2) - ac2_chat = ac2.create_chat(ac1) - - lp.sec("Send a message from ac2 to ac1 and check that it's 'fresh'") - ac2_chat.send_text("Hi") - ac1_message = ac1._evtracker.wait_next_incoming_message() - ac1_clone_message = ac1_clone._evtracker.wait_next_incoming_message() - assert ac1_chat.count_fresh_messages() == 1 - assert ac1_clone_chat.count_fresh_messages() == 1 - assert ac1_message.is_in_fresh - assert ac1_clone_message.is_in_fresh - - lp.sec("ac1 marks message as seen on the first device") - ac1.mark_seen_messages([ac1_message]) - assert ac1_message.is_in_seen - - lp.sec("ac1 clone detects that message is marked as seen") - ev = ac1_clone._evtracker.get_matching("DC_EVENT_MSGS_NOTICED") - assert ev.data1 == ac1_clone_chat.id - assert ac1_clone_message.is_in_seen - - lp.sec("Send an ephemeral message from ac2 to ac1") - ac2_chat.set_ephemeral_timer(60) - ac1._evtracker.get_matching("DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED") - ac1._evtracker.wait_next_incoming_message() - ac1_clone._evtracker.get_matching("DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED") - ac1_clone._evtracker.wait_next_incoming_message() - - ac2_chat.send_text("Foobar") - ac1_message = ac1._evtracker.wait_next_incoming_message() - ac1_clone_message = ac1_clone._evtracker.wait_next_incoming_message() - assert "Ephemeral timer: 60\n" in ac1_message.get_message_info() - assert "Expires: " not in ac1_clone_message.get_message_info() - assert "Ephemeral timer: 60\n" in ac1_message.get_message_info() - assert "Expires: " not in ac1_clone_message.get_message_info() - - ac1.mark_seen_messages([ac1_message]) - assert ac1_message.is_in_seen - assert "Expires: " in ac1_message.get_message_info() - ev = ac1_clone._evtracker.get_matching("DC_EVENT_MSGS_NOTICED") - assert ev.data1 == ac1_clone_chat.id - assert ac1_clone_message.is_in_seen - # Test that the timer is started on the second device after synchronizing the seen status. - assert "Expires: " in ac1_clone_message.get_message_info() - - def test_see_new_verified_member_after_going_online(acfactory, tmp_path, lp): """The test for the bug #3836: - Alice has two devices, the second is offline.