test(spaces): add an EventFactory method to create an m.space_order event

This commit is contained in:
Benjamin Bouvier
2026-02-16 17:09:03 +01:00
parent ea0a81989a
commit 961edaf4b9
3 changed files with 12 additions and 10 deletions
+2 -8
View File
@@ -687,8 +687,7 @@ mod tests {
use futures_util::{StreamExt, pin_mut};
use matrix_sdk::{room::ParentSpace, test_utils::mocks::MatrixMockServer};
use matrix_sdk_test::{
JoinedRoomBuilder, LeftRoomBuilder, RoomAccountDataTestEvent, async_test,
event_factory::EventFactory,
JoinedRoomBuilder, LeftRoomBuilder, async_test, event_factory::EventFactory,
};
use ruma::{
MilliSecondsSinceUnixEpoch, RoomVersionId, UserId, event_id, owned_room_id, room_id,
@@ -1707,12 +1706,7 @@ mod tests {
.add_state_event(factory.create(user_id, RoomVersionId::V1).with_space_type());
if let Some(order) = parameters.order {
builder = builder.add_account_data(RoomAccountDataTestEvent::Custom(json!({
"type": "m.space_order",
"content": {
"order": order
}
})));
builder = builder.add_account_data(factory.space_order(order));
}
for parent_id in parameters.parents {
@@ -89,6 +89,7 @@ use ruma::{
notification::{NotificationType, RtcNotificationEventContent},
},
space::{child::SpaceChildEventContent, parent::SpaceParentEventContent},
space_order::SpaceOrderEventContent,
sticker::StickerEventContent,
tag::TagEventContent,
typing::TypingEventContent,
@@ -1515,6 +1516,13 @@ impl EventFactory {
self.room_account_data(content)
}
/// Create a new `m.space_order` room account data event with the given
/// order.
pub fn space_order(&self, order: &str) -> EventBuilder<SpaceOrderEventContent> {
let order = ruma::SpaceChildOrder::parse(order).expect("order should be valid");
self.room_account_data(SpaceOrderEventContent::new(order))
}
/// Create a new `m.presence` event.
///
/// This is a special event type that has its own structure different from
@@ -5,7 +5,7 @@ use ruma::{
serde::Raw,
};
use super::{RoomAccountDataTestEvent, StateMutExt};
use super::StateMutExt;
use crate::DEFAULT_TEST_ROOM_ID;
pub struct LeftRoomBuilder {
@@ -79,7 +79,7 @@ impl LeftRoomBuilder {
}
/// Add room account data.
pub fn add_account_data(mut self, event: RoomAccountDataTestEvent) -> Self {
pub fn add_account_data(mut self, event: impl Into<Raw<AnyRoomAccountDataEvent>>) -> Self {
self.inner.account_data.events.push(event.into());
self
}