Skip to content

Commit 2a02b21

Browse files
committed
refactor(tests): Allow converting EventBuilder to state
1 parent a804c3d commit 2a02b21

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

testing/matrix-sdk-test/src/event_factory.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ use ruma::{
5151
topic::RoomTopicEventContent,
5252
},
5353
typing::TypingEventContent,
54-
AnySyncTimelineEvent, AnyTimelineEvent, BundledMessageLikeRelations, EventContent,
55-
RedactedMessageLikeEventContent, RedactedStateEventContent,
54+
AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
55+
BundledMessageLikeRelations, EventContent, RedactedMessageLikeEventContent,
56+
RedactedStateEventContent, StateEventContent,
5657
},
5758
serde::Raw,
5859
server_name, EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri,
@@ -263,6 +264,14 @@ where
263264
Raw::new(&self.construct_json(false)).unwrap().cast()
264265
}
265266

267+
pub fn into_raw_state(self) -> Raw<AnyStateEvent> {
268+
Raw::new(&self.construct_json(true)).unwrap().cast()
269+
}
270+
271+
pub fn into_raw_sync_state(self) -> Raw<AnySyncStateEvent> {
272+
Raw::new(&self.construct_json(false)).unwrap().cast()
273+
}
274+
266275
pub fn into_event(self) -> TimelineEvent {
267276
TimelineEvent::new(self.into_raw_sync())
268277
}
@@ -372,6 +381,24 @@ where
372381
}
373382
}
374383

384+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
385+
where
386+
E::EventType: Serialize,
387+
{
388+
fn from(val: EventBuilder<E>) -> Self {
389+
val.into_raw_sync_state()
390+
}
391+
}
392+
393+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
394+
where
395+
E::EventType: Serialize,
396+
{
397+
fn from(val: EventBuilder<E>) -> Self {
398+
val.into_raw_state()
399+
}
400+
}
401+
375402
#[derive(Debug, Default)]
376403
pub struct EventFactory {
377404
next_ts: AtomicU64,

0 commit comments

Comments
 (0)