Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Dec 24, 2024
1 parent 8f3a656 commit adda704
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ pub(crate) async fn start_ephemeral_timers(context: &Context) -> Result<()> {
mod tests {
use super::*;
use crate::chat::marknoticed_chat;
use crate::chat::ChatVisibility;
use crate::config::Config;
use crate::constants::DC_CHAT_ID_ARCHIVED_LINK;
use crate::download::DownloadState;
use crate::location;
use crate::message::markseen_msgs;
Expand Down Expand Up @@ -1468,4 +1470,34 @@ mod tests {
.is_none());
Ok(())
}

/// Tests that archiving the chat and marking all archived chats as noticed
/// starts ephemeral timer.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_archived_and_noticed_ephemeral_timer() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;

let chat = alice.create_chat(bob).await;
let duration = 60;
chat.id
.set_ephemeral_timer(alice, Timer::Enabled { duration })
.await?;
let bob_received_message = tcm.send_recv(alice, bob, "Hello!").await;

bob_received_message
.chat_id
.set_visibility(bob, ChatVisibility::Archived)
.await?;
marknoticed_chat(bob, DC_CHAT_ID_ARCHIVED_LINK).await?;
SystemTime::shift(Duration::from_secs(100));

delete_expired_messages(bob, time()).await?;

assert!(Message::load_from_db_optional(bob, bob_received_message.id)
.await?
.is_none());
Ok(())
}
}

0 comments on commit adda704

Please sign in to comment.