From a5702e92f1ff4dec536fe601b4115bb16b144cb5 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 10 Jul 2024 14:52:31 +0200 Subject: [PATCH] test(base): Test `RoomInfoNotableUpdateReason::RECENCY_TIMESTAMP` is sent. This patch adds a missing test to ensure that a `RoomInfoNotableUpdateReason::RECENCY_TIMESTAMP` is correctly sent. --- crates/matrix-sdk-base/src/sliding_sync.rs | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 49e21f46f..96318bee5 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -806,7 +806,7 @@ mod tests { rooms::normal::{RoomHero, RoomInfoNotableUpdateReasons}, store::MemoryStore, test_utils::logged_in_base_client, - BaseClient, Room, RoomState, + BaseClient, Room, RoomInfoNotableUpdate, RoomState, }; #[async_test] @@ -1847,6 +1847,46 @@ mod tests { } } + #[async_test] + async fn test_recency_timestamp_can_trigger_a_notable_update_reason() { + // Given a logged-in client + let client = logged_in_base_client(None).await; + let mut room_info_notable_update_stream = client.room_info_notable_update_receiver(); + let room_id = room_id!("!r:e.uk"); + + // When I send sliding sync response containing a room with a recency timestamp. + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())), + }); + let response = response_with_room(room_id, room); + client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); + + // Then a room info notable update is NOT received, because it's the first time the room is seen. + assert_matches!( + room_info_notable_update_stream.recv().await, + Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { + assert_eq!(received_room_id, room_id); + assert!(!received_reasons.contains(RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP)); + } + ); + + // When I send sliding sync response containing a room with a recency timestamp. + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: Some(MilliSecondsSinceUnixEpoch(43u32.into())), + }); + let response = response_with_room(room_id, room); + client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); + + // Then a room info notable update is received. + assert_matches!( + room_info_notable_update_stream.recv().await, + Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { + assert_eq!(received_room_id, room_id); + assert!(received_reasons.contains(RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP)); + } + ); + } + async fn choose_event_to_cache(events: &[SyncTimelineEvent]) -> Option { let room = make_room(); let mut room_info = room.clone_info();