Files
matrix-rust-sdk/testing/matrix-sdk-test/src/lib.rs
T
Nicolas Mauri 6961a7fb36 Fix is_user_mention_enabled and is_room_mention_enabled (#2357)
* Fix is_user_mention_enabled, is_room_mention_enabled

* Fix: XXX comments in UnitTests

* Update comments

* UnitTests: code refactoring
2023-08-01 14:43:32 +02:00

46 lines
1.5 KiB
Rust

use http::Response;
pub use matrix_sdk_test_macros::async_test;
use ruma::api::{client::sync::sync_events::v3::Response as SyncResponse, IncomingResponse};
use serde_json::Value as JsonValue;
#[cfg(feature = "appservice")]
pub mod appservice;
mod event_builder;
pub mod notification_settings;
pub mod test_json;
pub use event_builder::{
bulk_room_members, EphemeralTestEvent, GlobalAccountDataTestEvent, InvitedRoomBuilder,
JoinedRoomBuilder, LeftRoomBuilder, PresenceTestEvent, RoomAccountDataTestEvent,
StateTestEvent, StrippedStateTestEvent, SyncResponseBuilder, TimelineTestEvent,
};
/// Embedded sync response files
pub enum SyncResponseFile {
All,
Default,
DefaultWithSummary,
Invite,
Leave,
Voip,
}
/// Get specific API responses for testing
pub fn sync_response(kind: SyncResponseFile) -> SyncResponse {
let data: &JsonValue = match kind {
SyncResponseFile::All => &test_json::MORE_SYNC,
SyncResponseFile::Default => &test_json::SYNC,
SyncResponseFile::DefaultWithSummary => &test_json::DEFAULT_SYNC_SUMMARY,
SyncResponseFile::Invite => &test_json::INVITE_SYNC,
SyncResponseFile::Leave => &test_json::LEAVE_SYNC,
SyncResponseFile::Voip => &test_json::VOIP_SYNC,
};
let response = Response::builder().body(data.to_string().as_bytes().to_vec()).unwrap();
SyncResponse::try_from_http_response(response).unwrap()
}
pub fn response_from_file(json: &JsonValue) -> Response<Vec<u8>> {
Response::builder().status(200).body(json.to_string().as_bytes().to_vec()).unwrap()
}