Skip to content

Commit 24548a2

Browse files
committed
chore(test): Don't require two room IDs in the mock_sync_room method
1 parent b9942fd commit 24548a2

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

crates/matrix-sdk/src/test_utils/mocks.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ impl MatrixMockServer {
9797
/// Overrides the sync/ endpoint with knowledge that the given
9898
/// invited/joined/knocked/left room exists, runs a sync and returns the
9999
/// given room.
100-
pub async fn sync_room(
101-
&self,
102-
client: &Client,
103-
room_id: &RoomId,
104-
room_data: impl Into<AnyRoomBuilder>,
105-
) -> Room {
100+
pub async fn sync_room(&self, client: &Client, room_data: impl Into<AnyRoomBuilder>) -> Room {
106101
let any_room = room_data.into();
102+
let room_id = any_room.room_id().to_owned();
107103

108104
self.mock_sync()
109105
.ok_and_run(client, move |builder| match any_room {
@@ -122,13 +118,13 @@ impl MatrixMockServer {
122118
})
123119
.await;
124120

125-
client.get_room(room_id).expect("look at me, the room is known now")
121+
client.get_room(&room_id).expect("look at me, the room is known now")
126122
}
127123

128124
/// Overrides the sync/ endpoint with knowledge that the given room exists
129125
/// in the joined state, runs a sync and returns the given room.
130126
pub async fn sync_joined_room(&self, client: &Client, room_id: &RoomId) -> Room {
131-
self.sync_room(client, room_id, JoinedRoomBuilder::new(room_id)).await
127+
self.sync_room(client, JoinedRoomBuilder::new(room_id)).await
132128
}
133129

134130
/// Verify that the previous mocks expected number of requests match
@@ -236,6 +232,18 @@ pub enum AnyRoomBuilder {
236232
Knocked(KnockedRoomBuilder),
237233
}
238234

235+
impl AnyRoomBuilder {
236+
/// Get the [`RoomId`] of the room this [`AnyRoomBuilder`] will create.
237+
fn room_id(&self) -> &RoomId {
238+
match self {
239+
AnyRoomBuilder::Invited(r) => r.room_id(),
240+
AnyRoomBuilder::Joined(r) => r.room_id(),
241+
AnyRoomBuilder::Left(r) => r.room_id(),
242+
AnyRoomBuilder::Knocked(r) => r.room_id(),
243+
}
244+
}
245+
}
246+
239247
impl From<InvitedRoomBuilder> for AnyRoomBuilder {
240248
fn from(val: InvitedRoomBuilder) -> AnyRoomBuilder {
241249
AnyRoomBuilder::Invited(val)

crates/matrix-sdk/tests/integration/send_queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async fn test_cant_send_invited_room() {
208208
// When I'm invited to a room,
209209
let room_id = room_id!("!a:b.c");
210210
let client = mock.client_builder().build().await;
211-
let room = mock.sync_room(&client, room_id, InvitedRoomBuilder::new(room_id)).await;
211+
let room = mock.sync_room(&client, InvitedRoomBuilder::new(room_id)).await;
212212

213213
// I can't send message to it with the send queue.
214214
assert_matches!(
@@ -224,7 +224,7 @@ async fn test_cant_send_left_room() {
224224
// When I've left a room,
225225
let room_id = room_id!("!a:b.c");
226226
let client = mock.client_builder().build().await;
227-
let room = mock.sync_room(&client, room_id, LeftRoomBuilder::new(room_id)).await;
227+
let room = mock.sync_room(&client, LeftRoomBuilder::new(room_id)).await;
228228

229229
// I can't send message to it with the send queue.
230230
assert_matches!(
@@ -242,7 +242,7 @@ async fn test_cant_send_knocked_room() {
242242
// When I've knocked into a room,
243243
let room_id = room_id!("!a:b.c");
244244
let client = mock.client_builder().build().await;
245-
let room = mock.sync_room(&client, room_id, KnockedRoomBuilder::new(room_id)).await;
245+
let room = mock.sync_room(&client, KnockedRoomBuilder::new(room_id)).await;
246246

247247
// I can't send message to it with the send queue.
248248
assert_matches!(

testing/matrix-sdk-test/src/sync_builder/invited_room.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ impl InvitedRoomBuilder {
2020
Self { room_id: room_id.to_owned(), inner: Default::default() }
2121
}
2222

23+
/// Get the room ID of this [`InvitedRoomBuilder`].
24+
pub fn room_id(&self) -> &RoomId {
25+
&self.room_id
26+
}
27+
2328
/// Add an event to the state.
2429
pub fn add_state_event(mut self, event: StrippedStateTestEvent) -> Self {
2530
self.inner.invite_state.events.push(event.into_raw_event());

testing/matrix-sdk-test/src/sync_builder/joined_room.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ impl JoinedRoomBuilder {
2525
Self { room_id: room_id.to_owned(), inner: Default::default() }
2626
}
2727

28+
/// Get the room ID of this [`JoinedRoomBuilder`].
29+
pub fn room_id(&self) -> &RoomId {
30+
&self.room_id
31+
}
32+
2833
/// Add an event to the timeline.
2934
///
3035
/// The raw event can be created with the

testing/matrix-sdk-test/src/sync_builder/knocked_room.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ impl KnockedRoomBuilder {
2020
Self { room_id: room_id.to_owned(), inner: Default::default() }
2121
}
2222

23+
/// Get the room ID of this [`KnockedRoomBuilder`].
24+
pub fn room_id(&self) -> &RoomId {
25+
&self.room_id
26+
}
27+
2328
/// Add an event to the state.
2429
pub fn add_state_event(mut self, event: StrippedStateTestEvent) -> Self {
2530
self.inner.knock_state.events.push(event.into_raw_event());

testing/matrix-sdk-test/src/sync_builder/left_room.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ impl LeftRoomBuilder {
2222
Self { room_id: room_id.to_owned(), inner: Default::default() }
2323
}
2424

25+
/// Get the room ID of this [`LeftRoomBuilder`].
26+
pub fn room_id(&self) -> &RoomId {
27+
&self.room_id
28+
}
29+
2530
/// Add an event to the timeline.
2631
///
2732
/// The raw event can be created with the

0 commit comments

Comments
 (0)