Skip to content

Commit 7f55613

Browse files
committed
test: avoid creating contacts in test_sync_{accept,block}_before_first_msg()
When it is possible to test that no unhidden contact is creating by looking through the contact list or get the contact ID as the from_id of received message, do it to avoid acidentally creating a contact or changing its origin before testing.
1 parent 03b0185 commit 7f55613

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/chat/chat_tests.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,15 +2964,24 @@ async fn test_sync_accept_before_first_msg() -> Result<()> {
29642964

29652965
let ba_chat = bob.create_chat(alice0).await;
29662966
let sent_msg = bob.send_text(ba_chat.id, "hi").await;
2967-
let a0b_chat_id = alice0.recv_msg(&sent_msg).await.chat_id;
2968-
assert_eq!(alice0.get_chat(&bob).await.blocked, Blocked::Request);
2967+
let rcvd_msg = alice0.recv_msg(&sent_msg).await;
2968+
let a0b_chat_id = rcvd_msg.chat_id;
2969+
let a0b_contact_id = rcvd_msg.from_id;
2970+
assert_eq!(
2971+
Chat::load_from_db(alice0, a0b_chat_id).await?.blocked,
2972+
Blocked::Request
2973+
);
29692974
a0b_chat_id.accept(alice0).await?;
2970-
let a0b_contact = alice0.add_or_lookup_contact(&bob).await;
2975+
let a0b_contact = Contact::get_by_id(alice0, a0b_contact_id).await?;
29712976
assert_eq!(a0b_contact.origin, Origin::CreateChat);
29722977
assert_eq!(alice0.get_chat(&bob).await.blocked, Blocked::Not);
29732978

29742979
sync(alice0, alice1).await;
2975-
let a1b_contact = alice1.add_or_lookup_contact(&bob).await;
2980+
let alice1_contacts = Contact::get_all(alice1, 0, None).await?;
2981+
assert_eq!(alice1_contacts.len(), 1);
2982+
let a1b_contact_id = alice1_contacts[0];
2983+
let a1b_contact = Contact::get_by_id(alice1, a1b_contact_id).await?;
2984+
assert_eq!(a1b_contact.get_addr(), "bob@example.net");
29762985
assert_eq!(a1b_contact.origin, Origin::CreateChat);
29772986
let a1b_chat = alice1.get_chat(&bob).await;
29782987
assert_eq!(a1b_chat.blocked, Blocked::Not);
@@ -2995,22 +3004,22 @@ async fn test_sync_block_before_first_msg() -> Result<()> {
29953004

29963005
let ba_chat = bob.create_chat(alice0).await;
29973006
let sent_msg = bob.send_text(ba_chat.id, "hi").await;
2998-
let a0b_chat_id = alice0.recv_msg(&sent_msg).await.chat_id;
3007+
let rcvd_msg = alice0.recv_msg(&sent_msg).await;
3008+
let a0b_chat_id = rcvd_msg.chat_id;
3009+
let a0b_contact_id = rcvd_msg.from_id;
29993010
assert_eq!(alice0.get_chat(&bob).await.blocked, Blocked::Request);
30003011
a0b_chat_id.block(alice0).await?;
3001-
let a0b_contact = alice0.add_or_lookup_contact(&bob).await;
3012+
let a0b_contact = Contact::get_by_id(alice0, a0b_contact_id).await?;
30023013
assert_eq!(a0b_contact.origin, Origin::IncomingUnknownFrom);
30033014
assert_eq!(alice0.get_chat(&bob).await.blocked, Blocked::Yes);
30043015

30053016
sync(alice0, alice1).await;
3006-
let a1b_contact = alice1.add_or_lookup_contact(&bob).await;
3007-
assert_eq!(a1b_contact.origin, Origin::Hidden);
3008-
assert!(ChatIdBlocked::lookup_by_contact(alice1, a1b_contact.id)
3009-
.await?
3010-
.is_none());
3017+
let alice1_contacts = Contact::get_all(alice1, 0, None).await?;
3018+
assert_eq!(alice1_contacts.len(), 0);
30113019

30123020
let rcvd_msg = alice1.recv_msg(&sent_msg).await;
3013-
let a1b_contact = alice1.add_or_lookup_contact(&bob).await;
3021+
let a1b_contact_id = rcvd_msg.from_id;
3022+
let a1b_contact = Contact::get_by_id(alice1, a1b_contact_id).await?;
30143023
assert_eq!(a1b_contact.origin, Origin::IncomingUnknownFrom);
30153024
let a1b_chat = alice1.get_chat(&bob).await;
30163025
assert_eq!(a1b_chat.blocked, Blocked::Yes);

0 commit comments

Comments
 (0)