testing: Generalize add_timeline_event for sync response room builders
This commit is contained in:
committed by
Jonas Platte
parent
c8a4bc799b
commit
054d26774c
@@ -8,7 +8,7 @@ use ruma::{
|
||||
};
|
||||
use serde_json::{from_value as from_json_value, Value as JsonValue};
|
||||
|
||||
use super::{EphemeralTestEvent, RoomAccountDataTestEvent, StateTestEvent, TimelineTestEvent};
|
||||
use super::{EphemeralTestEvent, RoomAccountDataTestEvent, StateTestEvent};
|
||||
use crate::test_json;
|
||||
|
||||
pub struct JoinedRoomBuilder {
|
||||
@@ -26,8 +26,13 @@ impl JoinedRoomBuilder {
|
||||
}
|
||||
|
||||
/// Add an event to the timeline.
|
||||
pub fn add_timeline_event(mut self, event: TimelineTestEvent) -> Self {
|
||||
self.inner.timeline.events.push(event.into_raw_event());
|
||||
///
|
||||
/// [`TimelineTestEvent`][super::TimelineTestEvent] can be passed because it
|
||||
/// implements `Into<Raw<AynSyncTimelineEvent>`. The raw event can also be
|
||||
/// created with the [`sync_timeline_event`](crate::sync_timeline_event)
|
||||
/// macro.
|
||||
pub fn add_timeline_event(mut self, event: impl Into<Raw<AnySyncTimelineEvent>>) -> Self {
|
||||
self.inner.timeline.events.push(event.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use ruma::{
|
||||
OwnedRoomId,
|
||||
};
|
||||
|
||||
use super::{RoomAccountDataTestEvent, StateTestEvent, TimelineTestEvent};
|
||||
use super::{RoomAccountDataTestEvent, StateTestEvent};
|
||||
use crate::test_json;
|
||||
|
||||
pub struct LeftRoomBuilder {
|
||||
@@ -23,8 +23,13 @@ impl LeftRoomBuilder {
|
||||
}
|
||||
|
||||
/// Add an event to the timeline.
|
||||
pub fn add_timeline_event(mut self, event: TimelineTestEvent) -> Self {
|
||||
self.inner.timeline.events.push(event.into_raw_event());
|
||||
///
|
||||
/// [`TimelineTestEvent`][super::TimelineTestEvent] can be passed because it
|
||||
/// implements `Into<Raw<AynSyncTimelineEvent>`. The raw event can also be
|
||||
/// created with the [`sync_timeline_event`](crate::sync_timeline_event)
|
||||
/// macro.
|
||||
pub fn add_timeline_event(mut self, event: impl Into<Raw<AnySyncTimelineEvent>>) -> Self {
|
||||
self.inner.timeline.events.push(event.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -67,10 +67,12 @@ impl TimelineTestEvent {
|
||||
Self::Custom(json) => json,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TimelineTestEvent> for Raw<AnySyncTimelineEvent> {
|
||||
/// Get the typed JSON representation of this test event.
|
||||
pub fn into_raw_event(self) -> Raw<AnySyncTimelineEvent> {
|
||||
from_json_value(self.into_json_value()).unwrap()
|
||||
fn from(value: TimelineTestEvent) -> Self {
|
||||
from_json_value(value.into_json_value()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user