pub struct MockEndpoint<'a, T> { /* private fields */ }
testing
and non-target_family="wasm"
only.Expand description
Generic mocked endpoint, with useful common helpers.
Implementations§
Source§impl<'a> MockEndpoint<'a, ServerMetadataEndpoint>
impl<'a> MockEndpoint<'a, ServerMetadataEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful metadata response with all the supported endpoints.
Sourcepub fn ok_https(self) -> MatrixMock<'a>
pub fn ok_https(self) -> MatrixMock<'a>
Returns a successful metadata response with all the supported endpoints using HTTPS URLs.
This should be used with
MockClientBuilder::insecure_rewrite_https_to_http()
to bypass checks
from the oauth2 crate.
Returns a successful metadata response without the device authorization endpoint.
Sourcepub fn ok_without_registration(self) -> MatrixMock<'a>
pub fn ok_without_registration(self) -> MatrixMock<'a>
Returns a successful metadata response without the registration endpoint.
Source§impl<'a> MockEndpoint<'a, RegistrationEndpoint>
impl<'a> MockEndpoint<'a, RegistrationEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful registration response.
Source§impl<'a> MockEndpoint<'a, DeviceAuthorizationEndpoint>
impl<'a> MockEndpoint<'a, DeviceAuthorizationEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful device authorization response.
Source§impl<'a> MockEndpoint<'a, TokenEndpoint>
impl<'a> MockEndpoint<'a, TokenEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful token response with the default tokens.
Sourcepub fn ok_with_tokens(
self,
access_token: &str,
refresh_token: &str,
) -> MatrixMock<'a>
pub fn ok_with_tokens( self, access_token: &str, refresh_token: &str, ) -> MatrixMock<'a>
Returns a successful token response with custom tokens.
Sourcepub fn access_denied(self) -> MatrixMock<'a>
pub fn access_denied(self) -> MatrixMock<'a>
Returns an error response when the request was invalid.
Sourcepub fn expired_token(self) -> MatrixMock<'a>
pub fn expired_token(self) -> MatrixMock<'a>
Returns an error response when the token in the request has expired.
Sourcepub fn invalid_grant(self) -> MatrixMock<'a>
pub fn invalid_grant(self) -> MatrixMock<'a>
Returns an error response when the token in the request is invalid.
Source§impl<'a> MockEndpoint<'a, RevocationEndpoint>
impl<'a> MockEndpoint<'a, RevocationEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful revocation response.
Source§impl<'a, T> MockEndpoint<'a, T>
impl<'a, T> MockEndpoint<'a, T>
Sourcepub fn expect_default_access_token(self) -> Self
pub fn expect_default_access_token(self) -> Self
Expect authentication with the default access token on this endpoint.
Sourcepub fn expect_access_token(self, access_token: &'static str) -> Self
pub fn expect_access_token(self, access_token: &'static str) -> Self
Expect authentication with the given access token on this endpoint.
Sourcepub fn do_not_expect_access_token(self) -> Self
pub fn do_not_expect_access_token(self) -> Self
Don’t expect authentication with an access token on this endpoint.
This should be used to override the default behavior of the endpoint, when the access token is unknown for example.
Sourcepub fn respond_with<R: Respond + 'static>(self, func: R) -> MatrixMock<'a>
pub fn respond_with<R: Respond + 'static>(self, func: R) -> MatrixMock<'a>
Specify how to respond to a query (viz., like
MockBuilder::respond_with
does), when other predefined responses
aren’t sufficient.
§Examples
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
use wiremock::ResponseTemplate;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send()
.respond_with(
ResponseTemplate::new(429)
.insert_header("Retry-After", "100")
.set_body_json(json!({
"errcode": "M_LIMIT_EXCEEDED",
"custom_field": "with custom data",
})))
.expect(1)
.mount()
.await;
room
.send_raw("m.room.message", json!({ "body": "Hello world" }))
.await
.expect_err("The sending of the event should fail");
Sourcepub fn error500(self) -> MatrixMock<'a>
pub fn error500(self) -> MatrixMock<'a>
Returns a send endpoint that emulates a transient failure, i.e responds with error 500.
§Examples
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
mock_server
.mock_room_send()
.error500()
.expect(1)
.mount()
.await;
room
.send_raw("m.room.message", json!({ "body": "Hello world" }))
.await.expect_err("The sending of the event should have failed");
Sourcepub fn error_too_large(self) -> MatrixMock<'a>
pub fn error_too_large(self) -> MatrixMock<'a>
Returns an endpoint that emulates a permanent failure error (e.g. event is too large).
§Examples
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
mock_server
.mock_room_send()
.error_too_large()
.expect(1)
.mount()
.await;
room
.send_raw("m.room.message", json!({ "body": "Hello world" }))
.await.expect_err("The sending of the event should have failed");
Source§impl<'a> MockEndpoint<'a, RoomSendEndpoint>
impl<'a> MockEndpoint<'a, RoomSendEndpoint>
Sourcepub fn body_matches_partial_json(self, body: Value) -> Self
pub fn body_matches_partial_json(self, body: Value) -> Self
Ensures that the body of the request is a superset of the provided
body
parameter.
§Examples
use matrix_sdk::{
ruma::{room_id, event_id, events::room::message::RoomMessageEventContent},
test_utils::mocks::MatrixMockServer
};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send()
.body_matches_partial_json(json!({
"body": "Hello world",
}))
.ok(event_id)
.expect(1)
.mount()
.await;
let content = RoomMessageEventContent::text_plain("Hello world");
let response = room.send(content).await?;
assert_eq!(
event_id,
response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn for_type(self, event_type: MessageLikeEventType) -> Self
pub fn for_type(self, event_type: MessageLikeEventType) -> Self
Ensures that the send endpoint request uses a specific event type.
§Examples
see also MatrixMockServer::mock_room_send
for more context.
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send()
.for_type("m.room.message".into())
.ok(event_id)
.expect(1)
.mount()
.await;
let response_not_mocked = room.send_raw("m.room.reaction", json!({ "body": "Hello world" })).await;
// The `m.room.reaction` event type should not be mocked by the server.
assert!(response_not_mocked.is_err());
let response = room.send_raw("m.room.message", json!({ "body": "Hello world" })).await?;
// The `m.room.message` event type should be mocked by the server.
assert_eq!(
event_id,
response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn match_delayed_event(self, delay: Duration) -> Self
pub fn match_delayed_event(self, delay: Duration) -> Self
Ensures the event was sent as a delayed event.
See also the MSC.
Note: works with any room.
§Examples
see also MatrixMockServer::mock_room_send
for more context.
use matrix_sdk::{
ruma::{
api::client::delayed_events::{delayed_message_event, DelayParameters},
events::{message::MessageEventContent, AnyMessageLikeEventContent},
room_id,
time::Duration,
TransactionId,
},
test_utils::mocks::MatrixMockServer,
};
use serde_json::json;
use wiremock::ResponseTemplate;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server.sync_joined_room(&client, room_id!("!room_id:localhost")).await;
mock_server
.mock_room_send()
.match_delayed_event(Duration::from_millis(500))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"delay_id":"$some_id"})))
.mock_once()
.mount()
.await;
let response_not_mocked =
room.send_raw("m.room.message", json!({ "body": "Hello world" })).await;
// A non delayed event should not be mocked by the server.
assert!(response_not_mocked.is_err());
let r = delayed_message_event::unstable::Request::new(
room.room_id().to_owned(),
TransactionId::new(),
DelayParameters::Timeout { timeout: Duration::from_millis(500) },
&AnyMessageLikeEventContent::Message(MessageEventContent::plain("hello world")),
)
.unwrap();
let response = room.client().send(r).await.unwrap();
// The delayed `m.room.message` event type should be mocked by the server.
assert_eq!("$some_id", response.delay_id);
Sourcepub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
pub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
Returns a send endpoint that emulates success, i.e. the event has been sent with the given event id.
§Examples
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
let send_guard = mock_server
.mock_room_send()
.ok(event_id)
.expect(1)
.mount_as_scoped()
.await;
let response = room.send_raw("m.room.message", json!({ "body": "Hello world" })).await?;
assert_eq!(
event_id,
response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn ok_with_capture(
self,
returned_event_id: impl Into<OwnedEventId>,
event_sender: impl Into<OwnedUserId>,
) -> (Receiver<Raw<AnySyncTimelineEvent>>, MatrixMock<'a>)
pub fn ok_with_capture( self, returned_event_id: impl Into<OwnedEventId>, event_sender: impl Into<OwnedUserId>, ) -> (Receiver<Raw<AnySyncTimelineEvent>>, MatrixMock<'a>)
Returns a send endpoint that emulates success, i.e. the event has been sent with the given event id.
The sent event is captured and can be accessed using the returned
Receiver
. The Receiver
is valid only for a send call. The given
event_sender
are added to the event JSON.
§Examples
use matrix_sdk::{
ruma::{
event_id, events::room::message::RoomMessageEventContent, room_id,
},
test_utils::mocks::MatrixMockServer,
};
use matrix_sdk_test::JoinedRoomBuilder;
let room_id = room_id!("!room_id:localhost");
let event_id = event_id!("$some_id");
let server = MatrixMockServer::new().await;
let client = server.client_builder().build().await;
let user_id = client.user_id().expect("We should have a user ID by now");
let (receiver, mock) =
server.mock_room_send().ok_with_capture(event_id, user_id);
server
.mock_sync()
.ok_and_run(&client, |builder| {
builder.add_joined_room(JoinedRoomBuilder::new(room_id));
})
.await;
// Mock any additional endpoints that might be needed to send the message.
let room = client
.get_room(room_id)
.expect("We should have access to our room now");
let event_id = room
.send(RoomMessageEventContent::text_plain("It's a secret to everybody"))
.await
.expect("We should be able to send an initial message")
.event_id;
let event = receiver.await?;
Source§impl<'a> MockEndpoint<'a, RoomSendStateEndpoint>
impl<'a> MockEndpoint<'a, RoomSendStateEndpoint>
Sourcepub fn body_matches_partial_json(self, body: Value) -> Self
pub fn body_matches_partial_json(self, body: Value) -> Self
Ensures that the body of the request is a superset of the provided
body
parameter.
§Examples
use matrix_sdk::{
ruma::{
room_id, event_id,
events::room::power_levels::RoomPowerLevelsEventContent,
room_version_rules::AuthorizationRules
},
test_utils::mocks::MatrixMockServer
};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send_state()
.body_matches_partial_json(json!({
"redact": 51,
}))
.ok(event_id)
.expect(1)
.mount()
.await;
let mut content = RoomPowerLevelsEventContent::new(&AuthorizationRules::V1);
// Update the power level to a non default value.
// Otherwise it will be skipped from serialization.
content.redact = 51.into();
let response = room.send_state_event(content).await?;
assert_eq!(
event_id,
response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn for_type(self, event_type: StateEventType) -> Self
pub fn for_type(self, event_type: StateEventType) -> Self
Ensures that the send endpoint request uses a specific event type.
Note: works with any room.
§Examples
see also MatrixMockServer::mock_room_send
for more context.
use matrix_sdk::{
ruma::{
event_id,
events::room::{
create::RoomCreateEventContent, power_levels::RoomPowerLevelsEventContent,
},
events::StateEventType,
room_id,
room_version_rules::AuthorizationRules,
},
test_utils::mocks::MatrixMockServer,
};
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server.sync_joined_room(&client, room_id!("!room_id:localhost")).await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send_state()
.for_type(StateEventType::RoomPowerLevels)
.ok(event_id)
.expect(1)
.mount()
.await;
let response_not_mocked = room.send_state_event(RoomCreateEventContent::new_v11()).await;
// The `m.room.reaction` event type should not be mocked by the server.
assert!(response_not_mocked.is_err());
let response = room.send_state_event(RoomPowerLevelsEventContent::new(&AuthorizationRules::V1)).await?;
// The `m.room.message` event type should be mocked by the server.
assert_eq!(
event_id, response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn match_delayed_event(self, delay: Duration) -> Self
pub fn match_delayed_event(self, delay: Duration) -> Self
Ensures the event was sent as a delayed event.
See also the MSC.
Note: works with any room.
§Examples
see also MatrixMockServer::mock_room_send
for more context.
use matrix_sdk::{
ruma::{
api::client::delayed_events::{delayed_state_event, DelayParameters},
events::{room::create::RoomCreateEventContent, AnyStateEventContent},
room_id,
time::Duration,
},
test_utils::mocks::MatrixMockServer,
};
use wiremock::ResponseTemplate;
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server.sync_joined_room(&client, room_id!("!room_id:localhost")).await;
mock_server
.mock_room_send_state()
.match_delayed_event(Duration::from_millis(500))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"delay_id":"$some_id"})))
.mock_once()
.mount()
.await;
let response_not_mocked = room.send_state_event(RoomCreateEventContent::new_v11()).await;
// A non delayed event should not be mocked by the server.
assert!(response_not_mocked.is_err());
let r = delayed_state_event::unstable::Request::new(
room.room_id().to_owned(),
"".to_owned(),
DelayParameters::Timeout { timeout: Duration::from_millis(500) },
&AnyStateEventContent::RoomCreate(RoomCreateEventContent::new_v11()),
)
.unwrap();
let response = room.client().send(r).await.unwrap();
// The delayed `m.room.message` event type should be mocked by the server.
assert_eq!("$some_id", response.delay_id);
Sourcepub fn for_key(self, state_key: String) -> Self
pub fn for_key(self, state_key: String) -> Self
use matrix_sdk::{
ruma::{
event_id,
events::{call::member::CallMemberEventContent, AnyStateEventContent},
room_id,
},
test_utils::mocks::MatrixMockServer,
};
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server.sync_joined_room(&client, room_id!("!room_id:localhost")).await;
let event_id = event_id!("$some_id");
mock_server
.mock_room_send_state()
.for_key("my_key".to_owned())
.ok(event_id)
.expect(1)
.mount()
.await;
let response_not_mocked = room
.send_state_event_for_key(
"",
AnyStateEventContent::CallMember(CallMemberEventContent::new_empty(None)),
)
.await;
// The `m.room.reaction` event type should not be mocked by the server.
assert!(response_not_mocked.is_err());
let response = room
.send_state_event_for_key(
"my_key",
AnyStateEventContent::CallMember(CallMemberEventContent::new_empty(None)),
)
.await
.unwrap();
// The `m.room.message` event type should be mocked by the server.
assert_eq!(
event_id, response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Sourcepub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
pub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
Returns a send endpoint that emulates success, i.e. the event has been sent with the given event id.
§Examples
use matrix_sdk::{ruma::{room_id, event_id}, test_utils::mocks::MatrixMockServer};
use serde_json::json;
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
let event_id = event_id!("$some_id");
let send_guard = mock_server
.mock_room_send_state()
.ok(event_id)
.expect(1)
.mount_as_scoped()
.await;
let response = room.send_state_event_raw("m.room.message", "my_key", json!({ "body": "Hello world" })).await?;
assert_eq!(
event_id,
response.event_id,
"The event ID we mocked should match the one we received when we sent the event"
);
Source§impl<'a> MockEndpoint<'a, SyncEndpoint>
impl<'a> MockEndpoint<'a, SyncEndpoint>
Sourcepub fn timeout(self, timeout: Option<Duration>) -> Self
pub fn timeout(self, timeout: Option<Duration>) -> Self
Expect the given timeout, or lack thereof, in the request.
Sourcepub fn ok<F: FnOnce(&mut SyncResponseBuilder)>(self, func: F) -> MatrixMock<'a>
pub fn ok<F: FnOnce(&mut SyncResponseBuilder)>(self, func: F) -> MatrixMock<'a>
Mocks the sync endpoint, using the given function to generate the response.
Sourcepub async fn ok_and_run<F: FnOnce(&mut SyncResponseBuilder)>(
self,
client: &Client,
func: F,
)
pub async fn ok_and_run<F: FnOnce(&mut SyncResponseBuilder)>( self, client: &Client, func: F, )
Temporarily mocks the sync with the given endpoint and runs a client sync with it.
After calling this function, the sync endpoint isn’t mocked anymore.
§Examples
use matrix_sdk::{ruma::room_id, test_utils::mocks::MatrixMockServer};
use matrix_sdk_test::JoinedRoomBuilder;
// First create the mock server and client pair.
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
let room_id = room_id!("!room_id:localhost");
// Let's emulate what `MatrixMockServer::sync_joined_room()` does.
mock_server
.mock_sync()
.ok_and_run(&client, |builder| {
builder.add_joined_room(JoinedRoomBuilder::new(room_id));
})
.await;
let room = client
.get_room(room_id)
.expect("The room should be available after we mocked the sync");
Source§impl<'a> MockEndpoint<'a, EncryptionStateEndpoint>
impl<'a> MockEndpoint<'a, EncryptionStateEndpoint>
Sourcepub fn encrypted(self) -> MatrixMock<'a>
pub fn encrypted(self) -> MatrixMock<'a>
Marks the room as encrypted.
§Examples
use matrix_sdk::{ruma::room_id, test_utils::mocks::MatrixMockServer};
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().encrypted().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
assert!(
room.latest_encryption_state().await?.is_encrypted(),
"The room should be marked as encrypted."
);
Sourcepub fn plain(self) -> MatrixMock<'a>
pub fn plain(self) -> MatrixMock<'a>
Marks the room as not encrypted.
§Examples
use matrix_sdk::{ruma::room_id, test_utils::mocks::MatrixMockServer};
let mock_server = MatrixMockServer::new().await;
let client = mock_server.client_builder().build().await;
mock_server.mock_room_state_encryption().plain().mount().await;
let room = mock_server
.sync_joined_room(&client, room_id!("!room_id:localhost"))
.await;
assert!(
!room.latest_encryption_state().await?.is_encrypted(),
"The room should not be marked as encrypted."
);
Source§impl<'a> MockEndpoint<'a, SetEncryptionStateEndpoint>
impl<'a> MockEndpoint<'a, SetEncryptionStateEndpoint>
Sourcepub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
pub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
Returns a mock for a successful setting of the encryption state event.
Source§impl<'a> MockEndpoint<'a, RoomRedactEndpoint>
impl<'a> MockEndpoint<'a, RoomRedactEndpoint>
Sourcepub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
pub fn ok(self, returned_event_id: impl Into<OwnedEventId>) -> MatrixMock<'a>
Returns a redact endpoint that emulates success, i.e. the redaction event has been sent with the given event id.
Source§impl<'a> MockEndpoint<'a, RoomEventEndpoint>
impl<'a> MockEndpoint<'a, RoomEventEndpoint>
Sourcepub fn room(self, room: impl Into<OwnedRoomId>) -> Self
pub fn room(self, room: impl Into<OwnedRoomId>) -> Self
Limits the scope of this mock to a specific room.
Sourcepub fn match_event_id(self) -> Self
pub fn match_event_id(self) -> Self
Whether the mock checks for the event id from the event.
Sourcepub fn ok(self, event: TimelineEvent) -> MatrixMock<'a>
pub fn ok(self, event: TimelineEvent) -> MatrixMock<'a>
Returns a redact endpoint that emulates success, i.e. the redaction event has been sent with the given event id.
Source§impl<'a> MockEndpoint<'a, RoomEventContextEndpoint>
impl<'a> MockEndpoint<'a, RoomEventContextEndpoint>
Sourcepub fn room(self, room: impl Into<OwnedRoomId>) -> Self
pub fn room(self, room: impl Into<OwnedRoomId>) -> Self
Limits the scope of this mock to a specific room.
Sourcepub fn match_event_id(self) -> Self
pub fn match_event_id(self) -> Self
Whether the mock checks for the event id from the event.
Sourcepub fn ok(
self,
event: TimelineEvent,
start: impl Into<String>,
end: impl Into<String>,
state_events: Vec<Raw<AnyStateEvent>>,
) -> MatrixMock<'a>
pub fn ok( self, event: TimelineEvent, start: impl Into<String>, end: impl Into<String>, state_events: Vec<Raw<AnyStateEvent>>, ) -> MatrixMock<'a>
Returns an endpoint that emulates success.
Source§impl<'a> MockEndpoint<'a, RoomMessagesEndpoint>
A prebuilt mock for getting a room messages in a room.
impl<'a> MockEndpoint<'a, RoomMessagesEndpoint>
A prebuilt mock for getting a room messages in a room.
Sourcepub fn match_limit(self, limit: u32) -> Self
pub fn match_limit(self, limit: u32) -> Self
Expects an optional limit to be set on the request.
Sourcepub fn match_from(self, from: &str) -> Self
pub fn match_from(self, from: &str) -> Self
Expects an optional from
to be set on the request.
Sourcepub fn ok(self, response: RoomMessagesResponseTemplate) -> MatrixMock<'a>
pub fn ok(self, response: RoomMessagesResponseTemplate) -> MatrixMock<'a>
Returns a messages endpoint that emulates success, i.e. the messages
provided as response
could be retrieved.
Note: pass chunk
in the correct order: topological for forward
pagination, reverse topological for backwards pagination.
Source§impl<'a> MockEndpoint<'a, UploadEndpoint>
impl<'a> MockEndpoint<'a, UploadEndpoint>
Sourcepub fn expect_mime_type(self, content_type: &str) -> Self
pub fn expect_mime_type(self, content_type: &str) -> Self
Expect that the content type matches what’s given here.
Sourcepub fn ok_with_capture(
self,
mxc_id: &MxcUri,
) -> (Receiver<Vec<u8>>, MatrixMock<'a>)
pub fn ok_with_capture( self, mxc_id: &MxcUri, ) -> (Receiver<Vec<u8>>, MatrixMock<'a>)
Returns a upload endpoint that emulates success, i.e. the media has been
uploaded to the media server and can be accessed using the given
event has been sent with the given MxcUri
.
The uploaded content is captured and can be accessed using the returned
Receiver
. The Receiver
is valid only for a single media
upload.
§Examples
use matrix_sdk::{
ruma::{event_id, mxc_uri, room_id},
test_utils::mocks::MatrixMockServer,
};
let mxid = mxc_uri!("mxc://localhost/12345");
let server = MatrixMockServer::new().await;
let (receiver, upload_mock) = server.mock_upload().ok_with_capture(mxid);
let client = server.client_builder().build().await;
client.media().upload(&mime::TEXT_PLAIN, vec![1, 2, 3, 4, 5], None).await?;
let uploaded = receiver.await?;
assert_eq!(uploaded, vec![1, 2, 3, 4, 5]);
Sourcepub fn ok(self, mxc_id: &MxcUri) -> MatrixMock<'a>
pub fn ok(self, mxc_id: &MxcUri) -> MatrixMock<'a>
Returns a upload endpoint that emulates success, i.e. the media has been
uploaded to the media server and can be accessed using the given
event has been sent with the given MxcUri
.
Source§impl<'a> MockEndpoint<'a, ResolveRoomAliasEndpoint>
impl<'a> MockEndpoint<'a, ResolveRoomAliasEndpoint>
Sourcepub fn for_alias(self, alias: impl Into<String>) -> Self
pub fn for_alias(self, alias: impl Into<String>) -> Self
Sets up the endpoint to only intercept requests for the given room alias.
Sourcepub fn ok(self, room_id: &str, servers: Vec<String>) -> MatrixMock<'a>
pub fn ok(self, room_id: &str, servers: Vec<String>) -> MatrixMock<'a>
Returns a data endpoint with a resolved room alias.
Sourcepub fn not_found(self) -> MatrixMock<'a>
pub fn not_found(self) -> MatrixMock<'a>
Returns a data endpoint for a room alias that does not exit.
Source§impl<'a> MockEndpoint<'a, CreateRoomAliasEndpoint>
impl<'a> MockEndpoint<'a, CreateRoomAliasEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a data endpoint for creating a room alias.
Source§impl<'a> MockEndpoint<'a, RemoveRoomAliasEndpoint>
impl<'a> MockEndpoint<'a, RemoveRoomAliasEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a data endpoint for removing a room alias.
Source§impl<'a> MockEndpoint<'a, PublicRoomsEndpoint>
impl<'a> MockEndpoint<'a, PublicRoomsEndpoint>
Sourcepub fn ok(
self,
chunk: Vec<PublicRoomsChunk>,
next_batch: Option<String>,
prev_batch: Option<String>,
total_room_count_estimate: Option<u64>,
) -> MatrixMock<'a>
pub fn ok( self, chunk: Vec<PublicRoomsChunk>, next_batch: Option<String>, prev_batch: Option<String>, total_room_count_estimate: Option<u64>, ) -> MatrixMock<'a>
Returns a data endpoint for paginating the public room list.
Sourcepub fn ok_with_via_params(
self,
server_map: BTreeMap<OwnedServerName, Vec<PublicRoomsChunk>>,
) -> MatrixMock<'a>
pub fn ok_with_via_params( self, server_map: BTreeMap<OwnedServerName, Vec<PublicRoomsChunk>>, ) -> MatrixMock<'a>
Returns a data endpoint for paginating the public room list with several
via
params.
Each via
param must be in the server_map
parameter, otherwise it’ll
fail.
Source§impl<'a> MockEndpoint<'a, GetRoomVisibilityEndpoint>
impl<'a> MockEndpoint<'a, GetRoomVisibilityEndpoint>
Sourcepub fn ok(self, visibility: Visibility) -> MatrixMock<'a>
pub fn ok(self, visibility: Visibility) -> MatrixMock<'a>
Returns an endpoint that get the room’s public visibility.
Source§impl<'a> MockEndpoint<'a, SetRoomVisibilityEndpoint>
impl<'a> MockEndpoint<'a, SetRoomVisibilityEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns an endpoint that updates the room’s visibility.
Source§impl<'a> MockEndpoint<'a, RoomKeysVersionEndpoint>
impl<'a> MockEndpoint<'a, RoomKeysVersionEndpoint>
Sourcepub fn exists(self) -> MatrixMock<'a>
pub fn exists(self) -> MatrixMock<'a>
Returns an endpoint that says there is a single room keys backup
Sourcepub fn none(self) -> MatrixMock<'a>
pub fn none(self) -> MatrixMock<'a>
Returns an endpoint that says there is no room keys backup
Sourcepub fn error429(self) -> MatrixMock<'a>
pub fn error429(self) -> MatrixMock<'a>
Returns an endpoint that 429 errors when we get it
Sourcepub fn error404(self) -> MatrixMock<'a>
pub fn error404(self) -> MatrixMock<'a>
Returns an endpoint that 404 errors when we get it
Source§impl<'a> MockEndpoint<'a, AddRoomKeysVersionEndpoint>
impl<'a> MockEndpoint<'a, AddRoomKeysVersionEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns an endpoint that may be used to add room key backups
Source§impl<'a> MockEndpoint<'a, DeleteRoomKeysVersionEndpoint>
impl<'a> MockEndpoint<'a, DeleteRoomKeysVersionEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns an endpoint that allows deleting room key backups
Source§impl<'a> MockEndpoint<'a, SendToDeviceEndpoint>
impl<'a> MockEndpoint<'a, SendToDeviceEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with default data.
Source§impl<'a> MockEndpoint<'a, GetRoomMembersEndpoint>
impl<'a> MockEndpoint<'a, GetRoomMembersEndpoint>
Sourcepub fn ok(self, members: Vec<Raw<RoomMemberEvent>>) -> MatrixMock<'a>
pub fn ok(self, members: Vec<Raw<RoomMemberEvent>>) -> MatrixMock<'a>
Returns a successful get members request with a list of members.
Source§impl<'a> MockEndpoint<'a, InviteUserByIdEndpoint>
impl<'a> MockEndpoint<'a, InviteUserByIdEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful invite user by id request.
Source§impl<'a> MockEndpoint<'a, KickUserEndpoint>
impl<'a> MockEndpoint<'a, KickUserEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful kick user request.
Source§impl<'a> MockEndpoint<'a, BanUserEndpoint>
impl<'a> MockEndpoint<'a, BanUserEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful ban user request.
Source§impl<'a> MockEndpoint<'a, VersionsEndpoint>
impl<'a> MockEndpoint<'a, VersionsEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful /_matrix/client/versions
request.
The response will return some commonly supported versions.
Sourcepub fn ok_with_unstable_features(self) -> MatrixMock<'a>
pub fn ok_with_unstable_features(self) -> MatrixMock<'a>
Returns a successful /_matrix/client/versions
request.
The response will return some commonly supported versions and unstable features supported by the SDK.
Source§impl<'a> MockEndpoint<'a, RoomSummaryEndpoint>
impl<'a> MockEndpoint<'a, RoomSummaryEndpoint>
Sourcepub fn ok(self, room_id: &RoomId) -> MatrixMock<'a>
pub fn ok(self, room_id: &RoomId) -> MatrixMock<'a>
Returns a successful response with some default data for the given room id.
Source§impl<'a> MockEndpoint<'a, SetRoomPinnedEventsEndpoint>
impl<'a> MockEndpoint<'a, SetRoomPinnedEventsEndpoint>
Sourcepub fn ok(self, event_id: OwnedEventId) -> MatrixMock<'a>
pub fn ok(self, event_id: OwnedEventId) -> MatrixMock<'a>
Returns a successful response with a given event id. id.
Returns an error response with a generic error code indicating the client is not authorized to set pinned events.
Source§impl<'a> MockEndpoint<'a, WhoAmIEndpoint>
impl<'a> MockEndpoint<'a, WhoAmIEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with the default device ID.
Sourcepub fn ok_with_device_id(self, device_id: &DeviceId) -> MatrixMock<'a>
pub fn ok_with_device_id(self, device_id: &DeviceId) -> MatrixMock<'a>
Returns a successful response with the given device ID.
Sourcepub fn err_unknown_token(self) -> MatrixMock<'a>
pub fn err_unknown_token(self) -> MatrixMock<'a>
Returns an error response with an M_UNKNOWN_TOKEN
.
Source§impl<'a> MockEndpoint<'a, UploadKeysEndpoint>
impl<'a> MockEndpoint<'a, UploadKeysEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with counts of 10 curve25519 keys and 20 signed curve25519 keys.
Source§impl<'a> MockEndpoint<'a, QueryKeysEndpoint>
impl<'a> MockEndpoint<'a, QueryKeysEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Source§impl<'a> MockEndpoint<'a, WellKnownEndpoint>
impl<'a> MockEndpoint<'a, WellKnownEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with the URL for this homeserver.
Sourcepub fn ok_with_homeserver_url(self, homeserver_url: &str) -> MatrixMock<'a>
pub fn ok_with_homeserver_url(self, homeserver_url: &str) -> MatrixMock<'a>
Returns a successful response with the given homeserver URL.
Sourcepub fn error404(self) -> MatrixMock<'a>
pub fn error404(self) -> MatrixMock<'a>
Returns a 404 error response.
Source§impl<'a> MockEndpoint<'a, UploadCrossSigningKeysEndpoint>
impl<'a> MockEndpoint<'a, UploadCrossSigningKeysEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Sourcepub fn uiaa_invalid_password(self) -> MatrixMock<'a>
pub fn uiaa_invalid_password(self) -> MatrixMock<'a>
Returns an error response with a UIAA stage that failed to authenticate because of an invalid password.
Sourcepub fn uiaa(self) -> MatrixMock<'a>
pub fn uiaa(self) -> MatrixMock<'a>
Returns an error response with a UIAA stage.
Sourcepub fn uiaa_oauth(self) -> MatrixMock<'a>
pub fn uiaa_oauth(self) -> MatrixMock<'a>
Returns an error response with an OAuth 2.0 UIAA stage.
Source§impl<'a> MockEndpoint<'a, UploadCrossSigningSignaturesEndpoint>
impl<'a> MockEndpoint<'a, UploadCrossSigningSignaturesEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Source§impl<'a> MockEndpoint<'a, RoomLeaveEndpoint>
impl<'a> MockEndpoint<'a, RoomLeaveEndpoint>
Sourcepub fn ok(self, room_id: &RoomId) -> MatrixMock<'a>
pub fn ok(self, room_id: &RoomId) -> MatrixMock<'a>
Returns a successful response with some default data for the given room id.
Sourcepub fn forbidden(self) -> MatrixMock<'a>
pub fn forbidden(self) -> MatrixMock<'a>
Returns a M_FORBIDDEN
response.
Source§impl<'a> MockEndpoint<'a, RoomForgetEndpoint>
impl<'a> MockEndpoint<'a, RoomForgetEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with some default data for the given room id.
Source§impl<'a> MockEndpoint<'a, LogoutEndpoint>
impl<'a> MockEndpoint<'a, LogoutEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Source§impl<'a> MockEndpoint<'a, RoomThreadsEndpoint>
impl<'a> MockEndpoint<'a, RoomThreadsEndpoint>
Sourcepub fn match_from(self, from: &str) -> Self
pub fn match_from(self, from: &str) -> Self
Expects an optional from
to be set on the request.
Sourcepub fn ok(
self,
chunk: Vec<Raw<AnyTimelineEvent>>,
next_batch: Option<String>,
) -> MatrixMock<'a>
pub fn ok( self, chunk: Vec<Raw<AnyTimelineEvent>>, next_batch: Option<String>, ) -> MatrixMock<'a>
Returns a successful response with some optional events and previous batch token.
Source§impl<'a> MockEndpoint<'a, RoomRelationsEndpoint>
impl<'a> MockEndpoint<'a, RoomRelationsEndpoint>
Sourcepub fn match_from(self, from: &str) -> Self
pub fn match_from(self, from: &str) -> Self
Expects an optional from
to be set on the request.
Sourcepub fn match_limit(self, limit: u32) -> Self
pub fn match_limit(self, limit: u32) -> Self
Expects an optional limit
to be set on the request.
Sourcepub fn match_subrequest(self, spec: IncludeRelations) -> Self
pub fn match_subrequest(self, spec: IncludeRelations) -> Self
Match the given subrequest, according to the given specification.
Sourcepub fn match_target_event(self, event_id: OwnedEventId) -> Self
pub fn match_target_event(self, event_id: OwnedEventId) -> Self
Expects the request to match a specific event id.
Sourcepub fn ok(self, response: RoomRelationsResponseTemplate) -> MatrixMock<'a>
pub fn ok(self, response: RoomRelationsResponseTemplate) -> MatrixMock<'a>
Returns a successful response with some optional events and pagination tokens.
Source§impl<'a> MockEndpoint<'a, GlobalAccountDataEndpoint>
impl<'a> MockEndpoint<'a, GlobalAccountDataEndpoint>
Sourcepub fn ok(
self,
user_id: &UserId,
event_type: GlobalAccountDataEventType,
json_response: Value,
) -> MatrixMock<'a>
pub fn ok( self, user_id: &UserId, event_type: GlobalAccountDataEventType, json_response: Value, ) -> MatrixMock<'a>
Returns a mock for a successful global account data event.
Sourcepub fn not_found(
self,
user_id: &UserId,
event_type: GlobalAccountDataEventType,
) -> MatrixMock<'a>
pub fn not_found( self, user_id: &UserId, event_type: GlobalAccountDataEventType, ) -> MatrixMock<'a>
Returns a mock for a not found global account data event.
Source§impl<'a> MockEndpoint<'a, ReceiptEndpoint>
impl<'a> MockEndpoint<'a, ReceiptEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Sourcepub fn body_matches_partial_json(self, body: Value) -> Self
pub fn body_matches_partial_json(self, body: Value) -> Self
Ensures that the body of the request is a superset of the provided
body
parameter.
Sourcepub fn body_json(self, body: Value) -> Self
pub fn body_json(self, body: Value) -> Self
Ensures that the body of the request is the exact provided body
parameter.
Sourcepub fn match_thread(self, thread: ReceiptThread) -> Self
pub fn match_thread(self, thread: ReceiptThread) -> Self
Ensures that the request matches a specific receipt thread.
Sourcepub fn match_event_id(self, event_id: &EventId) -> Self
pub fn match_event_id(self, event_id: &EventId) -> Self
Ensures that the request matches a specific event id.
Source§impl<'a> MockEndpoint<'a, ReadMarkersEndpoint>
impl<'a> MockEndpoint<'a, ReadMarkersEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Source§impl<'a> MockEndpoint<'a, RoomAccountDataEndpoint>
impl<'a> MockEndpoint<'a, RoomAccountDataEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty response.
Source§impl<'a> MockEndpoint<'a, AuthenticatedMediaConfigEndpoint>
impl<'a> MockEndpoint<'a, AuthenticatedMediaConfigEndpoint>
Sourcepub fn ok(self, max_upload_size: UInt) -> MatrixMock<'a>
pub fn ok(self, max_upload_size: UInt) -> MatrixMock<'a>
Returns a successful response with the provided max upload size.
Sourcepub fn ok_default(self) -> MatrixMock<'a>
pub fn ok_default(self) -> MatrixMock<'a>
Returns a successful response with a maxed out max upload size.
Source§impl<'a> MockEndpoint<'a, MediaConfigEndpoint>
impl<'a> MockEndpoint<'a, MediaConfigEndpoint>
Sourcepub fn ok(self, max_upload_size: UInt) -> MatrixMock<'a>
pub fn ok(self, max_upload_size: UInt) -> MatrixMock<'a>
Returns a successful response with the provided max upload size.
Source§impl<'a> MockEndpoint<'a, LoginEndpoint>
impl<'a> MockEndpoint<'a, LoginEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Sourcepub fn ok_with(self, response: LoginResponseTemplate200) -> MatrixMock<'a>
pub fn ok_with(self, response: LoginResponseTemplate200) -> MatrixMock<'a>
Returns a given response on POST /login requests
§Arguments
response
- The response that the mock server sends on POST /login requests.
§Returns
Returns a MatrixMock
which can be mounted.
§Examples
use matrix_sdk::test_utils::mocks::{
LoginResponseTemplate200, MatrixMockServer,
};
use matrix_sdk_test::async_test;
use ruma::{device_id, time::Duration, user_id};
#[async_test]
async fn test_ok_with() {
let server = MatrixMockServer::new().await;
server
.mock_login()
.ok_with(LoginResponseTemplate200::new(
"qwerty",
device_id!("DEADBEEF"),
user_id!("@cheeky_monkey:matrix.org"),
))
.mount()
.await;
let client = server.client_builder().unlogged().build().await;
let result = client
.matrix_auth()
.login_username("example", "wordpass")
.send()
.await
.unwrap();
assert!(
result.access_tokesn.unwrap() == "qwerty",
"wrong access token in response"
);
assert!(
result.device_id.unwrap() == "DEADBEEF",
"wrong device id in response"
);
assert!(
result.user_id.unwrap() == "@cheeky_monkey:matrix.org",
"wrong user id in response"
);
}
Sourcepub fn body_matches_partial_json(self, body: Value) -> Self
pub fn body_matches_partial_json(self, body: Value) -> Self
Ensures that the body of the request is a superset of the provided
body
parameter.
Source§impl<'a> MockEndpoint<'a, DevicesEndpoint>
impl<'a> MockEndpoint<'a, DevicesEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Source§impl<'a> MockEndpoint<'a, UserDirectoryEndpoint>
impl<'a> MockEndpoint<'a, UserDirectoryEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Source§impl<'a> MockEndpoint<'a, CreateRoomEndpoint>
impl<'a> MockEndpoint<'a, CreateRoomEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Source§impl<'a> MockEndpoint<'a, UpgradeRoomEndpoint>
impl<'a> MockEndpoint<'a, UpgradeRoomEndpoint>
Sourcepub fn ok_with(self, new_room_id: &RoomId) -> MatrixMock<'a>
pub fn ok_with(self, new_room_id: &RoomId) -> MatrixMock<'a>
Returns a successful response with desired replacement_room ID.
Source§impl<'a> MockEndpoint<'a, MediaAllocateEndpoint>
impl<'a> MockEndpoint<'a, MediaAllocateEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Source§impl<'a> MockEndpoint<'a, MediaAllocatedUploadEndpoint>
impl<'a> MockEndpoint<'a, MediaAllocatedUploadEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response.
Source§impl<'a> MockEndpoint<'a, MediaDownloadEndpoint>
impl<'a> MockEndpoint<'a, MediaDownloadEndpoint>
Sourcepub fn ok_plain_text(self) -> MatrixMock<'a>
pub fn ok_plain_text(self) -> MatrixMock<'a>
Returns a successful response with a plain text content.
Sourcepub fn ok_image(self) -> MatrixMock<'a>
pub fn ok_image(self) -> MatrixMock<'a>
Returns a successful response with a fake image content.
Source§impl<'a> MockEndpoint<'a, MediaThumbnailEndpoint>
impl<'a> MockEndpoint<'a, MediaThumbnailEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with a fake image content.
Source§impl<'a> MockEndpoint<'a, AuthedMediaDownloadEndpoint>
impl<'a> MockEndpoint<'a, AuthedMediaDownloadEndpoint>
Sourcepub fn ok_plain_text(self) -> MatrixMock<'a>
pub fn ok_plain_text(self) -> MatrixMock<'a>
Returns a successful response with a plain text content.
Sourcepub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a>
pub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a>
Returns a successful response with the given bytes.
Sourcepub fn ok_image(self) -> MatrixMock<'a>
pub fn ok_image(self) -> MatrixMock<'a>
Returns a successful response with a fake image content.
Source§impl<'a> MockEndpoint<'a, AuthedMediaThumbnailEndpoint>
impl<'a> MockEndpoint<'a, AuthedMediaThumbnailEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with a fake image content.
Source§impl<'a> MockEndpoint<'a, JoinRoomEndpoint>
impl<'a> MockEndpoint<'a, JoinRoomEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response using the provided RoomId
.
Source§impl<'a> MockEndpoint<'a, RoomGetThreadSubscriptionEndpoint>
impl<'a> MockEndpoint<'a, RoomGetThreadSubscriptionEndpoint>
Sourcepub fn ok(self, automatic: bool) -> MatrixMock<'a>
pub fn ok(self, automatic: bool) -> MatrixMock<'a>
Returns a successful response for the given thread subscription.
Sourcepub fn match_room_id(self, room_id: OwnedRoomId) -> Self
pub fn match_room_id(self, room_id: OwnedRoomId) -> Self
Match the request parameter against a specific room id.
Sourcepub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
pub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
Match the request parameter against a specific thread root event id.
Source§impl<'a> MockEndpoint<'a, RoomPutThreadSubscriptionEndpoint>
impl<'a> MockEndpoint<'a, RoomPutThreadSubscriptionEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response for the given setting of thread subscription.
Sourcepub fn conflicting_unsubscription(self) -> MatrixMock<'a>
pub fn conflicting_unsubscription(self) -> MatrixMock<'a>
Returns that the server skipped an automated thread subscription, because the user unsubscribed to the thread after the event id passed in the automatic subscription.
Sourcepub fn match_room_id(self, room_id: OwnedRoomId) -> Self
pub fn match_room_id(self, room_id: OwnedRoomId) -> Self
Match the request parameter against a specific room id.
Sourcepub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
pub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
Match the request parameter against a specific thread root event id.
Sourcepub fn match_automatic_event_id(self, up_to_event_id: &EventId) -> Self
pub fn match_automatic_event_id(self, up_to_event_id: &EventId) -> Self
Match the request body’s automatic
field against a specific event id.
Source§impl<'a> MockEndpoint<'a, RoomDeleteThreadSubscriptionEndpoint>
impl<'a> MockEndpoint<'a, RoomDeleteThreadSubscriptionEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response for the deletion of a given thread subscription.
Sourcepub fn match_room_id(self, room_id: OwnedRoomId) -> Self
pub fn match_room_id(self, room_id: OwnedRoomId) -> Self
Match the request parameter against a specific room id.
Sourcepub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
pub fn match_thread_id(self, thread_root: OwnedEventId) -> Self
Match the request parameter against a specific thread root event id.
Source§impl<'a> MockEndpoint<'a, EnablePushRuleEndpoint>
impl<'a> MockEndpoint<'a, EnablePushRuleEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty JSON response.
Source§impl<'a> MockEndpoint<'a, SetPushRulesActionsEndpoint>
impl<'a> MockEndpoint<'a, SetPushRulesActionsEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty JSON response.
Source§impl<'a> MockEndpoint<'a, SetPushRulesEndpoint>
impl<'a> MockEndpoint<'a, SetPushRulesEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty JSON response.
Source§impl<'a> MockEndpoint<'a, DeletePushRulesEndpoint>
impl<'a> MockEndpoint<'a, DeletePushRulesEndpoint>
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful empty JSON response.
Source§impl<'a> MockEndpoint<'a, FederationVersionEndpoint>
impl<'a> MockEndpoint<'a, FederationVersionEndpoint>
Sourcepub fn ok(self, server_name: &str, version: &str) -> MatrixMock<'a>
pub fn ok(self, server_name: &str, version: &str) -> MatrixMock<'a>
Returns a successful response with the given server name and version.
Sourcepub fn ok_empty(self) -> MatrixMock<'a>
pub fn ok_empty(self) -> MatrixMock<'a>
Returns a successful response with empty/missing server information.
Source§impl<'a> MockEndpoint<'a, GetThreadSubscriptionsEndpoint>
impl<'a> MockEndpoint<'a, GetThreadSubscriptionsEndpoint>
Sourcepub fn add_subscription(
self,
room_id: OwnedRoomId,
thread_root: OwnedEventId,
subscription: ThreadSubscription,
) -> Self
pub fn add_subscription( self, room_id: OwnedRoomId, thread_root: OwnedEventId, subscription: ThreadSubscription, ) -> Self
Add a single thread subscription to the response.
Sourcepub fn add_unsubcription(
self,
room_id: OwnedRoomId,
thread_root: OwnedEventId,
unsubscription: ThreadUnsubscription,
) -> Self
pub fn add_unsubcription( self, room_id: OwnedRoomId, thread_root: OwnedEventId, unsubscription: ThreadUnsubscription, ) -> Self
Add a single thread unsubscription to the response.
Sourcepub fn with_delay(self, delay: Duration) -> Self
pub fn with_delay(self, delay: Duration) -> Self
Respond with a given delay to the query.
Sourcepub fn match_from(self, from: &str) -> Self
pub fn match_from(self, from: &str) -> Self
Match the from
query parameter to a given value.
Sourcepub fn ok(self, end: Option<String>) -> MatrixMock<'a>
pub fn ok(self, end: Option<String>) -> MatrixMock<'a>
Returns a successful response with the given thread subscriptions, and “end” parameter to be used in the next query.
Source§impl<'a> MockEndpoint<'a, GetHierarchyEndpoint>
impl<'a> MockEndpoint<'a, GetHierarchyEndpoint>
Sourcepub fn ok_with_room_ids(self, room_ids: Vec<&RoomId>) -> MatrixMock<'a>
pub fn ok_with_room_ids(self, room_ids: Vec<&RoomId>) -> MatrixMock<'a>
Returns a successful response containing the given room IDs.
Sourcepub fn ok_with_room_ids_and_children_state(
self,
room_ids: Vec<&RoomId>,
children_state: Vec<&RoomId>,
) -> MatrixMock<'a>
pub fn ok_with_room_ids_and_children_state( self, room_ids: Vec<&RoomId>, children_state: Vec<&RoomId>, ) -> MatrixMock<'a>
Returns a successful response containing the given room IDs and children states
Sourcepub fn ok(self) -> MatrixMock<'a>
pub fn ok(self) -> MatrixMock<'a>
Returns a successful response with an empty list of rooms.
Source§impl<'a> MockEndpoint<'a, SlidingSyncEndpoint>
impl<'a> MockEndpoint<'a, SlidingSyncEndpoint>
Sourcepub fn ok(self, response: Response) -> MatrixMock<'a>
pub fn ok(self, response: Response) -> MatrixMock<'a>
Mocks the sliding sync endpoint with the given response.
Sourcepub async fn ok_and_run<F: FnOnce(SlidingSyncBuilder) -> SlidingSyncBuilder>(
self,
client: &Client,
on_builder: F,
response: Response,
)
pub async fn ok_and_run<F: FnOnce(SlidingSyncBuilder) -> SlidingSyncBuilder>( self, client: &Client, on_builder: F, response: Response, )
Temporarily mocks the sync with the given endpoint and runs a client sync with it.
After calling this function, the sync endpoint isn’t mocked anymore.
Auto Trait Implementations§
impl<'a, T> Freeze for MockEndpoint<'a, T>where
T: Freeze,
impl<'a, T> !RefUnwindSafe for MockEndpoint<'a, T>
impl<'a, T> Send for MockEndpoint<'a, T>where
T: Send,
impl<'a, T> Sync for MockEndpoint<'a, T>where
T: Sync,
impl<'a, T> Unpin for MockEndpoint<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for MockEndpoint<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more