Skip to content

Commit bd9dc68

Browse files
committed
refactor(tests): Allow converting EventBuilder to state
1 parent 4a51613 commit bd9dc68

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

Lines changed: 21 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,
@@ -372,6 +373,24 @@ where
372373
}
373374
}
374375

376+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
377+
where
378+
E::EventType: Serialize,
379+
{
380+
fn from(val: EventBuilder<E>) -> Self {
381+
Raw::new(&val.construct_json(false)).unwrap().cast()
382+
}
383+
}
384+
385+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
386+
where
387+
E::EventType: Serialize,
388+
{
389+
fn from(val: EventBuilder<E>) -> Self {
390+
Raw::new(&val.construct_json(true)).unwrap().cast()
391+
}
392+
}
393+
375394
#[derive(Debug, Default)]
376395
pub struct EventFactory {
377396
next_ts: AtomicU64,

0 commit comments

Comments
 (0)