matrix-sdk: Use the EventBuilder in the async client tests.

master
Damir Jelić 2020-05-08 09:57:42 +02:00
parent 207fac2b49
commit 1e8ab74058
2 changed files with 33 additions and 56 deletions

View File

@ -46,6 +46,7 @@ default-features = false
features = ["sync", "time", "fs"] features = ["sync", "time", "fs"]
[dev-dependencies] [dev-dependencies]
matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" }
tokio = { version = "0.2.20", features = ["rt-threaded", "macros"] } tokio = { version = "0.2.20", features = ["rt-threaded", "macros"] }
ruma-identifiers = { version = "0.16.1", features = ["rand"] } ruma-identifiers = { version = "0.16.1", features = ["rand"] }
serde_json = "1.0.52" serde_json = "1.0.52"

View File

@ -1197,10 +1197,13 @@ mod test {
leave_room, Invite3pid, MessageEventContent, RoomIdOrAliasId, leave_room, Invite3pid, MessageEventContent, RoomIdOrAliasId,
}; };
use super::{AsyncClient, AsyncClientConfig, Session, SyncSettings, Url}; use super::{AsyncClient, AsyncClientConfig, Session, SyncSettings, Url};
use crate::events::collections::all::RoomEvent;
use crate::events::room::member::MembershipState; use crate::events::room::member::MembershipState;
use crate::events::room::message::TextMessageEventContent; use crate::events::room::message::TextMessageEventContent;
use crate::identifiers::{EventId, RoomId, UserId}; use crate::identifiers::{EventId, RoomId, UserId};
use matrix_sdk_base::JsonStore; use matrix_sdk_base::JsonStore;
use matrix_sdk_test::EventBuilder;
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};
use std::convert::TryFrom; use std::convert::TryFrom;
@ -1236,66 +1239,39 @@ mod test {
// assert_eq!(1, ignored_users.len()) // assert_eq!(1, ignored_users.len())
} }
// #[tokio::test] #[tokio::test]
// async fn client_runner() { async fn room_creation() {
// let session = crate::Session { let session = crate::Session {
// access_token: "12345".to_owned(), access_token: "12345".to_owned(),
// user_id: UserId::try_from("@example:localhost").unwrap(), user_id: UserId::try_from("@example:localhost").unwrap(),
// device_id: "DEVICEID".to_owned(), device_id: "DEVICEID".to_owned(),
// }; };
// let homeserver = url::Url::parse(&mockito::server_url()).unwrap(); let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
// let client = AsyncClient::new(homeserver, Some(session)).unwrap(); let client = AsyncClient::new(homeserver, Some(session)).unwrap();
// let rid = RoomId::try_from("!roomid:room.com").unwrap(); let mut response = EventBuilder::default()
// let uid = UserId::try_from("@example:localhost").unwrap(); .add_room_event_from_file("../test_data/events/member.json", RoomEvent::RoomMember)
.add_room_event_from_file(
"../test_data/events/power_levels.json",
RoomEvent::RoomPowerLevels,
)
.build_sync_response();
// let mut bld = EventBuilder::default() client
// .add_room_event_from_file("../test_data/events/member.json", RoomEvent::RoomMember) .base_client
// .add_room_event_from_file( .receive_sync_response(&mut response)
// "../test_data/events/power_levels.json", .await
// RoomEvent::RoomPowerLevels, .unwrap();
// ) let room_id = RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap();
// .build_client_runner(rid, uid);
// let cli = bld.set_client(client).to_client().await; assert_eq!(
client.homeserver(),
&Url::parse(&mockito::server_url()).unwrap()
);
// assert_eq!( let room = client.get_joined_room(&room_id).await;
// cli.homeserver(), assert!(room.is_some());
// &Url::parse(&mockito::server_url()).unwrap() }
// );
// }
// #[tokio::test]
// async fn mock_runner() {
// use std::convert::TryFrom;
// let session = crate::Session {
// access_token: "12345".to_owned(),
// user_id: UserId::try_from("@example:localhost").unwrap(),
// device_id: "DEVICEID".to_owned(),
// };
// let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
// let client = AsyncClient::new(homeserver, Some(session)).unwrap();
// let mut bld = EventBuilder::default()
// .add_room_event_from_file("../test_data/events/member.json", RoomEvent::RoomMember)
// .add_room_event_from_file(
// "../test_data/events/power_levels.json",
// RoomEvent::RoomPowerLevels,
// )
// .build_mock_runner(
// "GET",
// mockito::Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()),
// );
// let cli = bld.set_client(client).to_client().await.unwrap();
// assert_eq!(
// cli.homeserver(),
// &Url::parse(&mockito::server_url()).unwrap()
// );
// }
#[tokio::test] #[tokio::test]
async fn login_error() { async fn login_error() {