tests: Test the sync method of the async client.

master
Damir Jelić 2019-11-17 21:23:01 +01:00
parent f246ab2f56
commit 3ab37ee8bd
3 changed files with 39 additions and 3 deletions

View File

@ -6,6 +6,7 @@ pub use crate::{error::Error, session::Session};
pub use reqwest::header::InvalidHeaderValue; pub use reqwest::header::InvalidHeaderValue;
pub use ruma_client_api as api; pub use ruma_client_api as api;
pub use ruma_events as events; pub use ruma_events as events;
pub use ruma_identifiers as identifiers;
mod async_client; mod async_client;
mod base_client; mod base_client;

View File

@ -1,9 +1,13 @@
use matrix_nio::{AsyncClient, AsyncClientConfig}; use matrix_nio::identifiers::UserId;
use mockito::mock; use matrix_nio::{AsyncClient, Session, SyncSettings};
use std::str::FromStr;
use mockito::{mock, Matcher};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use url::Url; use url::Url;
use std::convert::TryFrom;
use std::str::FromStr;
#[test] #[test]
fn login() { fn login() {
let rt = Runtime::new().unwrap(); let rt = Runtime::new().unwrap();
@ -22,3 +26,30 @@ fn login() {
assert!(client.logged_in(), "Clint should be logged in"); assert!(client.logged_in(), "Clint should be logged in");
} }
#[test]
fn sync() {
let rt = Runtime::new().unwrap();
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let session = Session {
access_token: "1234".to_owned(),
user_id: UserId::try_from("@example:example.com").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("tests/data/sync.json")
.create();
let mut client = AsyncClient::new(homeserver, Some(session)).unwrap();
let sync_settings = SyncSettings::new().timeout(3000).unwrap();
rt.block_on(client.sync(sync_settings)).unwrap();
}

View File

@ -218,5 +218,9 @@
}, },
"to_device": { "to_device": {
"events": [] "events": []
},
"presence": {
"events": []
} }
} }