Skip to content

Commit cd14a15

Browse files
committed
test: Add multidevice test
1 parent 0426baa commit cd14a15

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
@@ -2934,6 +2934,9 @@ async fn test_broadcast_channel_protected_listid() -> Result<()> {
29342934
Ok(())
29352935
}
29362936

2937+
/// Test that if Bob leaves a broadcast channel,
2938+
/// Alice (the channel owner) won't see him as a member anymore,
2939+
/// but won't be notified about this in any way.
29372940
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
29382941
async fn test_leave_broadcast() -> Result<()> {
29392942
let mut tcm = TestContextManager::new();
@@ -2989,6 +2992,44 @@ async fn test_leave_broadcast() -> Result<()> {
29892992
Ok(())
29902993
}
29912994

2995+
/// Tests that if Bob leaves a broadcast channel with one device,
2996+
/// the other device shows a correct info message "You left.".
2997+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2998+
async fn test_leave_broadcast_multidevice() -> Result<()> {
2999+
let mut tcm = TestContextManager::new();
3000+
let alice = &tcm.alice().await;
3001+
let bob0 = &tcm.bob().await;
3002+
let bob1 = &tcm.bob().await;
3003+
3004+
tcm.section("Alice creates broadcast channel with Bob.");
3005+
let alice_chat_id = create_broadcast(alice, "foo".to_string()).await?;
3006+
let bob_contact = alice.add_or_lookup_contact(bob0).await.id;
3007+
add_contact_to_chat(alice, alice_chat_id, bob_contact).await?;
3008+
3009+
tcm.section("Alice sends first message to broadcast.");
3010+
let sent_msg = alice.send_text(alice_chat_id, "Hello!").await;
3011+
let bob0_hello = bob0.recv_msg(&sent_msg).await;
3012+
let bob1_hello = bob1.recv_msg(&sent_msg).await;
3013+
3014+
tcm.section("Bob leaves the broadcast channel with his first device.");
3015+
let bob_chat_id = bob0_hello.chat_id;
3016+
bob_chat_id.accept(bob0).await?;
3017+
remove_contact_from_chat(bob0, bob_chat_id, ContactId::SELF).await?;
3018+
3019+
let leave_msg = bob0.pop_sent_msg().await;
3020+
let rcvd = bob1.recv_msg(&leave_msg).await;
3021+
3022+
assert_eq!(rcvd.chat_id, bob1_hello.chat_id);
3023+
assert!(rcvd.is_info());
3024+
assert_eq!(rcvd.get_info_type(), SystemMessage::MemberRemovedFromGroup);
3025+
assert_eq!(
3026+
rcvd.text,
3027+
stock_str::msg_group_left_local(bob1, ContactId::SELF).await
3028+
);
3029+
3030+
Ok(())
3031+
}
3032+
29923033
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
29933034
async fn test_create_for_contact_with_blocked() -> Result<()> {
29943035
let t = TestContext::new().await;

0 commit comments

Comments
 (0)