Skip to content

Commit 9e0205a

Browse files
committed
test: Add multidevice test
1 parent 87a7982 commit 9e0205a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/chat/chat_tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,9 @@ async fn test_block_broadcast() -> Result<()> {
28922892
Ok(())
28932893
}
28942894

2895+
/// Test that if Bob leaves a broadcast channel,
2896+
/// Alice (the channel owner) won't see him as a member anymore,
2897+
/// but won't be notified about this in any way.
28952898
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
28962899
async fn test_leave_broadcast() -> Result<()> {
28972900
let mut tcm = TestContextManager::new();
@@ -2947,6 +2950,44 @@ async fn test_leave_broadcast() -> Result<()> {
29472950
Ok(())
29482951
}
29492952

2953+
/// Tests that if Bob leaves a broadcast channel with one device,
2954+
/// the other device shows a correct info message "You left.".
2955+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2956+
async fn test_leave_broadcast_multidevice() -> Result<()> {
2957+
let mut tcm = TestContextManager::new();
2958+
let alice = &tcm.alice().await;
2959+
let bob0 = &tcm.bob().await;
2960+
let bob1 = &tcm.bob().await;
2961+
2962+
tcm.section("Alice creates broadcast channel with Bob.");
2963+
let alice_chat_id = create_broadcast(alice, "foo".to_string()).await?;
2964+
let bob_contact = alice.add_or_lookup_contact(bob0).await.id;
2965+
add_contact_to_chat(alice, alice_chat_id, bob_contact).await?;
2966+
2967+
tcm.section("Alice sends first message to broadcast.");
2968+
let sent_msg = alice.send_text(alice_chat_id, "Hello!").await;
2969+
let bob0_hello = bob0.recv_msg(&sent_msg).await;
2970+
let bob1_hello = bob1.recv_msg(&sent_msg).await;
2971+
2972+
tcm.section("Bob leaves the broadcast channel with his first device.");
2973+
let bob_chat_id = bob0_hello.chat_id;
2974+
bob_chat_id.accept(bob0).await?;
2975+
remove_contact_from_chat(bob0, bob_chat_id, ContactId::SELF).await?;
2976+
2977+
let leave_msg = bob0.pop_sent_msg().await;
2978+
let rcvd = bob1.recv_msg(&leave_msg).await;
2979+
2980+
assert_eq!(rcvd.chat_id, bob1_hello.chat_id);
2981+
assert!(rcvd.is_info());
2982+
assert_eq!(rcvd.get_info_type(), SystemMessage::MemberRemovedFromGroup);
2983+
assert_eq!(
2984+
rcvd.text,
2985+
stock_str::msg_group_left_local(bob1, ContactId::SELF).await
2986+
);
2987+
2988+
Ok(())
2989+
}
2990+
29502991
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
29512992
async fn test_create_for_contact_with_blocked() -> Result<()> {
29522993
let t = TestContext::new().await;

0 commit comments

Comments
 (0)