diff --git a/crates/matrix-sdk/src/test_utils/mocks.rs b/crates/matrix-sdk/src/test_utils/mocks.rs index a4bd0bf716f..15ee9080cb4 100644 --- a/crates/matrix-sdk/src/test_utils/mocks.rs +++ b/crates/matrix-sdk/src/test_utils/mocks.rs @@ -97,13 +97,9 @@ impl MatrixMockServer { /// Overrides the sync/ endpoint with knowledge that the given /// invited/joined/knocked/left room exists, runs a sync and returns the /// given room. - pub async fn sync_room( - &self, - client: &Client, - room_id: &RoomId, - room_data: impl Into, - ) -> Room { + pub async fn sync_room(&self, client: &Client, room_data: impl Into) -> Room { let any_room = room_data.into(); + let room_id = any_room.room_id().to_owned(); self.mock_sync() .ok_and_run(client, move |builder| match any_room { @@ -122,13 +118,13 @@ impl MatrixMockServer { }) .await; - client.get_room(room_id).expect("look at me, the room is known now") + client.get_room(&room_id).expect("look at me, the room is known now") } /// Overrides the sync/ endpoint with knowledge that the given room exists /// in the joined state, runs a sync and returns the given room. pub async fn sync_joined_room(&self, client: &Client, room_id: &RoomId) -> Room { - self.sync_room(client, room_id, JoinedRoomBuilder::new(room_id)).await + self.sync_room(client, JoinedRoomBuilder::new(room_id)).await } /// Verify that the previous mocks expected number of requests match @@ -236,6 +232,18 @@ pub enum AnyRoomBuilder { Knocked(KnockedRoomBuilder), } +impl AnyRoomBuilder { + /// Get the [`RoomId`] of the room this [`AnyRoomBuilder`] will create. + fn room_id(&self) -> &RoomId { + match self { + AnyRoomBuilder::Invited(r) => r.room_id(), + AnyRoomBuilder::Joined(r) => r.room_id(), + AnyRoomBuilder::Left(r) => r.room_id(), + AnyRoomBuilder::Knocked(r) => r.room_id(), + } + } +} + impl From for AnyRoomBuilder { fn from(val: InvitedRoomBuilder) -> AnyRoomBuilder { AnyRoomBuilder::Invited(val) diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index 51529c9b122..1a9dce61f7c 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -208,7 +208,7 @@ async fn test_cant_send_invited_room() { // When I'm invited to a room, let room_id = room_id!("!a:b.c"); let client = mock.client_builder().build().await; - let room = mock.sync_room(&client, room_id, InvitedRoomBuilder::new(room_id)).await; + let room = mock.sync_room(&client, InvitedRoomBuilder::new(room_id)).await; // I can't send message to it with the send queue. assert_matches!( @@ -224,7 +224,7 @@ async fn test_cant_send_left_room() { // When I've left a room, let room_id = room_id!("!a:b.c"); let client = mock.client_builder().build().await; - let room = mock.sync_room(&client, room_id, LeftRoomBuilder::new(room_id)).await; + let room = mock.sync_room(&client, LeftRoomBuilder::new(room_id)).await; // I can't send message to it with the send queue. assert_matches!( @@ -242,7 +242,7 @@ async fn test_cant_send_knocked_room() { // When I've knocked into a room, let room_id = room_id!("!a:b.c"); let client = mock.client_builder().build().await; - let room = mock.sync_room(&client, room_id, KnockedRoomBuilder::new(room_id)).await; + let room = mock.sync_room(&client, KnockedRoomBuilder::new(room_id)).await; // I can't send message to it with the send queue. assert_matches!( diff --git a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs index a5a985e7502..7af107446ae 100644 --- a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs @@ -20,6 +20,11 @@ impl InvitedRoomBuilder { Self { room_id: room_id.to_owned(), inner: Default::default() } } + /// Get the room ID of this [`InvitedRoomBuilder`]. + pub fn room_id(&self) -> &RoomId { + &self.room_id + } + /// Add an event to the state. pub fn add_state_event(mut self, event: StrippedStateTestEvent) -> Self { self.inner.invite_state.events.push(event.into_raw_event()); diff --git a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs index bd93c2461df..079bc04cc41 100644 --- a/testing/matrix-sdk-test/src/sync_builder/joined_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/joined_room.rs @@ -25,6 +25,11 @@ impl JoinedRoomBuilder { Self { room_id: room_id.to_owned(), inner: Default::default() } } + /// Get the room ID of this [`JoinedRoomBuilder`]. + pub fn room_id(&self) -> &RoomId { + &self.room_id + } + /// Add an event to the timeline. /// /// The raw event can be created with the diff --git a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs index 0df9a4e73a6..5838298efea 100644 --- a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs @@ -20,6 +20,11 @@ impl KnockedRoomBuilder { Self { room_id: room_id.to_owned(), inner: Default::default() } } + /// Get the room ID of this [`KnockedRoomBuilder`]. + pub fn room_id(&self) -> &RoomId { + &self.room_id + } + /// Add an event to the state. pub fn add_state_event(mut self, event: StrippedStateTestEvent) -> Self { self.inner.knock_state.events.push(event.into_raw_event()); diff --git a/testing/matrix-sdk-test/src/sync_builder/left_room.rs b/testing/matrix-sdk-test/src/sync_builder/left_room.rs index b18ef3df00f..acf271d6682 100644 --- a/testing/matrix-sdk-test/src/sync_builder/left_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/left_room.rs @@ -22,6 +22,11 @@ impl LeftRoomBuilder { Self { room_id: room_id.to_owned(), inner: Default::default() } } + /// Get the room ID of this [`LeftRoomBuilder`]. + pub fn room_id(&self) -> &RoomId { + &self.room_id + } + /// Add an event to the timeline. /// /// The raw event can be created with the