Skip to content

Commit 3410c01

Browse files
committed
refactor(tests): Allow converting EventBuilder to state
1 parent be0e10e commit 3410c01

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
@@ -55,8 +55,9 @@ use ruma::{
5555
topic::RoomTopicEventContent,
5656
},
5757
typing::TypingEventContent,
58-
AnySyncTimelineEvent, AnyTimelineEvent, BundledMessageLikeRelations, EventContent,
59-
RedactedMessageLikeEventContent, RedactedStateEventContent,
58+
AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
59+
BundledMessageLikeRelations, EventContent, RedactedMessageLikeEventContent,
60+
RedactedStateEventContent, StateEventContent,
6061
},
6162
serde::Raw,
6263
server_name, EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri,
@@ -387,6 +388,24 @@ where
387388
}
388389
}
389390

391+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
392+
where
393+
E::EventType: Serialize,
394+
{
395+
fn from(val: EventBuilder<E>) -> Self {
396+
Raw::new(&val.construct_json(false)).unwrap().cast()
397+
}
398+
}
399+
400+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
401+
where
402+
E::EventType: Serialize,
403+
{
404+
fn from(val: EventBuilder<E>) -> Self {
405+
Raw::new(&val.construct_json(true)).unwrap().cast()
406+
}
407+
}
408+
390409
#[derive(Debug, Default)]
391410
pub struct EventFactory {
392411
next_ts: AtomicU64,

0 commit comments

Comments
 (0)