Use identifier macros in tests
parent
591388d13e
commit
d016ce1848
|
@ -842,7 +842,7 @@ impl Client {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use std::convert::TryFrom;
|
/// # use std::convert::TryFrom;
|
||||||
/// use matrix_sdk::{Client, MessagesRequestBuilder};
|
/// use matrix_sdk::{Client, MessagesRequestBuilder};
|
||||||
/// # use matrix_sdk::identifiers::RoomId;
|
/// # use matrix_sdk::identifiers::room_id;
|
||||||
/// # use matrix_sdk::api::r0::filter::RoomEventFilter;
|
/// # use matrix_sdk::api::r0::filter::RoomEventFilter;
|
||||||
/// # use matrix_sdk::api::r0::message::get_message_events::Direction;
|
/// # use matrix_sdk::api::r0::message::get_message_events::Direction;
|
||||||
/// # use url::Url;
|
/// # use url::Url;
|
||||||
|
@ -850,7 +850,7 @@ impl Client {
|
||||||
///
|
///
|
||||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||||
/// let mut builder = MessagesRequestBuilder::new(
|
/// let mut builder = MessagesRequestBuilder::new(
|
||||||
/// RoomId::try_from("!roomid:example.com").unwrap(),
|
/// room_id!("!roomid:example.com"),
|
||||||
/// "t47429-4392820_219380_26003_2265".to_string(),
|
/// "t47429-4392820_219380_26003_2265".to_string(),
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
|
@ -972,13 +972,13 @@ impl Client {
|
||||||
/// # use matrix_sdk::{Client, SyncSettings};
|
/// # use matrix_sdk::{Client, SyncSettings};
|
||||||
/// # use url::Url;
|
/// # use url::Url;
|
||||||
/// # use futures::executor::block_on;
|
/// # use futures::executor::block_on;
|
||||||
/// # use matrix_sdk::identifiers::RoomId;
|
/// # use matrix_sdk::identifiers::room_id;
|
||||||
/// # use std::convert::TryFrom;
|
/// # use std::convert::TryFrom;
|
||||||
/// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent};
|
/// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent};
|
||||||
/// # block_on(async {
|
/// # block_on(async {
|
||||||
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
||||||
/// # let mut client = Client::new(homeserver).unwrap();
|
/// # let mut client = Client::new(homeserver).unwrap();
|
||||||
/// # let room_id = RoomId::try_from("!test:localhost").unwrap();
|
/// # let room_id = room_id!("!test:localhost");
|
||||||
/// use matrix_sdk_common::uuid::Uuid;
|
/// use matrix_sdk_common::uuid::Uuid;
|
||||||
///
|
///
|
||||||
/// let content = MessageEventContent::Text(TextMessageEventContent::plain("Hello world"));
|
/// let content = MessageEventContent::Text(TextMessageEventContent::plain("Hello world"));
|
||||||
|
@ -1077,13 +1077,13 @@ impl Client {
|
||||||
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
|
||||||
/// # let mut client = Client::new(homeserver).unwrap();
|
/// # let mut client = Client::new(homeserver).unwrap();
|
||||||
/// use matrix_sdk::api::r0::profile;
|
/// use matrix_sdk::api::r0::profile;
|
||||||
/// use matrix_sdk::identifiers::UserId;
|
/// use matrix_sdk::identifiers::user_id;
|
||||||
///
|
///
|
||||||
/// // First construct the request you want to make
|
/// // First construct the request you want to make
|
||||||
/// // See https://docs.rs/ruma-client-api/latest/ruma_client_api/index.html
|
/// // See https://docs.rs/ruma-client-api/latest/ruma_client_api/index.html
|
||||||
/// // for all available Endpoints
|
/// // for all available Endpoints
|
||||||
/// let request = profile::get_profile::Request {
|
/// let request = profile::get_profile::Request {
|
||||||
/// user_id: UserId::try_from("@example:localhost").unwrap(),
|
/// user_id: user_id!("@example:localhost"),
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// // Start the request using Client::send()
|
/// // Start the request using Client::send()
|
||||||
|
@ -1447,7 +1447,7 @@ mod test {
|
||||||
use crate::events::room::message::TextMessageEventContent;
|
use crate::events::room::message::TextMessageEventContent;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
|
identifiers::{event_id, room_id, user_id},
|
||||||
RegistrationBuilder, RoomListFilterBuilder,
|
RegistrationBuilder, RoomListFilterBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1456,22 +1456,17 @@ mod test {
|
||||||
use mockito::{mock, Matcher};
|
use mockito::{mock, Matcher};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use std::{
|
use std::{convert::TryInto, path::Path, str::FromStr, time::Duration};
|
||||||
convert::{TryFrom, TryInto},
|
|
||||||
path::Path,
|
|
||||||
str::FromStr,
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_join_leave_room() {
|
async fn test_join_leave_room() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
|
|
||||||
let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
|
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1536,7 +1531,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:example.com").unwrap(),
|
user_id: user_id!("@example:example.com"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1564,7 +1559,7 @@ mod test {
|
||||||
async fn room_creation() {
|
async fn room_creation() {
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "12345".to_owned(),
|
access_token: "12345".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
|
let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
|
||||||
|
@ -1581,7 +1576,7 @@ mod test {
|
||||||
.receive_sync_response(&mut response)
|
.receive_sync_response(&mut response)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
|
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
client.homeserver(),
|
client.homeserver(),
|
||||||
|
@ -1676,7 +1671,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1690,7 +1685,7 @@ mod test {
|
||||||
|
|
||||||
let client = Client::new(homeserver).unwrap();
|
let client = Client::new(homeserver).unwrap();
|
||||||
client.restore_login(session).await.unwrap();
|
client.restore_login(session).await.unwrap();
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId field
|
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId field
|
||||||
|
@ -1705,7 +1700,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1719,7 +1714,7 @@ mod test {
|
||||||
|
|
||||||
let client = Client::new(homeserver).unwrap();
|
let client = Client::new(homeserver).unwrap();
|
||||||
client.restore_login(session).await.unwrap();
|
client.restore_login(session).await.unwrap();
|
||||||
let room_id = RoomIdOrAliasId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org").into();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId field
|
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId field
|
||||||
|
@ -1728,7 +1723,7 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.room_id,
|
.room_id,
|
||||||
RoomId::try_from("!testroom:example.org").unwrap()
|
room_id!("!testroom:example.org")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1736,8 +1731,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn invite_user_by_id() {
|
async fn invite_user_by_id() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1763,8 +1758,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn invite_user_by_3pid() {
|
async fn invite_user_by_3pid() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1825,7 +1820,7 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn room_search_filtered() {
|
async fn room_search_filtered() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1864,7 +1859,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1879,7 +1874,7 @@ mod test {
|
||||||
|
|
||||||
let client = Client::new(homeserver).unwrap();
|
let client = Client::new(homeserver).unwrap();
|
||||||
client.restore_login(session).await.unwrap();
|
client.restore_login(session).await.unwrap();
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let response = client.leave_room(&room_id).await.unwrap();
|
let response = client.leave_room(&room_id).await.unwrap();
|
||||||
if let leave_room::Response = response {
|
if let leave_room::Response = response {
|
||||||
|
@ -1895,8 +1890,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn ban_user() {
|
async fn ban_user() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1930,8 +1925,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn kick_user() {
|
async fn kick_user() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1965,8 +1960,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn forget_room() {
|
async fn forget_room() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -2000,9 +1995,9 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn read_receipt() {
|
async fn read_receipt() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
let event_id = EventId::try_from("$xxxxxx:example.org").unwrap();
|
let event_id = event_id!("$xxxxxx:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -2036,9 +2031,9 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn read_marker() {
|
async fn read_marker() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
let event_id = EventId::try_from("$xxxxxx:example.org").unwrap();
|
let event_id = event_id!("$xxxxxx:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -2072,8 +2067,8 @@ mod test {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
async fn typing_notice() {
|
async fn typing_notice() {
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -2116,8 +2111,8 @@ mod test {
|
||||||
use matrix_sdk_common::uuid::Uuid;
|
use matrix_sdk_common::uuid::Uuid;
|
||||||
|
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
let user = UserId::try_from("@example:localhost").unwrap();
|
let user = user_id!("@example:localhost");
|
||||||
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
|
let room_id = room_id!("!testroom:example.org");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -2147,10 +2142,7 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id)
|
||||||
EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
|
||||||
response.event_id
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -2159,7 +2151,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2181,7 +2173,7 @@ mod test {
|
||||||
let rooms_lock = &client.base_client.joined_rooms();
|
let rooms_lock = &client.base_client.joined_rooms();
|
||||||
let rooms = rooms_lock.read().await;
|
let rooms = rooms_lock.read().await;
|
||||||
let room = &rooms
|
let room = &rooms
|
||||||
.get(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
.get(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read()
|
.read()
|
||||||
.await;
|
.await;
|
||||||
|
@ -2196,7 +2188,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2224,11 +2216,9 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn invited_rooms() {
|
async fn invited_rooms() {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "12345".to_owned(),
|
access_token: "12345".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2251,18 +2241,16 @@ mod test {
|
||||||
assert!(!client.invited_rooms().read().await.is_empty());
|
assert!(!client.invited_rooms().read().await.is_empty());
|
||||||
|
|
||||||
assert!(client
|
assert!(client
|
||||||
.get_invited_room(&RoomId::try_from("!696r7674:example.com").unwrap())
|
.get_invited_room(&room_id!("!696r7674:example.com"))
|
||||||
.await
|
.await
|
||||||
.is_some());
|
.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn left_rooms() {
|
async fn left_rooms() {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "12345".to_owned(),
|
access_token: "12345".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2285,7 +2273,7 @@ mod test {
|
||||||
assert!(client.invited_rooms().read().await.is_empty());
|
assert!(client.invited_rooms().read().await.is_empty());
|
||||||
|
|
||||||
assert!(client
|
assert!(client
|
||||||
.get_left_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
.get_left_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
|
||||||
.await
|
.await
|
||||||
.is_some())
|
.is_some())
|
||||||
}
|
}
|
||||||
|
@ -2296,7 +2284,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@cheeky_monkey:matrix.org").unwrap(),
|
user_id: user_id!("@cheeky_monkey:matrix.org"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2343,7 +2331,7 @@ mod test {
|
||||||
// This is commented out because this field is private...
|
// This is commented out because this field is private...
|
||||||
// assert_eq!(
|
// assert_eq!(
|
||||||
// *base_client.ignored_users.read().await,
|
// *base_client.ignored_users.read().await,
|
||||||
// vec![UserId::try_from("@someone:example.org").unwrap()]
|
// vec![user_id!("@someone:example.org")]
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2393,7 +2381,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2423,7 +2411,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2448,7 +2436,7 @@ mod test {
|
||||||
}
|
}
|
||||||
assert_eq!(vec!["tutorial"], names);
|
assert_eq!(vec!["tutorial"], names);
|
||||||
let room = client
|
let room = client
|
||||||
.get_joined_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -169,17 +169,17 @@ impl Into<create_room::Request> for RoomBuilder {
|
||||||
/// # use std::convert::TryFrom;
|
/// # use std::convert::TryFrom;
|
||||||
/// # use matrix_sdk::{Client, MessagesRequestBuilder};
|
/// # use matrix_sdk::{Client, MessagesRequestBuilder};
|
||||||
/// # use matrix_sdk::api::r0::message::get_message_events::{self, Direction};
|
/// # use matrix_sdk::api::r0::message::get_message_events::{self, Direction};
|
||||||
/// # use matrix_sdk::identifiers::RoomId;
|
/// # use matrix_sdk::identifiers::room_id;
|
||||||
/// # use url::Url;
|
/// # use url::Url;
|
||||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||||
/// # let mut rt = tokio::runtime::Runtime::new().unwrap();
|
/// # let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
/// # rt.block_on(async {
|
/// # rt.block_on(async {
|
||||||
/// # let room_id = RoomId::try_from("!test:localhost").unwrap();
|
/// # let room_id = room_id!("!test:localhost");
|
||||||
/// # let last_sync_token = "".to_string();
|
/// # let last_sync_token = "".to_string();
|
||||||
/// let mut client = Client::new(homeserver).unwrap();
|
/// let mut client = Client::new(homeserver).unwrap();
|
||||||
///
|
///
|
||||||
/// let mut builder = MessagesRequestBuilder::new(
|
/// let mut builder = MessagesRequestBuilder::new(
|
||||||
/// RoomId::try_from("!roomid:example.com").unwrap(),
|
/// room_id!("!roomid:example.com"),
|
||||||
/// "t47429-4392820_219380_26003_2265".to_string(),
|
/// "t47429-4392820_219380_26003_2265".to_string(),
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
|
@ -457,14 +457,13 @@ mod test {
|
||||||
use crate::{
|
use crate::{
|
||||||
api::r0::filter::{LazyLoadOptions, RoomEventFilter},
|
api::r0::filter::{LazyLoadOptions, RoomEventFilter},
|
||||||
events::room::power_levels::NotificationPowerLevels,
|
events::room::power_levels::NotificationPowerLevels,
|
||||||
identifiers::RoomId,
|
identifiers::{room_id, user_id},
|
||||||
js_int::Int,
|
js_int::Int,
|
||||||
Client, Session,
|
Client, Session,
|
||||||
};
|
};
|
||||||
|
|
||||||
use matrix_sdk_test::test_json;
|
use matrix_sdk_test::test_json;
|
||||||
use mockito::{mock, Matcher};
|
use mockito::{mock, Matcher};
|
||||||
use std::convert::TryFrom;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -478,7 +477,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -526,12 +525,12 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut builder = MessagesRequestBuilder::new(
|
let mut builder = MessagesRequestBuilder::new(
|
||||||
RoomId::try_from("!roomid:example.com").unwrap(),
|
room_id!("!roomid:example.com"),
|
||||||
"t47429-4392820_219380_26003_2265".to_string(),
|
"t47429-4392820_219380_26003_2265".to_string(),
|
||||||
);
|
);
|
||||||
builder
|
builder
|
||||||
|
|
|
@ -1868,9 +1868,11 @@ impl BaseClient {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identifiers::{RoomId, UserId},
|
events::AnySyncRoomEvent, identifiers::event_id, BaseClientConfig, JsonStore, Raw,
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
identifiers::{room_id, user_id, RoomId},
|
||||||
BaseClient, Session,
|
BaseClient, Session,
|
||||||
};
|
};
|
||||||
use matrix_sdk_common_macros::async_trait;
|
use matrix_sdk_common_macros::async_trait;
|
||||||
|
@ -1886,7 +1888,7 @@ mod test {
|
||||||
async fn get_client() -> BaseClient {
|
async fn get_client() -> BaseClient {
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
@ -1895,7 +1897,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_room_id() -> RoomId {
|
fn get_room_id() -> RoomId {
|
||||||
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
|
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn member_event() -> serde_json::Value {
|
fn member_event() -> serde_json::Value {
|
||||||
|
@ -1955,7 +1957,7 @@ mod test {
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
async fn test_left_room_creation() {
|
async fn test_left_room_creation() {
|
||||||
let room_id = RoomId::try_from("!left_room:localhost").unwrap();
|
let room_id = room_id!("!left_room:localhost");
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_left_event(&room_id, member_event())
|
.add_custom_left_event(&room_id, member_event())
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
@ -1995,7 +1997,7 @@ mod test {
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
async fn test_invited_room_creation() {
|
async fn test_invited_room_creation() {
|
||||||
let room_id = RoomId::try_from("!invited_room:localhost").unwrap();
|
let room_id = room_id!("!invited_room:localhost");
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_invited_event(&room_id, member_event())
|
.add_custom_invited_event(&room_id, member_event())
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
@ -2068,7 +2070,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
|
|
||||||
let passed = Arc::new(AtomicBool::default());
|
let passed = Arc::new(AtomicBool::default());
|
||||||
let emitter = EE(Arc::clone(&passed));
|
let emitter = EE(Arc::clone(&passed));
|
||||||
|
@ -2393,11 +2395,11 @@ mod test {
|
||||||
async fn message_queue_redaction_event_store_deser() {
|
async fn message_queue_redaction_event_store_deser() {
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
|
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@cheeky_monkey:matrix.org").unwrap(),
|
user_id: user_id!("@cheeky_monkey:matrix.org"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2448,10 +2450,7 @@ mod test {
|
||||||
) = &queue.msgs[0]
|
) = &queue.msgs[0]
|
||||||
{
|
{
|
||||||
// this is the id from the message event in the sync response
|
// this is the id from the message event in the sync response
|
||||||
assert_eq!(
|
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
|
||||||
event.event_id,
|
|
||||||
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
panic!("message event in message queue should be redacted")
|
panic!("message event in message queue should be redacted")
|
||||||
}
|
}
|
||||||
|
@ -2476,10 +2475,7 @@ mod test {
|
||||||
) = &queue.msgs[0]
|
) = &queue.msgs[0]
|
||||||
{
|
{
|
||||||
// this is the id from the message event in the sync response
|
// this is the id from the message event in the sync response
|
||||||
assert_eq!(
|
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
|
||||||
event.event_id,
|
|
||||||
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
panic!("[post store sync] message event in message queue should be redacted")
|
panic!("[post store sync] message event in message queue should be redacted")
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,14 +481,12 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::{identifiers::UserId, BaseClient, Session};
|
use crate::{identifiers::user_id, BaseClient, Session};
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
async fn get_client() -> BaseClient {
|
async fn get_client() -> BaseClient {
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:example.com").unwrap(),
|
user_id: user_id!("@example:example.com"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
|
|
@ -161,11 +161,11 @@ pub(crate) mod ser_deser {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::{collections::HashMap, convert::TryFrom};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent},
|
events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent},
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{room_id, user_id, RoomId},
|
||||||
};
|
};
|
||||||
use matrix_sdk_test::test_json;
|
use matrix_sdk_test::test_json;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
@ -176,8 +176,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize() {
|
fn serialize() {
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let mut room = Room::new(&id, &user);
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let mut room = Room::new(&id, &user);
|
let mut room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
|
|
@ -1083,10 +1083,12 @@ mod test {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use crate::{
|
use crate::{
|
||||||
events::{room::encryption::EncryptionEventContent, Unsigned},
|
events::{room::encryption::EncryptionEventContent, Unsigned},
|
||||||
identifiers::EventId,
|
|
||||||
Raw,
|
Raw,
|
||||||
};
|
};
|
||||||
use crate::{identifiers::UserId, BaseClient, Session};
|
use crate::{
|
||||||
|
identifiers::{event_id, room_id, user_id, UserId},
|
||||||
|
BaseClient, Session,
|
||||||
|
};
|
||||||
use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
|
use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
@ -1095,12 +1097,12 @@ mod test {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
use std::{convert::TryFrom, ops::Deref};
|
use std::ops::Deref;
|
||||||
|
|
||||||
async fn get_client() -> BaseClient {
|
async fn get_client() -> BaseClient {
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
@ -1109,7 +1111,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_room_id() -> RoomId {
|
fn get_room_id() -> RoomId {
|
||||||
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
|
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
|
@ -1123,7 +1125,7 @@ mod test {
|
||||||
let rooms_lock = &client.joined_rooms();
|
let rooms_lock = &client.joined_rooms();
|
||||||
let rooms = rooms_lock.read().await;
|
let rooms = rooms_lock.read().await;
|
||||||
let room = &rooms
|
let room = &rooms
|
||||||
.get(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
.get(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read()
|
.read()
|
||||||
.await;
|
.await;
|
||||||
|
@ -1154,8 +1156,8 @@ mod test {
|
||||||
async fn member_is_not_both_invited_and_joined() {
|
async fn member_is_not_both_invited_and_joined() {
|
||||||
let client = get_client().await;
|
let client = get_client().await;
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
let user_id1 = UserId::try_from("@example:localhost").unwrap();
|
let user_id1 = user_id!("@example:localhost");
|
||||||
let user_id2 = UserId::try_from("@example2:localhost").unwrap();
|
let user_id2 = user_id!("@example2:localhost");
|
||||||
|
|
||||||
let member2_invite_event = serde_json::json!({
|
let member2_invite_event = serde_json::json!({
|
||||||
"content": {
|
"content": {
|
||||||
|
@ -1263,9 +1265,9 @@ mod test {
|
||||||
|
|
||||||
let client = get_client().await;
|
let client = get_client().await;
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
let user_id1 = UserId::try_from("@example:localhost").unwrap();
|
let user_id1 = user_id!("@example:localhost");
|
||||||
let user_id2 = UserId::try_from("@example2:localhost").unwrap();
|
let user_id2 = user_id!("@example2:localhost");
|
||||||
let user_id3 = UserId::try_from("@example3:localhost").unwrap();
|
let user_id3 = user_id!("@example3:localhost");
|
||||||
|
|
||||||
let member2_join_event = serde_json::json!({
|
let member2_join_event = serde_json::json!({
|
||||||
"content": {
|
"content": {
|
||||||
|
@ -1544,7 +1546,7 @@ mod test {
|
||||||
async fn room_events() {
|
async fn room_events() {
|
||||||
let client = get_client().await;
|
let client = get_client().await;
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
|
|
||||||
let mut response = EventBuilder::default()
|
let mut response = EventBuilder::default()
|
||||||
.add_state_event(EventsJson::Member)
|
.add_state_event(EventsJson::Member)
|
||||||
|
@ -1626,7 +1628,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
@ -1650,7 +1652,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
@ -1680,10 +1682,7 @@ mod test {
|
||||||
) = &queue.msgs[0]
|
) = &queue.msgs[0]
|
||||||
{
|
{
|
||||||
// this is the id from the message event in the sync response
|
// this is the id from the message event in the sync response
|
||||||
assert_eq!(
|
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
|
||||||
event.event_id,
|
|
||||||
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
panic!("message event in message queue should be redacted")
|
panic!("message event in message queue should be redacted")
|
||||||
}
|
}
|
||||||
|
@ -1696,7 +1695,7 @@ mod test {
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
let mut response = sync_response(SyncResponseFile::DefaultWithSummary);
|
let mut response = sync_response(SyncResponseFile::DefaultWithSummary);
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
|
@ -1712,7 +1711,7 @@ mod test {
|
||||||
content.rotation_period_msgs = Some(100u32.into());
|
content.rotation_period_msgs = Some(100u32.into());
|
||||||
|
|
||||||
let event = SyncStateEvent {
|
let event = SyncStateEvent {
|
||||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
event_id: event_id!("$h29iv0s8:example.com"),
|
||||||
origin_server_ts: SystemTime::now(),
|
origin_server_ts: SystemTime::now(),
|
||||||
sender: user_id,
|
sender: user_id,
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
|
|
|
@ -155,21 +155,18 @@ mod test {
|
||||||
use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
|
use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{room_id, user_id, RoomId},
|
||||||
|
js_int::int,
|
||||||
BaseClient, Session,
|
BaseClient, Session,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::js_int::int;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
async fn get_client() -> BaseClient {
|
async fn get_client() -> BaseClient {
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
user_id: user_id!("@example:localhost"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
let client = BaseClient::new().unwrap();
|
let client = BaseClient::new().unwrap();
|
||||||
|
@ -180,7 +177,7 @@ mod test {
|
||||||
// TODO: Move this to EventBuilder since it's a magic room ID used in EventBuilder's example
|
// TODO: Move this to EventBuilder since it's a magic room ID used in EventBuilder's example
|
||||||
// events.
|
// events.
|
||||||
fn test_room_id() -> RoomId {
|
fn test_room_id() -> RoomId {
|
||||||
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
|
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
|
@ -201,7 +198,7 @@ mod test {
|
||||||
|
|
||||||
let member = room
|
let member = room
|
||||||
.joined_members
|
.joined_members
|
||||||
.get(&UserId::try_from("@example:localhost").unwrap())
|
.get(&user_id!("@example:localhost"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(member.power_level, Some(int!(100)));
|
assert_eq!(member.power_level, Some(int!(100)));
|
||||||
}
|
}
|
||||||
|
@ -232,7 +229,7 @@ mod test {
|
||||||
|
|
||||||
let member = room
|
let member = room
|
||||||
.joined_members
|
.joined_members
|
||||||
.get(&UserId::try_from("@example:localhost").unwrap())
|
.get(&user_id!("@example:localhost"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(member.display_name.as_ref().unwrap(), "example");
|
assert_eq!(member.display_name.as_ref().unwrap(), "example");
|
||||||
|
@ -249,7 +246,7 @@ mod test {
|
||||||
|
|
||||||
let member = room
|
let member = room
|
||||||
.joined_members
|
.joined_members
|
||||||
.get(&UserId::try_from("@example:localhost").unwrap())
|
.get(&user_id!("@example:localhost"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(member.display_name.as_ref().unwrap(), "changed");
|
assert_eq!(member.display_name.as_ref().unwrap(), "changed");
|
||||||
|
@ -275,7 +272,7 @@ mod test {
|
||||||
|
|
||||||
let member = room
|
let member = room
|
||||||
.joined_members
|
.joined_members
|
||||||
.get(&UserId::try_from("@example:localhost").unwrap())
|
.get(&user_id!("@example:localhost"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(member.power_level, Some(int!(100)));
|
assert_eq!(member.power_level, Some(int!(100)));
|
||||||
|
|
|
@ -217,12 +217,12 @@ impl StateStore for JsonStore {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::{convert::TryFrom, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{room_id, user_id},
|
||||||
push::Ruleset,
|
push::Ruleset,
|
||||||
BaseClient, BaseClientConfig, Session,
|
BaseClient, BaseClientConfig, Session,
|
||||||
};
|
};
|
||||||
|
@ -234,7 +234,7 @@ mod test {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
|
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let sess = Session {
|
let sess = Session {
|
||||||
access_token: "32nj9zu034btz90".to_string(),
|
access_token: "32nj9zu034btz90".to_string(),
|
||||||
|
@ -266,8 +266,8 @@ mod test {
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
let store = JsonStore::open(path).unwrap();
|
let store = JsonStore::open(path).unwrap();
|
||||||
|
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
store
|
store
|
||||||
|
@ -284,8 +284,8 @@ mod test {
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
let store = JsonStore::open(path).unwrap();
|
let store = JsonStore::open(path).unwrap();
|
||||||
|
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
store
|
store
|
||||||
|
@ -302,8 +302,8 @@ mod test {
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
let store = JsonStore::open(path).unwrap();
|
let store = JsonStore::open(path).unwrap();
|
||||||
|
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
store
|
store
|
||||||
|
@ -320,8 +320,8 @@ mod test {
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
let store = JsonStore::open(path).unwrap();
|
let store = JsonStore::open(path).unwrap();
|
||||||
|
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
store
|
store
|
||||||
|
@ -344,8 +344,8 @@ mod test {
|
||||||
let path: &Path = dir.path();
|
let path: &Path = dir.path();
|
||||||
let store = JsonStore::open(path).unwrap();
|
let store = JsonStore::open(path).unwrap();
|
||||||
|
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
store
|
store
|
||||||
|
@ -368,7 +368,7 @@ mod test {
|
||||||
|
|
||||||
let session = Session {
|
let session = Session {
|
||||||
access_token: "1234".to_owned(),
|
access_token: "1234".to_owned(),
|
||||||
user_id: UserId::try_from("@cheeky_monkey:matrix.org").unwrap(),
|
user_id: user_id!("@cheeky_monkey:matrix.org"),
|
||||||
device_id: "DEVICEID".into(),
|
device_id: "DEVICEID".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ mod test {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*client.ignored_users.read().await,
|
*client.ignored_users.read().await,
|
||||||
vec![UserId::try_from("@someone:example.org").unwrap()]
|
vec![user_id!("@someone:example.org")]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,14 +121,14 @@ pub trait StateStore {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::{collections::HashMap, convert::TryFrom};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::identifiers::RoomId;
|
use crate::identifiers::{room_id, user_id};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize() {
|
fn serialize() {
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
@ -205,8 +205,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let id = RoomId::try_from("!roomid:example.com").unwrap();
|
let id = room_id!("!roomid:example.com");
|
||||||
let user = UserId::try_from("@example:example.com").unwrap();
|
let user = user_id!("@example:example.com");
|
||||||
|
|
||||||
let room = Room::new(&id, &user);
|
let room = Room::new(&id, &user);
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ pub(crate) mod test {
|
||||||
use crate::device::{Device, TrustState};
|
use crate::device::{Device, TrustState};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::keys::{DeviceKeys, KeyAlgorithm},
|
api::r0::keys::{DeviceKeys, KeyAlgorithm},
|
||||||
identifiers::UserId,
|
identifiers::user_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn device_keys() -> DeviceKeys {
|
fn device_keys() -> DeviceKeys {
|
||||||
|
@ -285,7 +285,7 @@ pub(crate) mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_a_device() {
|
fn create_a_device() {
|
||||||
let user_id = UserId::try_from("@example:localhost").unwrap();
|
let user_id = user_id!("@example:localhost");
|
||||||
let device_id = "BNYQQWUMXO";
|
let device_id = "BNYQQWUMXO";
|
||||||
|
|
||||||
let device = get_device();
|
let device = get_device();
|
||||||
|
|
|
@ -1294,13 +1294,13 @@ mod test {
|
||||||
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
|
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
|
||||||
ToDeviceEvent, Unsigned,
|
ToDeviceEvent, Unsigned,
|
||||||
},
|
},
|
||||||
identifiers::{DeviceId, EventId, RoomId, UserId},
|
identifiers::{event_id, room_id, user_id, DeviceId, UserId},
|
||||||
Raw,
|
Raw,
|
||||||
};
|
};
|
||||||
use matrix_sdk_test::test_json;
|
use matrix_sdk_test::test_json;
|
||||||
|
|
||||||
fn alice_id() -> UserId {
|
fn alice_id() -> UserId {
|
||||||
UserId::try_from("@alice:example.org").unwrap()
|
user_id!("@alice:example.org")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alice_device_id() -> Box<DeviceId> {
|
fn alice_device_id() -> Box<DeviceId> {
|
||||||
|
@ -1536,7 +1536,7 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn tests_session_invalidation() {
|
async fn tests_session_invalidation() {
|
||||||
let mut machine = OlmMachine::new(&user_id(), &alice_device_id());
|
let mut machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||||
let room_id = RoomId::try_from("!test:example.org").unwrap();
|
let room_id = room_id!("!test:example.org");
|
||||||
|
|
||||||
machine
|
machine
|
||||||
.create_outbound_group_session(&room_id)
|
.create_outbound_group_session(&room_id)
|
||||||
|
@ -1632,7 +1632,7 @@ mod test {
|
||||||
async fn test_keys_query() {
|
async fn test_keys_query() {
|
||||||
let (mut machine, _) = get_prepared_machine().await;
|
let (mut machine, _) = get_prepared_machine().await;
|
||||||
let response = keys_query_response();
|
let response = keys_query_response();
|
||||||
let alice_id = UserId::try_from("@alice:example.org").unwrap();
|
let alice_id = user_id!("@alice:example.org");
|
||||||
let alice_device_id: &DeviceId = "JLAFKJWSCS".into();
|
let alice_device_id: &DeviceId = "JLAFKJWSCS".into();
|
||||||
|
|
||||||
let alice_devices = machine
|
let alice_devices = machine
|
||||||
|
@ -1753,7 +1753,7 @@ mod test {
|
||||||
async fn test_room_key_sharing() {
|
async fn test_room_key_sharing() {
|
||||||
let (mut alice, mut bob) = get_machine_pair_with_session().await;
|
let (mut alice, mut bob) = get_machine_pair_with_session().await;
|
||||||
|
|
||||||
let room_id = RoomId::try_from("!test:example.org").unwrap();
|
let room_id = room_id!("!test:example.org");
|
||||||
|
|
||||||
let to_device_requests = alice
|
let to_device_requests = alice
|
||||||
.share_group_session(&room_id, [bob.user_id.clone()].iter())
|
.share_group_session(&room_id, [bob.user_id.clone()].iter())
|
||||||
|
@ -1798,7 +1798,7 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_megolm_encryption() {
|
async fn test_megolm_encryption() {
|
||||||
let (mut alice, mut bob) = get_machine_pair_with_setup_sessions().await;
|
let (mut alice, mut bob) = get_machine_pair_with_setup_sessions().await;
|
||||||
let room_id = RoomId::try_from("!test:example.org").unwrap();
|
let room_id = room_id!("!test:example.org");
|
||||||
|
|
||||||
let to_device_requests = alice
|
let to_device_requests = alice
|
||||||
.share_group_session(&room_id, [bob.user_id().clone()].iter())
|
.share_group_session(&room_id, [bob.user_id().clone()].iter())
|
||||||
|
@ -1819,7 +1819,7 @@ mod test {
|
||||||
let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap();
|
let encrypted_content = alice.encrypt(&room_id, content.clone()).await.unwrap();
|
||||||
|
|
||||||
let event = SyncMessageEvent {
|
let event = SyncMessageEvent {
|
||||||
event_id: EventId::try_from("$xxxxx:example.org").unwrap(),
|
event_id: event_id!("$xxxxx:example.org"),
|
||||||
origin_server_ts: SystemTime::now(),
|
origin_server_ts: SystemTime::now(),
|
||||||
sender: alice.user_id().clone(),
|
sender: alice.user_id().clone(),
|
||||||
content: encrypted_content,
|
content: encrypted_content,
|
||||||
|
|
|
@ -212,14 +212,12 @@ impl DeviceStore {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::test::get_device,
|
device::test::get_device,
|
||||||
memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
|
memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
|
||||||
olm::{test::get_account_and_session, InboundGroupSession},
|
olm::{test::get_account_and_session, InboundGroupSession},
|
||||||
};
|
};
|
||||||
use matrix_sdk_common::identifiers::RoomId;
|
use matrix_sdk_common::identifiers::room_id;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_session_store() {
|
async fn test_session_store() {
|
||||||
|
@ -256,7 +254,7 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_group_session_store() {
|
async fn test_group_session_store() {
|
||||||
let (account, _) = get_account_and_session().await;
|
let (account, _) = get_account_and_session().await;
|
||||||
let room_id = RoomId::try_from("!test:localhost").unwrap();
|
let room_id = room_id!("!test:localhost");
|
||||||
|
|
||||||
let (outbound, _) = account.create_group_session_pair(&room_id).await;
|
let (outbound, _) = account.create_group_session_pair(&room_id).await;
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,13 @@ pub(crate) mod test {
|
||||||
use crate::olm::{Account, InboundGroupSession, Session};
|
use crate::olm::{Account, InboundGroupSession, Session};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::keys::SignedKey,
|
api::r0::keys::SignedKey,
|
||||||
identifiers::{DeviceId, RoomId, UserId},
|
identifiers::{room_id, user_id, DeviceId, UserId},
|
||||||
};
|
};
|
||||||
use olm_rs::session::OlmMessage;
|
use olm_rs::session::OlmMessage;
|
||||||
use std::{collections::BTreeMap, convert::TryFrom};
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
fn alice_id() -> UserId {
|
fn alice_id() -> UserId {
|
||||||
UserId::try_from("@alice:example.org").unwrap()
|
user_id!("@alice:example.org")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alice_device_id() -> Box<DeviceId> {
|
fn alice_device_id() -> Box<DeviceId> {
|
||||||
|
@ -39,7 +39,7 @@ pub(crate) mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bob_id() -> UserId {
|
fn bob_id() -> UserId {
|
||||||
UserId::try_from("@bob:example.org").unwrap()
|
user_id!("@bob:example.org")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bob_device_id() -> Box<DeviceId> {
|
fn bob_device_id() -> Box<DeviceId> {
|
||||||
|
@ -177,7 +177,7 @@ pub(crate) mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn group_session_creation() {
|
async fn group_session_creation() {
|
||||||
let alice = Account::new(&alice_id(), &alice_device_id());
|
let alice = Account::new(&alice_id(), &alice_device_id());
|
||||||
let room_id = RoomId::try_from("!test:localhost").unwrap();
|
let room_id = room_id!("!test:localhost");
|
||||||
|
|
||||||
let (outbound, _) = alice.create_group_session_pair(&room_id).await;
|
let (outbound, _) = alice.create_group_session_pair(&room_id).await;
|
||||||
|
|
||||||
|
|
|
@ -126,14 +126,12 @@ impl CryptoStore for MemoryStore {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::test::get_device,
|
device::test::get_device,
|
||||||
olm::{test::get_account_and_session, InboundGroupSession},
|
olm::{test::get_account_and_session, InboundGroupSession},
|
||||||
store::{memorystore::MemoryStore, CryptoStore},
|
store::{memorystore::MemoryStore, CryptoStore},
|
||||||
};
|
};
|
||||||
use matrix_sdk_common::identifiers::RoomId;
|
use matrix_sdk_common::identifiers::room_id;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_session_store() {
|
async fn test_session_store() {
|
||||||
|
@ -160,7 +158,7 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_group_session_store() {
|
async fn test_group_session_store() {
|
||||||
let (account, _) = get_account_and_session().await;
|
let (account, _) = get_account_and_session().await;
|
||||||
let room_id = RoomId::try_from("!test:localhost").unwrap();
|
let room_id = room_id!("!test:localhost");
|
||||||
|
|
||||||
let (outbound, _) = account.create_group_session_pair(&room_id).await;
|
let (outbound, _) = account.create_group_session_pair(&room_id).await;
|
||||||
let inbound = InboundGroupSession::new(
|
let inbound = InboundGroupSession::new(
|
||||||
|
|
|
@ -896,16 +896,16 @@ mod test {
|
||||||
use crate::{device::test::get_device, olm::GroupSessionKey};
|
use crate::{device::test::get_device, olm::GroupSessionKey};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::keys::SignedKey,
|
api::r0::keys::SignedKey,
|
||||||
identifiers::{DeviceId, UserId},
|
identifiers::{room_id, user_id, DeviceId, UserId},
|
||||||
};
|
};
|
||||||
use olm_rs::outbound_group_session::OlmOutboundGroupSession;
|
use olm_rs::outbound_group_session::OlmOutboundGroupSession;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use super::{Account, CryptoStore, InboundGroupSession, RoomId, Session, SqliteStore, TryFrom};
|
use super::{Account, CryptoStore, InboundGroupSession, Session, SqliteStore};
|
||||||
|
|
||||||
fn example_user_id() -> UserId {
|
fn example_user_id() -> UserId {
|
||||||
UserId::try_from("@example:localhost").unwrap()
|
user_id!("@example:localhost")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn example_device_id() -> &'static DeviceId {
|
fn example_device_id() -> &'static DeviceId {
|
||||||
|
@ -944,7 +944,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alice_id() -> UserId {
|
fn alice_id() -> UserId {
|
||||||
UserId::try_from("@alice:example.org").unwrap()
|
user_id!("@alice:example.org")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alice_device_id() -> Box<DeviceId> {
|
fn alice_device_id() -> Box<DeviceId> {
|
||||||
|
@ -952,7 +952,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bob_id() -> UserId {
|
fn bob_id() -> UserId {
|
||||||
UserId::try_from("@bob:example.org").unwrap()
|
user_id!("@bob:example.org")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bob_device_id() -> Box<DeviceId> {
|
fn bob_device_id() -> Box<DeviceId> {
|
||||||
|
@ -1144,7 +1144,7 @@ mod test {
|
||||||
let session = InboundGroupSession::new(
|
let session = InboundGroupSession::new(
|
||||||
identity_keys.curve25519(),
|
identity_keys.curve25519(),
|
||||||
identity_keys.ed25519(),
|
identity_keys.ed25519(),
|
||||||
&RoomId::try_from("!test:localhost").unwrap(),
|
&room_id!("!test:localhost"),
|
||||||
GroupSessionKey(outbound_session.session_key()),
|
GroupSessionKey(outbound_session.session_key()),
|
||||||
)
|
)
|
||||||
.expect("Can't create session");
|
.expect("Can't create session");
|
||||||
|
@ -1164,7 +1164,7 @@ mod test {
|
||||||
let session = InboundGroupSession::new(
|
let session = InboundGroupSession::new(
|
||||||
identity_keys.curve25519(),
|
identity_keys.curve25519(),
|
||||||
identity_keys.ed25519(),
|
identity_keys.ed25519(),
|
||||||
&RoomId::try_from("!test:localhost").unwrap(),
|
&room_id!("!test:localhost"),
|
||||||
GroupSessionKey(outbound_session.session_key()),
|
GroupSessionKey(outbound_session.session_key()),
|
||||||
)
|
)
|
||||||
.expect("Can't create session");
|
.expect("Can't create session");
|
||||||
|
|
|
@ -8,7 +8,7 @@ use matrix_sdk_common::{
|
||||||
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
|
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
|
||||||
AnySyncStateEvent,
|
AnySyncStateEvent,
|
||||||
},
|
},
|
||||||
identifiers::RoomId,
|
identifiers::{room_id, RoomId},
|
||||||
};
|
};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
|
@ -138,10 +138,7 @@ impl EventBuilder {
|
||||||
|
|
||||||
let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
|
let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
|
||||||
|
|
||||||
self.add_joined_event(
|
self.add_joined_event(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"), event);
|
||||||
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
|
|
||||||
event,
|
|
||||||
);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +216,7 @@ impl EventBuilder {
|
||||||
/// Builds a `SyncResponse` containing the events we queued so far. The next response returned
|
/// 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.
|
/// by `build_sync_response` will then be empty if no further events were queued.
|
||||||
pub fn build_sync_response(&mut self) -> SyncResponse {
|
pub fn build_sync_response(&mut self) -> SyncResponse {
|
||||||
let main_room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
|
let main_room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||||
|
|
||||||
// First time building a sync response, so initialize the `prev_batch` to a default one.
|
// First time building a sync response, so initialize the `prev_batch` to a default one.
|
||||||
let prev_batch = self.generate_sync_token();
|
let prev_batch = self.generate_sync_token();
|
||||||
|
|
Loading…
Reference in New Issue