Skip to content

Commit 2c8e71e

Browse files
robintownpoljar
authored andcommitted
refactor(tests): Allow converting EventBuilder to state
1 parent 6f683d3 commit 2c8e71e

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
@@ -57,8 +57,9 @@ use ruma::{
5757
topic::RoomTopicEventContent,
5858
},
5959
typing::TypingEventContent,
60-
AnySyncTimelineEvent, AnyTimelineEvent, BundledMessageLikeRelations, EventContent,
61-
RedactedMessageLikeEventContent, RedactedStateEventContent,
60+
AnyStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
61+
BundledMessageLikeRelations, EventContent, RedactedMessageLikeEventContent,
62+
RedactedStateEventContent, StateEventContent,
6263
},
6364
serde::Raw,
6465
server_name, EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri,
@@ -441,6 +442,24 @@ where
441442
}
442443
}
443444

445+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
446+
where
447+
E::EventType: Serialize,
448+
{
449+
fn from(val: EventBuilder<E>) -> Self {
450+
Raw::new(&val.construct_json(false)).unwrap().cast()
451+
}
452+
}
453+
454+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
455+
where
456+
E::EventType: Serialize,
457+
{
458+
fn from(val: EventBuilder<E>) -> Self {
459+
Raw::new(&val.construct_json(true)).unwrap().cast()
460+
}
461+
}
462+
444463
#[derive(Debug, Default)]
445464
pub struct EventFactory {
446465
next_ts: AtomicU64,

0 commit comments

Comments
 (0)