From 8ac2cdd929a7214a783d3666cc0c3e5934481992 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Tue, 2 Feb 2021 21:57:41 +0100 Subject: [PATCH] Add `set_config_bool`, fix rust test to test the current expected behavior --- src/config.rs | 5 +++++ src/message.rs | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index 02aff7cff..654949176 100644 --- a/src/config.rs +++ b/src/config.rs @@ -290,6 +290,11 @@ impl Context { _ => self.sql.set_raw_config(self, key, value).await, } } + + pub async fn set_config_bool(&self, key: Config, value: bool) -> crate::sql::Result<()> { + self.set_config(key, if value { Some("1") } else { None }) + .await + } } /// Returns all available configuration keys concated together. diff --git a/src/message.rs b/src/message.rs index fb61ab22f..b93649f23 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1968,6 +1968,7 @@ mod tests { true, false, false, + false, ) .await; } @@ -1984,6 +1985,7 @@ mod tests { false, false, false, + false, ) .await; } @@ -1991,21 +1993,26 @@ mod tests { #[async_std::test] async fn test_needs_move_outgoing() { - // Test outgoing emails - for (folder, mvbox_move, chat_msg, mut expected_destination) in COMBINATIONS_ACCEPTED_CHAT { - if *folder == "INBOX" && !mvbox_move && *chat_msg { - expected_destination = "Sent" + for sentbox_move in &[true, false] { + // Test outgoing emails + for (folder, mvbox_move, chat_msg, mut expected_destination) in + COMBINATIONS_ACCEPTED_CHAT + { + if *folder == "INBOX" && !mvbox_move && *chat_msg && *sentbox_move { + expected_destination = "Sent" + } + check_needs_move_combination( + folder, + *mvbox_move, + *chat_msg, + expected_destination, + true, + true, + false, + *sentbox_move, + ) + .await; } - check_needs_move_combination( - folder, - *mvbox_move, - *chat_msg, - expected_destination, - true, - true, - false, - ) - .await; } } @@ -2021,11 +2028,13 @@ mod tests { true, true, true, + false, ) .await; } } + #[allow(clippy::too_many_arguments)] async fn check_needs_move_combination( folder: &str, mvbox_move: bool, @@ -2034,6 +2043,7 @@ mod tests { accepted_chat: bool, outgoing: bool, setupmessage: bool, + sentbox_move: bool, ) { use crate::dc_receive_imf::dc_receive_imf; println!("Testing: For folder {}, mvbox_move {}, chat_msg {}, accepted {}, outgoing {}, setupmessage {}", @@ -2060,6 +2070,10 @@ mod tests { .set_config(Config::ShowEmails, Some("2")) .await .unwrap(); + t.ctx + .set_config_bool(Config::SentboxMove, sentbox_move) + .await + .unwrap(); if accepted_chat { let contact_id = Contact::create(&t.ctx, "", "bob@example.net")