diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index d82d10d56..30c176389 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -3010,8 +3010,8 @@ pub(crate) mod tests { RoomState, }; use matrix_sdk_test::{ - async_test, event_factory::EventFactory, GlobalAccountDataTestEvent, JoinedRoomBuilder, - StateTestEvent, SyncResponseBuilder, DEFAULT_TEST_ROOM_ID, + async_test, event_factory::EventFactory, JoinedRoomBuilder, StateTestEvent, + SyncResponseBuilder, DEFAULT_TEST_ROOM_ID, }; #[cfg(target_family = "wasm")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); @@ -3763,13 +3763,13 @@ pub(crate) mod tests { server .mock_sync() .ok_and_run(&client, |builder| { - builder.add_global_account_data_event(GlobalAccountDataTestEvent::Custom(json!({ + builder.add_custom_global_account_data(json!({ "content": { "media_previews": "private", "invite_avatars": "off" }, "type": "m.media_preview_config" - }))); + })); }) .await; @@ -3785,13 +3785,13 @@ pub(crate) mod tests { server .mock_sync() .ok_and_run(&client, |builder| { - builder.add_global_account_data_event(GlobalAccountDataTestEvent::Custom(json!({ + builder.add_custom_global_account_data(json!({ "content": { "media_previews": "off", "invite_avatars": "on" }, "type": "m.media_preview_config" - }))); + })); }) .await; @@ -3814,13 +3814,13 @@ pub(crate) mod tests { server .mock_sync() .ok_and_run(&client, |builder| { - builder.add_global_account_data_event(GlobalAccountDataTestEvent::Custom(json!({ + builder.add_custom_global_account_data(json!({ "content": { "media_previews": "private", "invite_avatars": "off" }, "type": "io.element.msc4278.media_preview_config" - }))); + })); }) .await; @@ -3836,13 +3836,13 @@ pub(crate) mod tests { server .mock_sync() .ok_and_run(&client, |builder| { - builder.add_global_account_data_event(GlobalAccountDataTestEvent::Custom(json!({ + builder.add_custom_global_account_data(json!({ "content": { "media_previews": "off", "invite_avatars": "on" }, "type": "io.element.msc4278.media_preview_config" - }))); + })); }) .await; diff --git a/crates/matrix-sdk/src/event_handler/mod.rs b/crates/matrix-sdk/src/event_handler/mod.rs index bfe2c62b2..99ad61bbe 100644 --- a/crates/matrix-sdk/src/event_handler/mod.rs +++ b/crates/matrix-sdk/src/event_handler/mod.rs @@ -1351,7 +1351,7 @@ mod tests { let mut response_builder = SyncResponseBuilder::new(); let response = response_builder - .add_global_account_data_bulk([Raw::new(&json!({ + .add_custom_global_account_data(json!({ "content": { "algorithm": "m.secret_storage.v1.aes-hmac-sha2", "iv": "gH2iNpiETFhApvW6/FFEJQ", @@ -1364,8 +1364,6 @@ mod tests { }, "type": "m.secret_storage.key.foobar", })) - .unwrap() - .cast_unchecked()]) .build_sync_response(); client.process_sync(response).await?; diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 0e35a47e7..083ba5a55 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -41,7 +41,7 @@ use ruma::{ int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId, RoomVersionId, TransactionId, }; -use serde_json::{from_value, json}; +use serde_json::json; use stream_assert::assert_pending; use tokio::time::sleep; use wiremock::{ diff --git a/testing/matrix-sdk-test/src/lib.rs b/testing/matrix-sdk-test/src/lib.rs index 78ad1ee32..25c2d7244 100644 --- a/testing/matrix-sdk-test/src/lib.rs +++ b/testing/matrix-sdk-test/src/lib.rs @@ -81,9 +81,9 @@ mod sync_builder; pub mod test_json; pub use self::sync_builder::{ - GlobalAccountDataTestEvent, InvitedRoomBuilder, JoinedRoomBuilder, KnockedRoomBuilder, - LeftRoomBuilder, PresenceTestEvent, RoomAccountDataTestEvent, StateTestEvent, - StrippedStateTestEvent, SyncResponseBuilder, bulk_room_members, + InvitedRoomBuilder, JoinedRoomBuilder, KnockedRoomBuilder, LeftRoomBuilder, PresenceTestEvent, + RoomAccountDataTestEvent, StateTestEvent, StrippedStateTestEvent, SyncResponseBuilder, + bulk_room_members, }; pub static ALICE: Lazy<&UserId> = Lazy::new(|| user_id!("@alice:server.name")); diff --git a/testing/matrix-sdk-test/src/sync_builder/mod.rs b/testing/matrix-sdk-test/src/sync_builder/mod.rs index 389123a50..dcdc33dbd 100644 --- a/testing/matrix-sdk-test/src/sync_builder/mod.rs +++ b/testing/matrix-sdk-test/src/sync_builder/mod.rs @@ -31,8 +31,7 @@ pub use joined_room::JoinedRoomBuilder; pub use knocked_room::KnockedRoomBuilder; pub use left_room::LeftRoomBuilder; pub use test_event::{ - GlobalAccountDataTestEvent, PresenceTestEvent, RoomAccountDataTestEvent, StateTestEvent, - StrippedStateTestEvent, + PresenceTestEvent, RoomAccountDataTestEvent, StateTestEvent, StrippedStateTestEvent, }; /// The `SyncResponseBuilder` struct can be used to easily generate valid sync @@ -145,25 +144,9 @@ impl SyncResponseBuilder { self } - /// Add global account data. - pub fn add_global_account_data_event( - &mut self, - event: GlobalAccountDataTestEvent, - ) -> &mut Self { - let val = match event { - GlobalAccountDataTestEvent::Custom(json) => json, - }; - - self.account_data.push(from_json_value(val).unwrap()); - self - } - - /// Add global account data in bulk. - pub fn add_global_account_data_bulk(&mut self, events: I) -> &mut Self - where - I: IntoIterator>, - { - self.account_data.extend(events); + /// Add custom global account data based on a JSON value. + pub fn add_custom_global_account_data(&mut self, event: serde_json::Value) -> &mut Self { + self.account_data.push(Raw::new(&event).unwrap().cast_unchecked()); self } diff --git a/testing/matrix-sdk-test/src/sync_builder/test_event.rs b/testing/matrix-sdk-test/src/sync_builder/test_event.rs index e3403d9bc..7bb508a88 100644 --- a/testing/matrix-sdk-test/src/sync_builder/test_event.rs +++ b/testing/matrix-sdk-test/src/sync_builder/test_event.rs @@ -1,7 +1,6 @@ use ruma::{ events::{ - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, - AnySyncStateEvent, presence::PresenceEvent, + AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, presence::PresenceEvent, }, serde::Raw, }; @@ -146,22 +145,3 @@ impl From for Raw { from_json_value(val.into()).unwrap() } } - -/// Test events that can be added to the global account data. -pub enum GlobalAccountDataTestEvent { - Custom(JsonValue), -} - -impl From for JsonValue { - fn from(val: GlobalAccountDataTestEvent) -> Self { - match val { - GlobalAccountDataTestEvent::Custom(json) => json, - } - } -} - -impl From for Raw { - fn from(val: GlobalAccountDataTestEvent) -> Self { - from_json_value(val.into()).unwrap() - } -}