test(timeline): get rid of handle_back_paginated_message_event_with_id

Callers can make use of the `EventFactory` which is easier to understand
IMO, and that avoids a special testing function just for this.
This commit is contained in:
Benjamin Bouvier
2024-07-09 18:57:06 +02:00
parent 5a04f5b66a
commit d7cbd9d218
3 changed files with 39 additions and 40 deletions

View File

@@ -47,7 +47,7 @@ use ruma::{
room_id,
serde::Raw,
server_name, uint, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId,
OwnedUserId, RoomId, RoomVersionId, TransactionId, UInt, UserId,
OwnedUserId, RoomVersionId, TransactionId, UInt, UserId,
};
use super::{
@@ -253,19 +253,6 @@ impl TestTimeline {
txn_id
}
async fn handle_back_paginated_message_event_with_id<C>(
&self,
sender: &UserId,
room_id: &RoomId,
event_id: &EventId,
content: C,
) where
C: MessageLikeEventContent,
{
let ev = self.event_builder.make_message_event_with_id(sender, room_id, event_id, content);
self.handle_back_paginated_custom_event(ev).await;
}
async fn handle_back_paginated_custom_event(&self, event: Raw<AnyTimelineEvent>) {
let timeline_event = TimelineEvent::new(event.cast());
self.inner

View File

@@ -15,6 +15,7 @@
use std::sync::Arc;
use eyeball_im::VectorDiff;
use matrix_sdk::test_utils::events::EventFactory;
use matrix_sdk_test::{async_test, ALICE, BOB, CAROL};
use ruma::{
event_id,
@@ -105,20 +106,19 @@ async fn test_read_receipts_updates_on_back_paginated_events() {
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
let room_id = room_id!("!room:localhost");
let f = EventFactory::new().room(room_id);
timeline
.handle_back_paginated_message_event_with_id(
*BOB,
room_id,
event_id!("$event_a"),
RoomMessageEventContent::text_plain("A"),
.handle_back_paginated_custom_event(
f.text_msg("A").sender(*BOB).event_id(event_id!("$event_a")).into_raw_timeline(),
)
.await;
timeline
.handle_back_paginated_message_event_with_id(
*CAROL,
room_id,
event_id!("$event_with_bob_receipt"),
RoomMessageEventContent::text_plain("B"),
.handle_back_paginated_custom_event(
f.text_msg("B")
.sender(*CAROL)
.event_id(event_id!("$event_with_bob_receipt"))
.into_raw_timeline(),
)
.await;
@@ -176,6 +176,7 @@ async fn test_read_receipts_updates_on_filtered_events() {
// Populate more events.
let event_d_id = owned_event_id!("$event_d");
timeline
.handle_live_message_event_with_id(
*ALICE,
@@ -285,20 +286,19 @@ async fn test_read_receipts_updates_on_back_paginated_filtered_events() {
let mut stream = timeline.subscribe().await;
let room_id = room_id!("!room:localhost");
let f = EventFactory::new().room(room_id);
timeline
.handle_back_paginated_message_event_with_id(
*ALICE,
room_id,
event_id!("$event_a"),
RoomMessageEventContent::text_plain("A"),
.handle_back_paginated_custom_event(
f.text_msg("A").sender(*ALICE).event_id(event_id!("$event_a")).into_raw_timeline(),
)
.await;
timeline
.handle_back_paginated_message_event_with_id(
*CAROL,
room_id,
event_id!("$event_with_bob_receipt"),
RoomMessageEventContent::notice_plain("B"),
.handle_back_paginated_custom_event(
f.notice("B")
.sender(*CAROL)
.event_id(event_id!("$event_with_bob_receipt"))
.into_raw_timeline(),
)
.await;
@@ -312,11 +312,8 @@ async fn test_read_receipts_updates_on_back_paginated_filtered_events() {
// Add non-filtered event to show read receipts.
timeline
.handle_back_paginated_message_event_with_id(
*CAROL,
room_id,
event_id!("$event_c"),
RoomMessageEventContent::text_plain("C"),
.handle_back_paginated_custom_event(
f.text_msg("C").sender(*CAROL).event_id(event_id!("$event_c")).into_raw_timeline(),
)
.await;
@@ -579,6 +576,8 @@ async fn test_clear_read_receipts() {
let event_a_id = event_id!("$event_a");
let event_b_id = event_id!("$event_b");
let f = EventFactory::new();
let timeline = TestTimeline::new()
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
@@ -604,9 +603,16 @@ async fn test_clear_read_receipts() {
RoomMessageEventContent::text_plain("B"),
)
.await;
// Old message via back-pagination.
timeline
.handle_back_paginated_message_event_with_id(*BOB, room_id, event_a_id, event_a_content)
.handle_back_paginated_custom_event(
f.event(event_a_content)
.sender(*BOB)
.room(room_id)
.event_id(event_a_id)
.into_raw_timeline(),
)
.await;
let items = timeline.inner.items().await;

View File

@@ -155,10 +155,16 @@ impl EventFactory {
}
}
/// Create a new plain text `m.room.message`.
pub fn text_msg(&self, content: impl Into<String>) -> EventBuilder<RoomMessageEventContent> {
self.event(RoomMessageEventContent::text_plain(content.into()))
}
/// Create a new plain notice `m.room.message`.
pub fn notice(&self, content: impl Into<String>) -> EventBuilder<RoomMessageEventContent> {
self.event(RoomMessageEventContent::notice_plain(content))
}
/// Set the next server timestamp.
///
/// Timestamps will continue to increase by 1 (millisecond) from that value.