From f3fb26c0662b34f0addf3be015a2e207d43e5427 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 14 Apr 2021 13:56:28 +0200 Subject: [PATCH] add a test to search for one-to-one-chats coming without authnames --- src/chatlist.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/chatlist.rs b/src/chatlist.rs index a44ea8303..6cdc4d241 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -614,6 +614,72 @@ mod tests { Ok(()) } + #[async_std::test] + async fn test_search_single_chat_without_authname() -> anyhow::Result<()> { + let t = TestContext::new_alice().await; + + // receive a one-to-one-message without authname set, accept contact request + dc_receive_imf( + &t, + b"From: bob@example.org\n\ + To: alice@example.com\n\ + Subject: foo\n\ + Message-ID: \n\ + Chat-Version: 1.0\n\ + Date: Sun, 22 Mar 2021 22:38:57 +0000\n\ + \n\ + hello foo\n", + "INBOX", + 1, + false, + ) + .await?; + + let msg = t.get_last_msg().await; + let chat_id = + message::decide_on_contact_request(&t, msg.get_id(), ContactRequestDecision::StartChat) + .await + .unwrap(); + let contacts = get_chat_contacts(&t, chat_id).await?; + let contact_id = *contacts.first().unwrap(); + let chat = Chat::load_from_db(&t, chat_id).await?; + assert_eq!(chat.get_name(), "bob@example.org"); + + // check, the one-to-one-chat can be found using chatlist search query + let chats = Chatlist::try_load(&t, 0, Some("bob@example.org"), None).await?; + assert_eq!(chats.len(), 1); + assert_eq!(chats.get_chat_id(0), chat_id); + + // change the name of the contact; this also changes the name of the one-to-one-chat + let test_id = Contact::create(&t, "Bob Nickname", "bob@example.org").await?; + assert_eq!(contact_id, test_id); + let chat = Chat::load_from_db(&t, chat_id).await?; + assert_eq!(chat.get_name(), "Bob Nickname"); + let chats = Chatlist::try_load(&t, 0, Some("bob@example.org"), None).await?; + assert_eq!(chats.len(), 0); // email-addresses are searchable in contacts, not in chats + let chats = Chatlist::try_load(&t, 0, Some("Bob Nickname"), None).await?; + assert_eq!(chats.len(), 1); + assert_eq!(chats.get_chat_id(0), chat_id); + + // revert name change, this again changes the name of the one-to-one-chat to the email-address + let test_id = Contact::create(&t, "", "bob@example.org").await?; + assert_eq!(contact_id, test_id); + let chat = Chat::load_from_db(&t, chat_id).await?; + assert_eq!(chat.get_name(), "bob@example.org"); + let chats = Chatlist::try_load(&t, 0, Some("bob@example.org"), None).await?; + assert_eq!(chats.len(), 1); + let chats = Chatlist::try_load(&t, 0, Some("bob nickname"), None).await?; + assert_eq!(chats.len(), 0); + + // finally, also check that a simple substring-search is working with email-addresses + let chats = Chatlist::try_load(&t, 0, Some("b@exa"), None).await?; + assert_eq!(chats.len(), 1); + let chats = Chatlist::try_load(&t, 0, Some("b@exac"), None).await?; + assert_eq!(chats.len(), 0); + + Ok(()) + } + #[async_std::test] async fn test_get_summary_unwrap() { let t = TestContext::new().await;