Skip to content

Commit

Permalink
test: add group consistency bug test
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Oct 3, 2024
1 parent fa9bd7f commit e837ced
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7681,4 +7681,50 @@ mod tests {

Ok(())
}

/// Tests that info message is not picked as a parent.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_add_member_bug() -> Result<()> {
let mut tcm = TestContextManager::new();

let alice = &tcm.alice().await;
let bob = &tcm.bob().await;

let alice_bob_contact_id = Contact::create(alice, "Bob", "[email protected]").await?;
let alice_fiona_contact_id = Contact::create(alice, "Fiona", "[email protected]").await?;

// Create a group.
let alice_chat_id =
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;

// Promote the group.
let alice_sent_msg = alice
.send_text(alice_chat_id, "Hi! I created a group.")
.await;
let bob_received_msg = bob.recv_msg(&alice_sent_msg).await;

let bob_chat_id = bob_received_msg.get_chat_id();
bob_chat_id.accept(&bob).await?;

// Alice removes Fiona from the chat.
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
let _alice_sent_add_msg = alice.pop_sent_msg().await;

SystemTime::shift(Duration::from_secs(3600));

// Bob sends a message
// to Alice and Fiona because he still has not received
// a message about Fiona being removed.
let bob_sent_msg = bob.send_text(bob_chat_id, "Hi Alice!").await;

// Alice receives a message.
// This should not add Fiona back.
let _alice_received_msg = alice.recv_msg(&bob_sent_msg).await;

assert_eq!(get_chat_contacts(alice, alice_chat_id).await?.len(), 2);

Ok(())
}
}

0 comments on commit e837ced

Please sign in to comment.