Skip to content

Commit

Permalink
tests: get rid of EventBuilder::make_message_event_with_id
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Jul 10, 2024
1 parent 00f0191 commit eec9128
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 70 deletions.
30 changes: 13 additions & 17 deletions crates/matrix-sdk-ui/tests/integration/timeline/replies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use matrix_sdk_ui::timeline::{
Error as TimelineError, EventSendState, RoomExt, TimelineDetails, TimelineItemContent,
};
use ruma::{
assign, event_id,
event_id,
events::{
reaction::RedactedReactionEventContent,
relation::InReplyTo,
Expand Down Expand Up @@ -169,9 +169,10 @@ async fn test_in_reply_to_details() {

#[async_test]
async fn test_transfer_in_reply_to_details_to_re_received_item() {
let f = EventFactory::new();

let room_id = room_id!("!a98sd12bjh:example.org");
let (client, server) = logged_in_client_with_server().await;
let event_builder = EventBuilder::new();
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));

let mut sync_builder = SyncResponseBuilder::new();
Expand All @@ -186,14 +187,7 @@ async fn test_transfer_in_reply_to_details_to_re_received_item() {

// Given a reply to an event that's not itself in the timeline...
let event_id_1 = event_id!("$event1");
let reply_event = event_builder.make_sync_message_event(
&BOB,
assign!(RoomMessageEventContent::text_plain("Reply"), {
relates_to: Some(Relation::Reply {
in_reply_to: InReplyTo::new(event_id_1.to_owned()),
}),
}),
);
let reply_event = f.text_msg("Reply").sender(&BOB).reply_to(event_id_1).into_raw_sync();
sync_builder
.add_joined_room(JoinedRoomBuilder::new(room_id).add_timeline_event(reply_event.clone()));

Expand All @@ -212,14 +206,16 @@ async fn test_transfer_in_reply_to_details_to_re_received_item() {
Mock::given(method("GET"))
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/event/\$event1"))
.and(header("authorization", "Bearer 1234"))
.respond_with(ResponseTemplate::new(200).set_body_json(
event_builder.make_message_event_with_id(
&ALICE,
room_id,
event_id_1,
RoomMessageEventContent::text_plain("Original Message"),
.respond_with(
ResponseTemplate::new(200).set_body_json(
f.text_msg("Original Message")
.sender(&ALICE)
.room(room_id)
.event_id(event_id_1)
.into_raw_timeline()
.json(),
),
))
)
.expect(1)
.mount(&server)
.await;
Expand Down
57 changes: 21 additions & 36 deletions crates/matrix-sdk/tests/integration/event_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ use matrix_sdk::{
test_utils::{assert_event_matches_msg, events::EventFactory, logged_in_client_with_server},
};
use matrix_sdk_test::{
async_test, EventBuilder, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder,
};
use ruma::{
event_id,
events::{room::message::RoomMessageEventContent, AnyTimelineEvent},
room_id,
serde::Raw,
user_id,
async_test, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder,
};
use ruma::{event_id, events::AnyTimelineEvent, room_id, serde::Raw, user_id};
use serde_json::json;
use tokio::{spawn, time::timeout};
use wiremock::{
Expand Down Expand Up @@ -265,12 +259,12 @@ macro_rules! non_sync_events {
@_ $builder,
[ $( $( $rest )* )? ]
[ $( $accumulator )*
$builder.make_message_event_with_id(
user_id!("@a:b.c"),
$room_id,
event_id!($event_id),
RoomMessageEventContent::text_plain($msg)
),
$builder
.text_msg($msg)
.sender(user_id!("@a:b.c"))
.room($room_id)
.event_id(event_id!($event_id))
.into_raw_timeline(),
]
)
};
Expand Down Expand Up @@ -321,18 +315,15 @@ async fn test_backpaginate_once() {
// token,
let room_id = room_id!("!omelette:fromage.fr");

let event_builder = EventBuilder::new();
let f = EventFactory::new();
let mut sync_builder = SyncResponseBuilder::new();

{
sync_builder.add_joined_room(
JoinedRoomBuilder::new(room_id)
// Note to self: a timeline must have at least single event to be properly
// serialized.
.add_timeline_event(event_builder.make_sync_message_event(
user_id!("@a:b.c"),
RoomMessageEventContent::text_plain("heyo"),
))
.add_timeline_event(f.text_msg("heyo").sender(user_id!("@a:b.c")))
.set_timeline_prev_batch("prev_batch".to_owned()),
);
let response_body = sync_builder.build_json_sync_response();
Expand Down Expand Up @@ -363,7 +354,7 @@ async fn test_backpaginate_once() {
&server,
"prev_batch",
None,
non_sync_events!(event_builder, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
non_sync_events!(f, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
)
.await;

Expand Down Expand Up @@ -399,18 +390,15 @@ async fn test_backpaginate_many_times_with_many_iterations() {
// token,
let room_id = room_id!("!omelette:fromage.fr");

let event_builder = EventBuilder::new();
let f = EventFactory::new();
let mut sync_builder = SyncResponseBuilder::new();

{
sync_builder.add_joined_room(
JoinedRoomBuilder::new(room_id)
// Note to self: a timeline must have at least single event to be properly
// serialized.
.add_timeline_event(event_builder.make_sync_message_event(
user_id!("@a:b.c"),
RoomMessageEventContent::text_plain("heyo"),
))
.add_timeline_event(f.text_msg("heyo").sender(user_id!("@a:b.c")))
.set_timeline_prev_batch("prev_batch".to_owned()),
);
let response_body = sync_builder.build_json_sync_response();
Expand Down Expand Up @@ -444,7 +432,7 @@ async fn test_backpaginate_many_times_with_many_iterations() {
&server,
"prev_batch",
Some("prev_batch2"),
non_sync_events!(event_builder, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
non_sync_events!(f, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
)
.await;

Expand All @@ -453,7 +441,7 @@ async fn test_backpaginate_many_times_with_many_iterations() {
&server,
"prev_batch2",
None,
non_sync_events!(event_builder, [ (room_id, "$4": "oh well"), ]),
non_sync_events!(f, [ (room_id, "$4": "oh well"), ]),
)
.await;

Expand Down Expand Up @@ -515,18 +503,15 @@ async fn test_backpaginate_many_times_with_one_iteration() {
// token,
let room_id = room_id!("!omelette:fromage.fr");

let event_builder = EventBuilder::new();
let f = EventFactory::new();
let mut sync_builder = SyncResponseBuilder::new();

{
sync_builder.add_joined_room(
JoinedRoomBuilder::new(room_id)
// Note to self: a timeline must have at least single event to be properly
// serialized.
.add_timeline_event(event_builder.make_sync_message_event(
user_id!("@a:b.c"),
RoomMessageEventContent::text_plain("heyo"),
))
.add_timeline_event(f.text_msg("heyo").sender(user_id!("@a:b.c")))
.set_timeline_prev_batch("prev_batch".to_owned()),
);
let response_body = sync_builder.build_json_sync_response();
Expand Down Expand Up @@ -560,7 +545,7 @@ async fn test_backpaginate_many_times_with_one_iteration() {
&server,
"prev_batch",
Some("prev_batch2"),
non_sync_events!(event_builder, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
non_sync_events!(f, [ (room_id, "$2": "world"), (room_id, "$3": "hello") ]),
)
.await;

Expand All @@ -569,7 +554,7 @@ async fn test_backpaginate_many_times_with_one_iteration() {
&server,
"prev_batch2",
None,
non_sync_events!(event_builder, [ (room_id, "$4": "oh well"), ]),
non_sync_events!(f, [ (room_id, "$4": "oh well"), ]),
)
.await;

Expand Down Expand Up @@ -770,7 +755,7 @@ async fn test_backpaginating_without_token() {
// token,
let room_id = room_id!("!omelette:fromage.fr");

let event_builder = EventBuilder::new();
let f = EventFactory::new();
let mut sync_builder = SyncResponseBuilder::new();

{
Expand All @@ -794,7 +779,7 @@ async fn test_backpaginating_without_token() {
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/messages$"))
.and(header("authorization", "Bearer 1234"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"chunk": non_sync_events!(event_builder, [(room_id, "$2": "hi")]),
"chunk": non_sync_events!(f, [(room_id, "$2": "hi")]),
"start": "t392-516_47314_0_7_1_1_1_11444_1",
})))
.expect(1)
Expand Down
17 changes: 0 additions & 17 deletions testing/matrix-sdk-test/src/event_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@ impl EventBuilder {
self.next_ts.store(value, SeqCst);
}

pub fn make_message_event_with_id<C: MessageLikeEventContent>(
&self,
sender: &UserId,
room_id: &RoomId,
event_id: &EventId,
content: C,
) -> Raw<AnyTimelineEvent> {
timeline_event!({
"type": content.event_type(),
"content": content,
"event_id": event_id,
"sender": sender,
"room_id": room_id,
"origin_server_ts": self.next_server_ts(),
})
}

pub fn make_state_event<C: StateEventContent>(
&self,
sender: &UserId,
Expand Down

0 comments on commit eec9128

Please sign in to comment.