Struct matrix_sdk_test::EventBuilder
source · [−]pub struct EventBuilder { /* private fields */ }
Expand description
The EventBuilder
struct can be used to easily generate valid sync
responses for testing. These can be then fed into either Client
or Room
.
It supports generated a number of canned events, such as a member entering a
room, his power level and display name changing and similar. It also
supports insertion of custom events in the form of EventsJson
values.
Important You must use the same builder when sending multiple sync
responses to a single client. Otherwise, the subsequent responses will be
ignored by the client because the next_batch
sync token will not be
rotated properly.
Example usage
use matrix_sdk_test::{EventBuilder, JoinedRoomBuilder, TimelineTestEvent};
let mut builder = EventBuilder::new();
// response1 now contains events that add an example member to the room and change their power
// level
let response1 = builder
.add_joined_room(
JoinedRoomBuilder::default()
.add_timeline_event(TimelineTestEvent::Member)
.add_timeline_event(TimelineTestEvent::PowerLevels)
)
.build_sync_response();
// response2 is now empty (nothing changed)
let response2 = builder.build_sync_response();
// response3 contains a display name change for member example
let response3 = builder
.add_joined_room(
JoinedRoomBuilder::default()
.add_timeline_event(TimelineTestEvent::MemberNameChange)
.add_timeline_event(TimelineTestEvent::PowerLevels)
)
.build_sync_response();
Implementations
sourceimpl EventBuilder
impl EventBuilder
pub fn new() -> Self
sourcepub fn add_joined_room(&mut self, room: JoinedRoomBuilder) -> &mut Self
pub fn add_joined_room(&mut self, room: JoinedRoomBuilder) -> &mut Self
Add a joined room to the next sync response.
If a room with the same room ID already exists, it is replaced by this one.
sourcepub fn add_invited_room(&mut self, room: InvitedRoomBuilder) -> &mut Self
pub fn add_invited_room(&mut self, room: InvitedRoomBuilder) -> &mut Self
Add an invited room to the next sync response.
If a room with the same room ID already exists, it is replaced by this one.
sourcepub fn add_left_room(&mut self, room: LeftRoomBuilder) -> &mut Self
pub fn add_left_room(&mut self, room: LeftRoomBuilder) -> &mut Self
Add a left room to the next sync response.
If a room with the same room ID already exists, it is replaced by this one.
sourcepub fn add_presence_event(&mut self, event: PresenceTestEvent) -> &mut Self
pub fn add_presence_event(&mut self, event: PresenceTestEvent) -> &mut Self
Add a presence event.
sourcepub fn add_presence_bulk<I>(&mut self, events: I) -> &mut Selfwhere
I: IntoIterator<Item = Raw<PresenceEvent>>,
pub fn add_presence_bulk<I>(&mut self, events: I) -> &mut Selfwhere
I: IntoIterator<Item = Raw<PresenceEvent>>,
Add presence in bulk.
sourcepub fn add_global_account_data_event(
&mut self,
event: GlobalAccountDataTestEvent
) -> &mut Self
pub fn add_global_account_data_event(
&mut self,
event: GlobalAccountDataTestEvent
) -> &mut Self
Add global account data.
sourcepub fn add_global_account_data_bulk<I>(&mut self, events: I) -> &mut Selfwhere
I: IntoIterator<Item = Raw<AnyGlobalAccountDataEvent>>,
pub fn add_global_account_data_bulk<I>(&mut self, events: I) -> &mut Selfwhere
I: IntoIterator<Item = Raw<AnyGlobalAccountDataEvent>>,
Add global account data in bulk.
sourcepub fn build_json_sync_response(&mut self) -> JsonValue
pub fn build_json_sync_response(&mut self) -> JsonValue
Builds a sync response as a JSON Value containing the events we queued so far.
The next response returned by build_sync_response
will then be empty
if no further events were queued.
This method is raw JSON equivalent to build_sync_response(), use build_sync_response() if you need a typed response.
sourcepub fn build_sync_response(&mut self) -> SyncResponse
pub fn build_sync_response(&mut self) -> SyncResponse
Builds a SyncResponse
containing the events we queued so far.
The next response returned by build_sync_response
will then be empty
if no further events were queued.
This method is high level and typed equivalent to build_json_sync_response(), use build_json_sync_response() if you need an untyped response.