Skip to content

Commit 7bcb1bc

Browse files
committed
refactor(tests): Allow converting EventBuilder to state
1 parent 2090117 commit 7bcb1bc

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,
@@ -382,6 +383,24 @@ where
382383
}
383384
}
384385

386+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
387+
where
388+
E::EventType: Serialize,
389+
{
390+
fn from(val: EventBuilder<E>) -> Self {
391+
Raw::new(&val.construct_json(false)).unwrap().cast()
392+
}
393+
}
394+
395+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
396+
where
397+
E::EventType: Serialize,
398+
{
399+
fn from(val: EventBuilder<E>) -> Self {
400+
Raw::new(&val.construct_json(true)).unwrap().cast()
401+
}
402+
}
403+
385404
#[derive(Debug, Default)]
386405
pub struct EventFactory {
387406
next_ts: AtomicU64,

0 commit comments

Comments
 (0)