From 32216a334d7b93cc58acfa3e44a6cc9cb102e8c1 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 1 Dec 2019 00:36:31 +0100 Subject: [PATCH] add a test that checks the device-chat is not recreated for messages that won't be added --- src/chat.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 06580134a..62bd4aa77 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2253,6 +2253,22 @@ mod tests { assert!(was_device_msg_ever_added(&t.ctx, "").is_err()); } + #[test] + fn test_delete_device_chat() { + let t = test_context(Some(Box::new(logging_cb))); + + let mut msg = Message::new(Viewtype::Text); + msg.text = Some("message text".to_string()); + add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)).ok(); + let chats = Chatlist::try_load(&t.ctx, 0, None, None).unwrap(); + assert_eq!(chats.len(), 1); + + // after the device-chat and all messages are deleted, a re-adding should do nothing + delete(&t.ctx, chats.get_chat_id(0)).ok(); + add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)).ok(); + assert_eq!(chatlist_len(&t.ctx, 0), 0) + } + fn chatlist_len(ctx: &Context, listflags: usize) -> usize { Chatlist::try_load(ctx, listflags, None, None) .unwrap()