Struct matrix_sdk_test::EventBuilder[][src]

pub struct EventBuilder { /* fields omitted */ }
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, EventsJson};

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_room_event(EventsJson::Member)
    .add_room_event(EventsJson::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_room_event(EventsJson::MemberNameChange)
    .build_sync_response();

Implementations

Add an event to the room events Vec.

Add an event to the room events Vec.

Add an event to the room events Vec.

Add a state event to the state events Vec.

Add an presence event to the presence events Vec.

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.

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.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.