Move test data to test crate, fix docs

master
Devin R 2020-06-25 08:31:51 -04:00
parent 1016519bb6
commit 92a43e7685
5 changed files with 60 additions and 83 deletions

View File

@ -651,7 +651,8 @@ impl Client {
/// Search the homeserver's directory of public rooms. /// Search the homeserver's directory of public rooms.
/// ///
/// Returns a `get_public_rooms::Response`, an empty response. /// Sends a request to "_matrix/client/r0/publicRooms", returns
/// a `get_public_rooms::Response`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -673,11 +674,8 @@ impl Client {
/// let mut cli = Client::new(homeserver).unwrap(); /// let mut cli = Client::new(homeserver).unwrap();
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # block_on(async { /// # block_on(async {
/// assert!(cli.public_rooms( ///
/// limit, /// cli.public_rooms(limit, since, server).await;
/// since,
/// server
/// ).await.is_ok());
/// # }); /// # });
/// ``` /// ```
pub async fn public_rooms( pub async fn public_rooms(
@ -700,7 +698,8 @@ impl Client {
/// Search the homeserver's directory of public rooms with a filter. /// Search the homeserver's directory of public rooms with a filter.
/// ///
/// Returns a `get_public_rooms_filtered::Response`, an empty response. /// Sends a request to "_matrix/client/r0/publicRooms", returns
/// a `get_public_rooms_filtered::Response`.
/// ///
/// # Arguments /// # Arguments
/// ///
@ -725,7 +724,7 @@ impl Client {
/// .since(last_sync_token) /// .since(last_sync_token)
/// .room_network(RoomNetwork::Matrix); /// .room_network(RoomNetwork::Matrix);
/// ///
/// client.public_rooms_filtered(builder).await.is_err(); /// client.public_rooms_filtered(builder).await;
/// # }) /// # })
/// ``` /// ```
pub async fn public_rooms_filtered<R: Into<get_public_rooms_filtered::Request>>( pub async fn public_rooms_filtered<R: Into<get_public_rooms_filtered::Request>>(
@ -1856,7 +1855,7 @@ mod test {
Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()), Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()),
) )
.with_status(200) .with_status(200)
.with_body_from_file("../test_data/public_rooms.json") .with_body(test_json::PUBLIC_ROOMS.to_string())
.create(); .create();
let client = Client::new(homeserver).unwrap(); let client = Client::new(homeserver).unwrap();
@ -1885,7 +1884,7 @@ mod test {
Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()), Matcher::Regex(r"^/_matrix/client/r0/publicRooms".to_string()),
) )
.with_status(200) .with_status(200)
.with_body_from_file("../test_data/public_rooms.json") .with_body(test_json::PUBLIC_ROOMS.to_string())
.create(); .create();
let client = Client::new(homeserver).unwrap(); let client = Client::new(homeserver).unwrap();

View File

@ -1,5 +1,3 @@
use std::convert::TryFrom;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::{ api::r0::{
account::register::{self, RegistrationKind}, account::register::{self, RegistrationKind},
@ -42,38 +40,17 @@ use matrix_sdk_common::{
/// ``` /// ```
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct RoomBuilder { pub struct RoomBuilder {
/// Extra keys to be added to the content of the `m.room.create`.
creation_content: Option<CreationContent>, creation_content: Option<CreationContent>,
/// List of state events to send to the new room.
///
/// Takes precedence over events set by preset, but gets overriden by
/// name and topic keys.
initial_state: Vec<InitialStateEvent>, initial_state: Vec<InitialStateEvent>,
/// A list of user IDs to invite to the room.
///
/// This will tell the server to invite everyone in the list to the newly created room.
invite: Vec<UserId>, invite: Vec<UserId>,
/// List of third party IDs of users to invite.
invite_3pid: Vec<Invite3pid>, invite_3pid: Vec<Invite3pid>,
/// If set, this sets the `is_direct` flag on room invites.
is_direct: Option<bool>, is_direct: Option<bool>,
/// If this is included, an `m.room.name` event will be sent into the room to indicate
/// the name of the room.
name: Option<String>, name: Option<String>,
/// Power level content to override in the default power level event.
power_level_content_override: Option<PowerLevelsEventContent>, power_level_content_override: Option<PowerLevelsEventContent>,
/// Convenience parameter for setting various default state events based on a preset.
preset: Option<RoomPreset>, preset: Option<RoomPreset>,
/// The desired room alias local part.
room_alias_name: Option<String>, room_alias_name: Option<String>,
/// Room version to set for the room. Defaults to homeserver's default if not specified.
room_version: Option<String>, room_version: Option<String>,
/// If this is included, an `m.room.topic` event will be sent into the room to indicate
/// the topic for the room.
topic: Option<String>, topic: Option<String>,
/// A public visibility indicates that the room will be shown in the published room
/// list. A private visibility will hide the room from the published room list. Rooms
/// default to private visibility if this key is not included.
visibility: Option<Visibility>, visibility: Option<Visibility>,
} }
@ -92,61 +69,68 @@ impl RoomBuilder {
self self
} }
/// Set the `InitialStateEvent` vector. /// Sets a list of state events to send to the new room.
///
/// Takes precedence over events set by preset, but gets overriden by
/// name and topic keys.
pub fn initial_state(&mut self, state: Vec<InitialStateEvent>) -> &mut Self { pub fn initial_state(&mut self, state: Vec<InitialStateEvent>) -> &mut Self {
self.initial_state = state; self.initial_state = state;
self self
} }
/// Set the vec of `UserId`s. /// Sets a list of user IDs to invite to the room.
///
/// This will tell the server to invite everyone in the list to the newly created room.
pub fn invite(&mut self, invite: Vec<UserId>) -> &mut Self { pub fn invite(&mut self, invite: Vec<UserId>) -> &mut Self {
self.invite = invite; self.invite = invite;
self self
} }
/// Set the vec of `Invite3pid`s. /// Sets a list of third party IDs of users to invite.
pub fn invite_3pid(&mut self, invite: Vec<Invite3pid>) -> &mut Self { pub fn invite_3pid(&mut self, invite: Vec<Invite3pid>) -> &mut Self {
self.invite_3pid = invite; self.invite_3pid = invite;
self self
} }
/// Set the vec of `Invite3pid`s. /// If set, this sets the `is_direct` flag on room invites.
pub fn is_direct(&mut self, direct: bool) -> &mut Self { pub fn is_direct(&mut self, direct: bool) -> &mut Self {
self.is_direct = Some(direct); self.is_direct = Some(direct);
self self
} }
/// Set the room name. A `m.room.name` event will be sent to the room. /// If this is included, an `m.room.name` event will be sent into the room to indicate
/// the name of the room.
pub fn name<S: Into<String>>(&mut self, name: S) -> &mut Self { pub fn name<S: Into<String>>(&mut self, name: S) -> &mut Self {
self.name = Some(name.into()); self.name = Some(name.into());
self self
} }
/// Set the room's power levels. /// Power level content to override in the default power level event.
pub fn power_level_override(&mut self, power: PowerLevelsEventContent) -> &mut Self { pub fn power_level_override(&mut self, power: PowerLevelsEventContent) -> &mut Self {
self.power_level_content_override = Some(power); self.power_level_content_override = Some(power);
self self
} }
/// Convenience for setting various default state events based on a preset. /// Convenience parameter for setting various default state events based on a preset.
pub fn preset(&mut self, preset: RoomPreset) -> &mut Self { pub fn preset(&mut self, preset: RoomPreset) -> &mut Self {
self.preset = Some(preset); self.preset = Some(preset);
self self
} }
/// The local part of a room alias. /// The desired room alias local part.
pub fn room_alias_name<S: Into<String>>(&mut self, alias: S) -> &mut Self { pub fn room_alias_name<S: Into<String>>(&mut self, alias: S) -> &mut Self {
self.room_alias_name = Some(alias.into()); self.room_alias_name = Some(alias.into());
self self
} }
/// Room version, defaults to homeserver's version if left unspecified. /// Room version to set for the room. Defaults to homeserver's default if not specified.
pub fn room_version<S: Into<String>>(&mut self, version: S) -> &mut Self { pub fn room_version<S: Into<String>>(&mut self, version: S) -> &mut Self {
self.room_version = Some(version.into()); self.room_version = Some(version.into());
self self
} }
/// If included, a `m.room.topic` event will be sent to the room. /// If this is included, an `m.room.topic` event will be sent into the room to indicate
/// the topic for the room.
pub fn topic<S: Into<String>>(&mut self, topic: S) -> &mut Self { pub fn topic<S: Into<String>>(&mut self, topic: S) -> &mut Self {
self.topic = Some(topic.into()); self.topic = Some(topic.into());
self self
@ -210,33 +194,24 @@ impl Into<create_room::Request> for RoomBuilder {
/// ``` /// ```
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MessagesRequestBuilder { pub struct MessagesRequestBuilder {
/// The room to get events from.
room_id: RoomId, room_id: RoomId,
/// The token to start returning events from.
///
/// This token can be obtained from a
/// prev_batch token returned for each room by the sync API, or from a start or end token
/// returned by a previous request to this endpoint.
from: String, from: String,
/// The token to stop returning events at.
///
/// This token can be obtained from a prev_batch
/// token returned for each room by the sync endpoint, or from a start or end token returned
/// by a previous request to this endpoint.
to: Option<String>, to: Option<String>,
/// The direction to return events from.
direction: Option<Direction>, direction: Option<Direction>,
/// The maximum number of events to return.
///
/// Default: 10.
limit: Option<u32>, limit: Option<u32>,
/// A filter of the returned events with.
filter: Option<RoomEventFilter>, filter: Option<RoomEventFilter>,
} }
impl MessagesRequestBuilder { impl MessagesRequestBuilder {
/// Create a `MessagesRequestBuilder` builder to make a `get_message_events::Request`. /// Create a `MessagesRequestBuilder` builder to make a `get_message_events::Request`.
/// The `room_id` and `from`` fields **need to be set** to create the request. ///
/// # Arguments
///
/// * `room_id` - The id of the room that is being requested.
///
/// * `from` - The token to start returning events from. This token can be obtained from
/// a `prev_batch` token from a sync response, or a start or end token from a previous request
/// to this endpoint.
pub fn new(room_id: RoomId, from: String) -> Self { pub fn new(room_id: RoomId, from: String) -> Self {
Self { Self {
room_id, room_id,
@ -286,7 +261,7 @@ impl Into<get_message_events::Request> for MessagesRequestBuilder {
from: self.from, from: self.from,
to: self.to, to: self.to,
dir: self.direction.unwrap_or(Direction::Backward), dir: self.direction.unwrap_or(Direction::Backward),
limit: self.limit.map_or(Ok(uint!(10)), UInt::try_from).ok(), limit: self.limit.map(UInt::from),
filter: self.filter, filter: self.filter,
} }
} }
@ -485,7 +460,7 @@ impl Into<get_public_rooms_filtered::Request> for RoomListFilterBuilder {
fn into(self) -> get_public_rooms_filtered::Request { fn into(self) -> get_public_rooms_filtered::Request {
get_public_rooms_filtered::Request { get_public_rooms_filtered::Request {
room_network: self.room_network.unwrap_or_default(), room_network: self.room_network.unwrap_or_default(),
limit: self.limit.map_or(Ok(uint!(0)), UInt::try_from).ok(), limit: self.limit.map(UInt::from),
server: self.server, server: self.server,
since: self.since, since: self.since,
filter: self.filter, filter: self.filter,

View File

@ -375,6 +375,28 @@ lazy_static! {
}); });
} }
lazy_static! {
pub static ref PUBLIC_ROOMS: JsonValue = json!({
"chunk": [
{
"aliases": [
"#murrays:cheese.bar"
],
"avatar_url": "mxc://bleeker.street/CHEDDARandBRIE",
"guest_can_join": false,
"name": "CHEESE",
"num_joined_members": 37,
"room_id": "!ol19s:bleecker.street",
"topic": "Tasty tasty cheese",
"world_readable": true
}
],
"next_batch": "p190q",
"prev_batch": "p1902",
"total_room_count_estimate": 115
});
}
lazy_static! { lazy_static! {
pub static ref REGISTRATION_RESPONSE_ERR: JsonValue = json!({ pub static ref REGISTRATION_RESPONSE_ERR: JsonValue = json!({
"errcode": "M_FORBIDDEN", "errcode": "M_FORBIDDEN",

View File

@ -9,7 +9,7 @@ pub mod sync;
pub use events::{ pub use events::{
ALIAS, ALIASES, EVENT_ID, KEYS_QUERY, KEYS_UPLOAD, LOGIN, LOGIN_RESPONSE_ERR, LOGOUT, MEMBER, ALIAS, ALIASES, EVENT_ID, KEYS_QUERY, KEYS_UPLOAD, LOGIN, LOGIN_RESPONSE_ERR, LOGOUT, MEMBER,
MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, REACTION, REGISTRATION_RESPONSE_ERR, MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, PUBLIC_ROOMS, REACTION,
ROOM_ID, ROOM_MESSAGES, TYPING, REGISTRATION_RESPONSE_ERR, ROOM_ID, ROOM_MESSAGES, TYPING,
}; };
pub use sync::{DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC}; pub use sync::{DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC};

View File

@ -1,19 +0,0 @@
{
"chunk": [
{
"aliases": [
"#murrays:cheese.bar"
],
"avatar_url": "mxc://bleeker.street/CHEDDARandBRIE",
"guest_can_join": false,
"name": "CHEESE",
"num_joined_members": 37,
"room_id": "!ol19s:bleecker.street",
"topic": "Tasty tasty cheese",
"world_readable": true
}
],
"next_batch": "p190q",
"prev_batch": "p1902",
"total_room_count_estimate": 115
}