matrix-sdk: Move all the async client tests into the async client file.
parent
ef6458c9cd
commit
720e45509a
|
@ -1,95 +0,0 @@
|
||||||
use matrix_sdk::identifiers::{RoomId, UserId};
|
|
||||||
use matrix_sdk::{AsyncClient, Session, SyncSettings};
|
|
||||||
|
|
||||||
use mockito::{mock, Matcher};
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn login() {
|
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
|
||||||
|
|
||||||
let _m = mock("POST", "/_matrix/client/r0/login")
|
|
||||||
.with_status(200)
|
|
||||||
.with_body_from_file("../test_data/login_response.json")
|
|
||||||
.create();
|
|
||||||
|
|
||||||
let client = AsyncClient::new(homeserver, None).unwrap();
|
|
||||||
|
|
||||||
client
|
|
||||||
.login("example", "wordpass", None, None)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let logged_in = client.logged_in().await;
|
|
||||||
assert!(logged_in, "Clint should be logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn sync() {
|
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
|
||||||
|
|
||||||
let session = Session {
|
|
||||||
access_token: "1234".to_owned(),
|
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
|
||||||
device_id: "DEVICEID".to_owned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let _m = mock(
|
|
||||||
"GET",
|
|
||||||
Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()),
|
|
||||||
)
|
|
||||||
.with_status(200)
|
|
||||||
.with_body_from_file("../test_data/sync.json")
|
|
||||||
.create();
|
|
||||||
|
|
||||||
let client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
|
||||||
|
|
||||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
|
||||||
|
|
||||||
let response = client.sync(sync_settings).await.unwrap();
|
|
||||||
|
|
||||||
assert_ne!(response.next_batch, "");
|
|
||||||
|
|
||||||
assert!(client.sync_token().await.is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn room_names() {
|
|
||||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
|
||||||
|
|
||||||
let session = Session {
|
|
||||||
access_token: "1234".to_owned(),
|
|
||||||
user_id: UserId::try_from("@example:localhost").unwrap(),
|
|
||||||
device_id: "DEVICEID".to_owned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let _m = mock(
|
|
||||||
"GET",
|
|
||||||
Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()),
|
|
||||||
)
|
|
||||||
.with_status(200)
|
|
||||||
.with_body_from_file("../test_data/sync.json")
|
|
||||||
.create();
|
|
||||||
|
|
||||||
let client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
|
||||||
|
|
||||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
|
||||||
|
|
||||||
let _response = client.sync(sync_settings).await.unwrap();
|
|
||||||
|
|
||||||
let mut names = vec![];
|
|
||||||
for r in client.joined_rooms().read().await.values() {
|
|
||||||
names.push(r.read().await.display_name());
|
|
||||||
}
|
|
||||||
assert_eq!(vec!["tutorial"], names);
|
|
||||||
let room = client
|
|
||||||
.get_joined_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!("tutorial".to_string(), room.read().await.display_name());
|
|
||||||
}
|
|
|
@ -1883,4 +1883,90 @@ mod test {
|
||||||
// vec![UserId::try_from("@someone:example.org").unwrap()]
|
// vec![UserId::try_from("@someone:example.org").unwrap()]
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn login() {
|
||||||
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
|
|
||||||
|
let _m = mock("POST", "/_matrix/client/r0/login")
|
||||||
|
.with_status(200)
|
||||||
|
.with_body_from_file("../test_data/login_response.json")
|
||||||
|
.create();
|
||||||
|
|
||||||
|
let client = AsyncClient::new(homeserver, None).unwrap();
|
||||||
|
|
||||||
|
client
|
||||||
|
.login("example", "wordpass", None, None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let logged_in = client.logged_in().await;
|
||||||
|
assert!(logged_in, "Clint should be logged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn sync() {
|
||||||
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
|
|
||||||
|
let session = Session {
|
||||||
|
access_token: "1234".to_owned(),
|
||||||
|
user_id: UserId::try_from("@example:localhost").unwrap(),
|
||||||
|
device_id: "DEVICEID".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let _m = mock(
|
||||||
|
"GET",
|
||||||
|
Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()),
|
||||||
|
)
|
||||||
|
.with_status(200)
|
||||||
|
.with_body_from_file("../test_data/sync.json")
|
||||||
|
.create();
|
||||||
|
|
||||||
|
let client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
||||||
|
|
||||||
|
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||||
|
|
||||||
|
let response = client.sync(sync_settings).await.unwrap();
|
||||||
|
|
||||||
|
assert_ne!(response.next_batch, "");
|
||||||
|
|
||||||
|
assert!(client.sync_token().await.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn room_names() {
|
||||||
|
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||||
|
|
||||||
|
let session = Session {
|
||||||
|
access_token: "1234".to_owned(),
|
||||||
|
user_id: UserId::try_from("@example:localhost").unwrap(),
|
||||||
|
device_id: "DEVICEID".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let _m = mock(
|
||||||
|
"GET",
|
||||||
|
Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()),
|
||||||
|
)
|
||||||
|
.with_status(200)
|
||||||
|
.with_body_from_file("../test_data/sync.json")
|
||||||
|
.create();
|
||||||
|
|
||||||
|
let client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
||||||
|
|
||||||
|
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||||
|
|
||||||
|
let _response = client.sync(sync_settings).await.unwrap();
|
||||||
|
|
||||||
|
let mut names = vec![];
|
||||||
|
for r in client.joined_rooms().read().await.values() {
|
||||||
|
names.push(r.read().await.display_name());
|
||||||
|
}
|
||||||
|
assert_eq!(vec!["tutorial"], names);
|
||||||
|
let room = client
|
||||||
|
.get_joined_room(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!("tutorial".to_string(), room.read().await.display_name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue