Use identifier macros in tests

master
Jonas Platte 2020-08-05 00:56:26 +02:00
parent 591388d13e
commit d016ce1848
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
16 changed files with 158 additions and 188 deletions

View File

@ -842,7 +842,7 @@ impl Client {
/// ```no_run
/// # use std::convert::TryFrom;
/// 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::message::get_message_events::Direction;
/// # use url::Url;
@ -850,7 +850,7 @@ impl Client {
///
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// let mut builder = MessagesRequestBuilder::new(
/// RoomId::try_from("!roomid:example.com").unwrap(),
/// room_id!("!roomid:example.com"),
/// "t47429-4392820_219380_26003_2265".to_string(),
/// );
///
@ -972,13 +972,13 @@ impl Client {
/// # use matrix_sdk::{Client, SyncSettings};
/// # use url::Url;
/// # use futures::executor::block_on;
/// # use matrix_sdk::identifiers::RoomId;
/// # use matrix_sdk::identifiers::room_id;
/// # use std::convert::TryFrom;
/// use matrix_sdk::events::room::message::{MessageEventContent, TextMessageEventContent};
/// # block_on(async {
/// # let homeserver = Url::parse("http://localhost:8080").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;
///
/// let content = MessageEventContent::Text(TextMessageEventContent::plain("Hello world"));
@ -1077,13 +1077,13 @@ impl Client {
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let mut client = Client::new(homeserver).unwrap();
/// 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
/// // See https://docs.rs/ruma-client-api/latest/ruma_client_api/index.html
/// // for all available Endpoints
/// 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()
@ -1447,7 +1447,7 @@ mod test {
use crate::events::room::message::TextMessageEventContent;
use crate::{
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
identifiers::{event_id, room_id, user_id},
RegistrationBuilder, RoomListFilterBuilder,
};
@ -1456,22 +1456,17 @@ mod test {
use mockito::{mock, Matcher};
use tempfile::tempdir;
use std::{
convert::{TryFrom, TryInto},
path::Path,
str::FromStr,
time::Duration,
};
use std::{convert::TryInto, path::Path, str::FromStr, time::Duration};
#[tokio::test]
async fn test_join_leave_room() {
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 {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -1536,7 +1531,7 @@ mod test {
let session = Session {
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(),
};
@ -1564,7 +1559,7 @@ mod test {
async fn room_creation() {
let session = Session {
access_token: "12345".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
@ -1581,7 +1576,7 @@ mod test {
.receive_sync_response(&mut response)
.await
.unwrap();
let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
assert_eq!(
client.homeserver(),
@ -1676,7 +1671,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -1690,7 +1685,7 @@ mod test {
let client = Client::new(homeserver).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!(
// 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 {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -1719,7 +1714,7 @@ mod test {
let client = Client::new(homeserver).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!(
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId field
@ -1728,7 +1723,7 @@ mod test {
.await
.unwrap()
.room_id,
RoomId::try_from("!testroom:example.org").unwrap()
room_id!("!testroom:example.org")
);
}
@ -1736,8 +1731,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn invite_user_by_id() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -1763,8 +1758,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn invite_user_by_3pid() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -1825,7 +1820,7 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn room_search_filtered() {
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 {
access_token: "1234".to_owned(),
@ -1864,7 +1859,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -1879,7 +1874,7 @@ mod test {
let client = Client::new(homeserver).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();
if let leave_room::Response = response {
@ -1895,8 +1890,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn ban_user() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -1930,8 +1925,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn kick_user() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -1965,8 +1960,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn forget_room() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -2000,9 +1995,9 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn read_receipt() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user_id = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let event_id = EventId::try_from("$xxxxxx:example.org").unwrap();
let user_id = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let event_id = event_id!("$xxxxxx:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -2036,9 +2031,9 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn read_marker() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user_id = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let event_id = EventId::try_from("$xxxxxx:example.org").unwrap();
let user_id = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let event_id = event_id!("$xxxxxx:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -2072,8 +2067,8 @@ mod test {
#[allow(irrefutable_let_patterns)]
async fn typing_notice() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -2116,8 +2111,8 @@ mod test {
use matrix_sdk_common::uuid::Uuid;
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let user = UserId::try_from("@example:localhost").unwrap();
let room_id = RoomId::try_from("!testroom:example.org").unwrap();
let user = user_id!("@example:localhost");
let room_id = room_id!("!testroom:example.org");
let session = Session {
access_token: "1234".to_owned(),
@ -2147,10 +2142,7 @@ mod test {
.await
.unwrap();
assert_eq!(
EventId::try_from("$h29iv0s8:example.com").unwrap(),
response.event_id
)
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id)
}
#[tokio::test]
@ -2159,7 +2151,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2181,7 +2173,7 @@ mod test {
let rooms_lock = &client.base_client.joined_rooms();
let rooms = rooms_lock.read().await;
let room = &rooms
.get(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
.get(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
.unwrap()
.read()
.await;
@ -2196,7 +2188,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2224,11 +2216,9 @@ mod test {
#[tokio::test]
async fn invited_rooms() {
use std::convert::TryFrom;
let session = Session {
access_token: "12345".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2251,18 +2241,16 @@ mod test {
assert!(!client.invited_rooms().read().await.is_empty());
assert!(client
.get_invited_room(&RoomId::try_from("!696r7674:example.com").unwrap())
.get_invited_room(&room_id!("!696r7674:example.com"))
.await
.is_some());
}
#[tokio::test]
async fn left_rooms() {
use std::convert::TryFrom;
let session = Session {
access_token: "12345".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2285,7 +2273,7 @@ mod test {
assert!(client.invited_rooms().read().await.is_empty());
assert!(client
.get_left_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
.get_left_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
.await
.is_some())
}
@ -2296,7 +2284,7 @@ mod test {
let session = Session {
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(),
};
@ -2343,7 +2331,7 @@ mod test {
// This is commented out because this field is private...
// assert_eq!(
// *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 {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2423,7 +2411,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -2448,7 +2436,7 @@ mod test {
}
assert_eq!(vec!["tutorial"], names);
let room = client
.get_joined_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
.await
.unwrap();

View File

@ -169,17 +169,17 @@ impl Into<create_room::Request> for RoomBuilder {
/// # use std::convert::TryFrom;
/// # use matrix_sdk::{Client, MessagesRequestBuilder};
/// # 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;
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// # let mut rt = tokio::runtime::Runtime::new().unwrap();
/// # 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 mut client = Client::new(homeserver).unwrap();
///
/// let mut builder = MessagesRequestBuilder::new(
/// RoomId::try_from("!roomid:example.com").unwrap(),
/// room_id!("!roomid:example.com"),
/// "t47429-4392820_219380_26003_2265".to_string(),
/// );
///
@ -457,14 +457,13 @@ mod test {
use crate::{
api::r0::filter::{LazyLoadOptions, RoomEventFilter},
events::room::power_levels::NotificationPowerLevels,
identifiers::RoomId,
identifiers::{room_id, user_id},
js_int::Int,
Client, Session,
};
use matrix_sdk_test::test_json;
use mockito::{mock, Matcher};
use std::convert::TryFrom;
use url::Url;
#[tokio::test]
@ -478,7 +477,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
@ -526,12 +525,12 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let mut builder = MessagesRequestBuilder::new(
RoomId::try_from("!roomid:example.com").unwrap(),
room_id!("!roomid:example.com"),
"t47429-4392820_219380_26003_2265".to_string(),
);
builder

View File

@ -1868,9 +1868,11 @@ impl BaseClient {
#[cfg(test)]
mod test {
#[cfg(feature = "messages")]
use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw};
use crate::{
identifiers::{RoomId, UserId},
events::AnySyncRoomEvent, identifiers::event_id, BaseClientConfig, JsonStore, Raw,
};
use crate::{
identifiers::{room_id, user_id, RoomId},
BaseClient, Session,
};
use matrix_sdk_common_macros::async_trait;
@ -1886,7 +1888,7 @@ mod test {
async fn get_client() -> BaseClient {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let client = BaseClient::new().unwrap();
@ -1895,7 +1897,7 @@ mod test {
}
fn get_room_id() -> RoomId {
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
}
fn member_event() -> serde_json::Value {
@ -1955,7 +1957,7 @@ mod test {
#[async_test]
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()
.add_custom_left_event(&room_id, member_event())
.build_sync_response();
@ -1995,7 +1997,7 @@ mod test {
#[async_test]
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()
.add_custom_invited_event(&room_id, member_event())
.build_sync_response();
@ -2068,7 +2070,7 @@ mod test {
}
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 emitter = EE(Arc::clone(&passed));
@ -2393,11 +2395,11 @@ mod test {
async fn message_queue_redaction_event_store_deser() {
use std::ops::Deref;
let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
let session = Session {
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(),
};
@ -2448,10 +2450,7 @@ mod test {
) = &queue.msgs[0]
{
// this is the id from the message event in the sync response
assert_eq!(
event.event_id,
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
)
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
} else {
panic!("message event in message queue should be redacted")
}
@ -2476,10 +2475,7 @@ mod test {
) = &queue.msgs[0]
{
// this is the id from the message event in the sync response
assert_eq!(
event.event_id,
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
)
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
} else {
panic!("[post store sync] message event in message queue should be redacted")
}

View File

@ -481,14 +481,12 @@ mod test {
}
}
use crate::{identifiers::UserId, BaseClient, Session};
use std::convert::TryFrom;
use crate::{identifiers::user_id, BaseClient, Session};
async fn get_client() -> BaseClient {
let session = Session {
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(),
};
let client = BaseClient::new().unwrap();

View File

@ -161,11 +161,11 @@ pub(crate) mod ser_deser {
#[cfg(test)]
mod test {
use std::{collections::HashMap, convert::TryFrom};
use std::collections::HashMap;
use matrix_sdk_common::{
events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent},
identifiers::{RoomId, UserId},
identifiers::{room_id, user_id, RoomId},
};
use matrix_sdk_test::test_json;
#[cfg(target_arch = "wasm32")]
@ -176,8 +176,8 @@ mod test {
#[test]
fn serialize() {
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let mut room = Room::new(&id, &user);
@ -223,8 +223,8 @@ mod test {
#[test]
fn deserialize() {
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let mut room = Room::new(&id, &user);

View File

@ -1083,10 +1083,12 @@ mod test {
#[cfg(not(target_arch = "wasm32"))]
use crate::{
events::{room::encryption::EncryptionEventContent, Unsigned},
identifiers::EventId,
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};
#[cfg(not(target_arch = "wasm32"))]
@ -1095,12 +1097,12 @@ mod test {
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
use std::{convert::TryFrom, ops::Deref};
use std::ops::Deref;
async fn get_client() -> BaseClient {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let client = BaseClient::new().unwrap();
@ -1109,7 +1111,7 @@ mod test {
}
fn get_room_id() -> RoomId {
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
}
#[async_test]
@ -1123,7 +1125,7 @@ mod test {
let rooms_lock = &client.joined_rooms();
let rooms = rooms_lock.read().await;
let room = &rooms
.get(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
.get(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"))
.unwrap()
.read()
.await;
@ -1154,8 +1156,8 @@ mod test {
async fn member_is_not_both_invited_and_joined() {
let client = get_client().await;
let room_id = get_room_id();
let user_id1 = UserId::try_from("@example:localhost").unwrap();
let user_id2 = UserId::try_from("@example2:localhost").unwrap();
let user_id1 = user_id!("@example:localhost");
let user_id2 = user_id!("@example2:localhost");
let member2_invite_event = serde_json::json!({
"content": {
@ -1263,9 +1265,9 @@ mod test {
let client = get_client().await;
let room_id = get_room_id();
let user_id1 = UserId::try_from("@example:localhost").unwrap();
let user_id2 = UserId::try_from("@example2:localhost").unwrap();
let user_id3 = UserId::try_from("@example3:localhost").unwrap();
let user_id1 = user_id!("@example:localhost");
let user_id2 = user_id!("@example2:localhost");
let user_id3 = user_id!("@example3:localhost");
let member2_join_event = serde_json::json!({
"content": {
@ -1544,7 +1546,7 @@ mod test {
async fn room_events() {
let client = get_client().await;
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()
.add_state_event(EventsJson::Member)
@ -1626,7 +1628,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let client = BaseClient::new().unwrap();
@ -1650,7 +1652,7 @@ mod test {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
let client = BaseClient::new().unwrap();
@ -1680,10 +1682,7 @@ mod test {
) = &queue.msgs[0]
{
// this is the id from the message event in the sync response
assert_eq!(
event.event_id,
EventId::try_from("$152037280074GZeOm:localhost").unwrap()
)
assert_eq!(event.event_id, event_id!("$152037280074GZeOm:localhost"))
} else {
panic!("message event in message queue should be redacted")
}
@ -1696,7 +1695,7 @@ mod test {
let room_id = get_room_id();
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 {
access_token: "1234".to_owned(),
@ -1712,7 +1711,7 @@ mod test {
content.rotation_period_msgs = Some(100u32.into());
let event = SyncStateEvent {
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: SystemTime::now(),
sender: user_id,
state_key: "".into(),

View File

@ -155,21 +155,18 @@ mod test {
use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
use crate::{
identifiers::{RoomId, UserId},
identifiers::{room_id, user_id, RoomId},
js_int::int,
BaseClient, Session,
};
use crate::js_int::int;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
use std::convert::TryFrom;
async fn get_client() -> BaseClient {
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:localhost").unwrap(),
user_id: user_id!("@example:localhost"),
device_id: "DEVICEID".into(),
};
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
// events.
fn test_room_id() -> RoomId {
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
room_id!("!SVkFJHzfwvuaIEawgC:localhost")
}
#[async_test]
@ -201,7 +198,7 @@ mod test {
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.get(&user_id!("@example:localhost"))
.unwrap();
assert_eq!(member.power_level, Some(int!(100)));
}
@ -232,7 +229,7 @@ mod test {
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.get(&user_id!("@example:localhost"))
.unwrap();
assert_eq!(member.display_name.as_ref().unwrap(), "example");
@ -249,7 +246,7 @@ mod test {
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.get(&user_id!("@example:localhost"))
.unwrap();
assert_eq!(member.display_name.as_ref().unwrap(), "changed");
@ -275,7 +272,7 @@ mod test {
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.get(&user_id!("@example:localhost"))
.unwrap();
assert_eq!(member.power_level, Some(int!(100)));

View File

@ -217,12 +217,12 @@ impl StateStore for JsonStore {
mod test {
use super::*;
use std::{convert::TryFrom, path::PathBuf};
use std::path::PathBuf;
use tempfile::tempdir;
use crate::{
identifiers::{RoomId, UserId},
identifiers::{room_id, user_id},
push::Ruleset,
BaseClient, BaseClientConfig, Session,
};
@ -234,7 +234,7 @@ mod test {
let dir = tempdir().unwrap();
let path: &Path = dir.path();
let user = UserId::try_from("@example:example.com").unwrap();
let user = user_id!("@example:example.com");
let sess = Session {
access_token: "32nj9zu034btz90".to_string(),
@ -266,8 +266,8 @@ mod test {
let path: &Path = dir.path();
let store = JsonStore::open(path).unwrap();
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
store
@ -284,8 +284,8 @@ mod test {
let path: &Path = dir.path();
let store = JsonStore::open(path).unwrap();
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
store
@ -302,8 +302,8 @@ mod test {
let path: &Path = dir.path();
let store = JsonStore::open(path).unwrap();
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
store
@ -320,8 +320,8 @@ mod test {
let path: &Path = dir.path();
let store = JsonStore::open(path).unwrap();
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
store
@ -344,8 +344,8 @@ mod test {
let path: &Path = dir.path();
let store = JsonStore::open(path).unwrap();
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
store
@ -368,7 +368,7 @@ mod test {
let session = Session {
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(),
};
@ -397,7 +397,7 @@ mod test {
);
assert_eq!(
*client.ignored_users.read().await,
vec![UserId::try_from("@someone:example.org").unwrap()]
vec![user_id!("@someone:example.org")]
);
}
}

View File

@ -121,14 +121,14 @@ pub trait StateStore {
mod test {
use super::*;
use std::{collections::HashMap, convert::TryFrom};
use std::collections::HashMap;
use crate::identifiers::RoomId;
use crate::identifiers::{room_id, user_id};
#[test]
fn serialize() {
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);
@ -205,8 +205,8 @@ mod test {
#[test]
fn deserialize() {
let id = RoomId::try_from("!roomid:example.com").unwrap();
let user = UserId::try_from("@example:example.com").unwrap();
let id = room_id!("!roomid:example.com");
let user = user_id!("@example:example.com");
let room = Room::new(&id, &user);

View File

@ -250,7 +250,7 @@ pub(crate) mod test {
use crate::device::{Device, TrustState};
use matrix_sdk_common::{
api::r0::keys::{DeviceKeys, KeyAlgorithm},
identifiers::UserId,
identifiers::user_id,
};
fn device_keys() -> DeviceKeys {
@ -285,7 +285,7 @@ pub(crate) mod test {
#[test]
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 = get_device();

View File

@ -1294,13 +1294,13 @@ mod test {
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
ToDeviceEvent, Unsigned,
},
identifiers::{DeviceId, EventId, RoomId, UserId},
identifiers::{event_id, room_id, user_id, DeviceId, UserId},
Raw,
};
use matrix_sdk_test::test_json;
fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap()
user_id!("@alice:example.org")
}
fn alice_device_id() -> Box<DeviceId> {
@ -1536,7 +1536,7 @@ mod test {
#[tokio::test]
async fn tests_session_invalidation() {
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
.create_outbound_group_session(&room_id)
@ -1632,7 +1632,7 @@ mod test {
async fn test_keys_query() {
let (mut machine, _) = get_prepared_machine().await;
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_devices = machine
@ -1753,7 +1753,7 @@ mod test {
async fn test_room_key_sharing() {
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
.share_group_session(&room_id, [bob.user_id.clone()].iter())
@ -1798,7 +1798,7 @@ mod test {
#[tokio::test]
async fn test_megolm_encryption() {
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
.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 event = SyncMessageEvent {
event_id: EventId::try_from("$xxxxx:example.org").unwrap(),
event_id: event_id!("$xxxxx:example.org"),
origin_server_ts: SystemTime::now(),
sender: alice.user_id().clone(),
content: encrypted_content,

View File

@ -212,14 +212,12 @@ impl DeviceStore {
#[cfg(test)]
mod test {
use std::convert::TryFrom;
use crate::{
device::test::get_device,
memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
olm::{test::get_account_and_session, InboundGroupSession},
};
use matrix_sdk_common::identifiers::RoomId;
use matrix_sdk_common::identifiers::room_id;
#[tokio::test]
async fn test_session_store() {
@ -256,7 +254,7 @@ mod test {
#[tokio::test]
async fn test_group_session_store() {
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;

View File

@ -25,13 +25,13 @@ pub(crate) mod test {
use crate::olm::{Account, InboundGroupSession, Session};
use matrix_sdk_common::{
api::r0::keys::SignedKey,
identifiers::{DeviceId, RoomId, UserId},
identifiers::{room_id, user_id, DeviceId, UserId},
};
use olm_rs::session::OlmMessage;
use std::{collections::BTreeMap, convert::TryFrom};
use std::collections::BTreeMap;
fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap()
user_id!("@alice:example.org")
}
fn alice_device_id() -> Box<DeviceId> {
@ -39,7 +39,7 @@ pub(crate) mod test {
}
fn bob_id() -> UserId {
UserId::try_from("@bob:example.org").unwrap()
user_id!("@bob:example.org")
}
fn bob_device_id() -> Box<DeviceId> {
@ -177,7 +177,7 @@ pub(crate) mod test {
#[tokio::test]
async fn group_session_creation() {
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;

View File

@ -126,14 +126,12 @@ impl CryptoStore for MemoryStore {
#[cfg(test)]
mod test {
use std::convert::TryFrom;
use crate::{
device::test::get_device,
olm::{test::get_account_and_session, InboundGroupSession},
store::{memorystore::MemoryStore, CryptoStore},
};
use matrix_sdk_common::identifiers::RoomId;
use matrix_sdk_common::identifiers::room_id;
#[tokio::test]
async fn test_session_store() {
@ -160,7 +158,7 @@ mod test {
#[tokio::test]
async fn test_group_session_store() {
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 inbound = InboundGroupSession::new(

View File

@ -896,16 +896,16 @@ mod test {
use crate::{device::test::get_device, olm::GroupSessionKey};
use matrix_sdk_common::{
api::r0::keys::SignedKey,
identifiers::{DeviceId, UserId},
identifiers::{room_id, user_id, DeviceId, UserId},
};
use olm_rs::outbound_group_session::OlmOutboundGroupSession;
use std::collections::BTreeMap;
use tempfile::tempdir;
use super::{Account, CryptoStore, InboundGroupSession, RoomId, Session, SqliteStore, TryFrom};
use super::{Account, CryptoStore, InboundGroupSession, Session, SqliteStore};
fn example_user_id() -> UserId {
UserId::try_from("@example:localhost").unwrap()
user_id!("@example:localhost")
}
fn example_device_id() -> &'static DeviceId {
@ -944,7 +944,7 @@ mod test {
}
fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap()
user_id!("@alice:example.org")
}
fn alice_device_id() -> Box<DeviceId> {
@ -952,7 +952,7 @@ mod test {
}
fn bob_id() -> UserId {
UserId::try_from("@bob:example.org").unwrap()
user_id!("@bob:example.org")
}
fn bob_device_id() -> Box<DeviceId> {
@ -1144,7 +1144,7 @@ mod test {
let session = InboundGroupSession::new(
identity_keys.curve25519(),
identity_keys.ed25519(),
&RoomId::try_from("!test:localhost").unwrap(),
&room_id!("!test:localhost"),
GroupSessionKey(outbound_session.session_key()),
)
.expect("Can't create session");
@ -1164,7 +1164,7 @@ mod test {
let session = InboundGroupSession::new(
identity_keys.curve25519(),
identity_keys.ed25519(),
&RoomId::try_from("!test:localhost").unwrap(),
&room_id!("!test:localhost"),
GroupSessionKey(outbound_session.session_key()),
)
.expect("Can't create session");

View File

@ -8,7 +8,7 @@ use matrix_sdk_common::{
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnySyncStateEvent,
},
identifiers::RoomId,
identifiers::{room_id, RoomId},
};
use serde_json::Value as JsonValue;
@ -138,10 +138,7 @@ impl EventBuilder {
let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
self.add_joined_event(
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
event,
);
self.add_joined_event(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"), event);
self
}
@ -219,7 +216,7 @@ impl EventBuilder {
/// 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.
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.
let prev_batch = self.generate_sync_token();