Skip to content

Commit 8d5129b

Browse files
committed
refactor(tests): Allow converting EventBuilder to state
1 parent 10305a5 commit 8d5129b

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,
@@ -427,6 +428,24 @@ where
427428
}
428429
}
429430

431+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent>
432+
where
433+
E::EventType: Serialize,
434+
{
435+
fn from(val: EventBuilder<E>) -> Self {
436+
Raw::new(&val.construct_json(false)).unwrap().cast()
437+
}
438+
}
439+
440+
impl<E: StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent>
441+
where
442+
E::EventType: Serialize,
443+
{
444+
fn from(val: EventBuilder<E>) -> Self {
445+
Raw::new(&val.construct_json(true)).unwrap().cast()
446+
}
447+
}
448+
430449
#[derive(Debug, Default)]
431450
pub struct EventFactory {
432451
next_ts: AtomicU64,

0 commit comments

Comments
 (0)