mirror of
https://github.com/chatmail/core.git
synced 2026-04-25 01:16:29 +03:00
test: use vCards to create contacts in more Rust tests
This commit is contained in:
@@ -4066,38 +4066,39 @@ async fn test_unsigned_chat_group_hdr() -> Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_sync_member_list_on_rejoin() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = tcm.alice().await;
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
let fiona = &tcm.fiona().await;
|
||||
|
||||
let bob_id = Contact::create(&alice, "", "bob@example.net").await?;
|
||||
let claire_id = Contact::create(&alice, "", "claire@example.de").await?;
|
||||
let bob_id = alice.add_or_lookup_contact_id(bob).await;
|
||||
let fiona_id = alice.add_or_lookup_contact_id(fiona).await;
|
||||
|
||||
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "foos").await?;
|
||||
add_contact_to_chat(&alice, alice_chat_id, bob_id).await?;
|
||||
add_contact_to_chat(&alice, alice_chat_id, claire_id).await?;
|
||||
let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "foos").await?;
|
||||
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
|
||||
add_contact_to_chat(alice, alice_chat_id, fiona_id).await?;
|
||||
|
||||
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
||||
send_text_msg(alice, alice_chat_id, "populate".to_string()).await?;
|
||||
let add = alice.pop_sent_msg().await;
|
||||
let bob = tcm.bob().await;
|
||||
bob.recv_msg(&add).await;
|
||||
let bob_chat_id = bob.get_last_msg().await.chat_id;
|
||||
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 3);
|
||||
assert_eq!(get_chat_contacts(bob, bob_chat_id).await?.len(), 3);
|
||||
|
||||
// remove bob from chat
|
||||
remove_contact_from_chat(&alice, alice_chat_id, bob_id).await?;
|
||||
remove_contact_from_chat(alice, alice_chat_id, bob_id).await?;
|
||||
let remove_bob = alice.pop_sent_msg().await;
|
||||
bob.recv_msg(&remove_bob).await;
|
||||
|
||||
// remove any other member
|
||||
remove_contact_from_chat(&alice, alice_chat_id, claire_id).await?;
|
||||
remove_contact_from_chat(alice, alice_chat_id, fiona_id).await?;
|
||||
alice.pop_sent_msg().await;
|
||||
|
||||
// re-add bob
|
||||
add_contact_to_chat(&alice, alice_chat_id, bob_id).await?;
|
||||
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
|
||||
let add2 = alice.pop_sent_msg().await;
|
||||
bob.recv_msg(&add2).await;
|
||||
|
||||
// number of members in chat should have updated
|
||||
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 2);
|
||||
assert_eq!(get_chat_contacts(bob, bob_chat_id).await?.len(), 2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4109,8 +4110,7 @@ async fn test_ignore_outdated_membership_changes() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
let alice_bob_id =
|
||||
Contact::create(alice, "", &bob.get_config(Config::Addr).await?.unwrap()).await?;
|
||||
let alice_bob_id = alice.add_or_lookup_contact_id(bob).await;
|
||||
let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "grp").await?;
|
||||
|
||||
// Alice creates a group chat. Bob accepts it.
|
||||
@@ -4798,13 +4798,14 @@ async fn test_create_group_with_big_msg() -> Result<()> {
|
||||
async fn test_partial_group_consistency() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = tcm.alice().await;
|
||||
let bob_id = Contact::create(&alice, "", "bob@example.net").await?;
|
||||
let bob = tcm.bob().await;
|
||||
let fiona = tcm.fiona().await;
|
||||
let bob_id = alice.add_or_lookup_contact_id(&bob).await;
|
||||
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "foos").await?;
|
||||
add_contact_to_chat(&alice, alice_chat_id, bob_id).await?;
|
||||
|
||||
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
||||
let add = alice.pop_sent_msg().await;
|
||||
let bob = tcm.bob().await;
|
||||
bob.recv_msg(&add).await;
|
||||
let bob_chat_id = bob.get_last_msg().await.chat_id;
|
||||
let contacts = get_chat_contacts(&bob, bob_chat_id).await?;
|
||||
@@ -4839,7 +4840,7 @@ Chat-Group-Member-Added: charlie@example.com",
|
||||
add_contact_to_chat(
|
||||
&alice,
|
||||
alice_chat_id,
|
||||
Contact::create(&alice, "fiona", "fiona@example.net").await?,
|
||||
alice.add_or_lookup_contact_id(&fiona).await,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -5410,14 +5411,16 @@ Hello!"
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_rename_chat_on_missing_message() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
let bob = TestContext::new_bob().await;
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = tcm.alice().await;
|
||||
let bob = tcm.bob().await;
|
||||
let charlie = tcm.charlie().await;
|
||||
let chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "Group").await?;
|
||||
add_to_chat_contacts_table(
|
||||
&alice,
|
||||
time(),
|
||||
chat_id,
|
||||
&[Contact::create(&alice, "bob", "bob@example.net").await?],
|
||||
&[alice.add_or_lookup_contact_id(&bob).await],
|
||||
)
|
||||
.await?;
|
||||
send_text_msg(&alice, chat_id, "populate".to_string()).await?;
|
||||
@@ -5431,8 +5434,8 @@ async fn test_rename_chat_on_missing_message() -> Result<()> {
|
||||
bob.pop_sent_msg().await;
|
||||
|
||||
// Bob adds a new member.
|
||||
let bob_orange = Contact::create(&bob, "orange", "orange@example.net").await?;
|
||||
add_contact_to_chat(&bob, bob_chat_id, bob_orange).await?;
|
||||
let bob_charlie = bob.add_or_lookup_contact_id(&charlie).await;
|
||||
add_contact_to_chat(&bob, bob_chat_id, bob_charlie).await?;
|
||||
let add_msg = bob.pop_sent_msg().await;
|
||||
|
||||
// Alice only receives the member addition.
|
||||
|
||||
Reference in New Issue
Block a user