From 759eeeb27f065bca81184e6950ba93762bbc55be Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 4 Aug 2025 15:10:35 +0300 Subject: [PATCH] feat(test): add event factory methods for creating space rooms and populating parent-children relationships. --- testing/matrix-sdk-test/src/event_factory.rs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/testing/matrix-sdk-test/src/event_factory.rs b/testing/matrix-sdk-test/src/event_factory.rs index 5a63c829b..e8c677653 100644 --- a/testing/matrix-sdk-test/src/event_factory.rs +++ b/testing/matrix-sdk-test/src/event_factory.rs @@ -72,10 +72,12 @@ use ruma::{ tombstone::RoomTombstoneEventContent, topic::RoomTopicEventContent, }, + space::{child::SpaceChildEventContent, parent::SpaceParentEventContent}, sticker::StickerEventContent, typing::TypingEventContent, }, push::Ruleset, + room::RoomType, room_version_rules::AuthorizationRules, serde::Raw, server_name, @@ -462,6 +464,12 @@ impl EventBuilder { self.content.predecessor = None; self } + + /// Sets the `m.room.create` `type` field to `m.space`. + pub fn with_space_type(mut self) -> Self { + self.content.room_type = Some(RoomType::Space); + self + } } impl EventBuilder { @@ -1024,6 +1032,30 @@ impl EventFactory { builder } + /// Create a new `m.space.child` state event. + pub fn space_child( + &self, + parent: OwnedRoomId, + child: OwnedRoomId, + ) -> EventBuilder { + let mut event = self.event(SpaceChildEventContent::new(vec![])); + event.room = Some(parent); + event.state_key = Some(child.to_string()); + event + } + + /// Create a new `m.space.parent` state event. + pub fn space_parent( + &self, + parent: OwnedRoomId, + child: OwnedRoomId, + ) -> EventBuilder { + let mut event = self.event(SpaceParentEventContent::new(vec![])); + event.state_key = Some(parent.to_string()); + event.room = Some(child); + event + } + /// Set the next server timestamp. /// /// Timestamps will continue to increase by 1 (millisecond) from that value.