mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-12 10:00:50 -04:00
Restore timeline integration tests
The directory had the wrong name, so it wasn't detected by Cargo.
This commit is contained in:
committed by
Jonas Platte
parent
5fa2fff8e5
commit
be7e162ce1
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -3038,6 +3038,7 @@ dependencies = [
|
||||
"assert_matches",
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"ctor 0.2.0",
|
||||
"eyeball-im",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
@@ -3054,6 +3055,8 @@ dependencies = [
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"wiremock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -35,4 +35,7 @@ tracing = { workspace = true, features = ["attributes"] }
|
||||
[dev-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
assert_matches = { workspace = true }
|
||||
ctor = { workspace = true }
|
||||
matrix-sdk-test = { version = "0.6.0", path = "../../testing/matrix-sdk-test" }
|
||||
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
|
||||
wiremock = "0.5.13"
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
mod timeline;
|
||||
91
crates/matrix-sdk-ui/tests/integration/main.rs
Normal file
91
crates/matrix-sdk-ui/tests/integration/main.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
use matrix_sdk::{config::RequestConfig, Client, ClientBuilder, Session};
|
||||
use matrix_sdk_test::test_json;
|
||||
use ruma::{api::MatrixVersion, device_id, user_id};
|
||||
use serde::Serialize;
|
||||
use wiremock::{
|
||||
matchers::{header, method, path, path_regex, query_param, query_param_is_missing},
|
||||
Mock, MockServer, ResponseTemplate,
|
||||
};
|
||||
|
||||
mod timeline;
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
#[ctor::ctor]
|
||||
fn init_logging() {
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with(tracing_subscriber::fmt::layer().with_test_writer())
|
||||
.init();
|
||||
}
|
||||
|
||||
async fn test_client_builder() -> (ClientBuilder, MockServer) {
|
||||
let server = MockServer::start().await;
|
||||
let builder =
|
||||
Client::builder().homeserver_url(server.uri()).server_versions([MatrixVersion::V1_0]);
|
||||
(builder, server)
|
||||
}
|
||||
|
||||
async fn no_retry_test_client() -> (Client, MockServer) {
|
||||
let (builder, server) = test_client_builder().await;
|
||||
let client =
|
||||
builder.request_config(RequestConfig::new().disable_retry()).build().await.unwrap();
|
||||
(client, server)
|
||||
}
|
||||
|
||||
async fn logged_in_client() -> (Client, MockServer) {
|
||||
let session = Session {
|
||||
access_token: "1234".to_owned(),
|
||||
refresh_token: None,
|
||||
user_id: user_id!("@example:localhost").to_owned(),
|
||||
device_id: device_id!("DEVICEID").to_owned(),
|
||||
};
|
||||
let (client, server) = no_retry_test_client().await;
|
||||
client.restore_session(session).await.unwrap();
|
||||
|
||||
(client, server)
|
||||
}
|
||||
|
||||
/// Mount a Mock on the given server to handle the `GET /sync` endpoint with
|
||||
/// an optional `since` param that returns a 200 status code with the given
|
||||
/// response body.
|
||||
async fn mock_sync(server: &MockServer, response_body: impl Serialize, since: Option<String>) {
|
||||
let mut builder = Mock::given(method("GET"))
|
||||
.and(path("/_matrix/client/r0/sync"))
|
||||
.and(header("authorization", "Bearer 1234"));
|
||||
|
||||
if let Some(since) = since {
|
||||
builder = builder.and(query_param("since", since));
|
||||
} else {
|
||||
builder = builder.and(query_param_is_missing("since"));
|
||||
}
|
||||
|
||||
builder
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(response_body))
|
||||
.mount(server)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Mount a Mock on the given server to handle the `GET
|
||||
/// /rooms/.../state/m.room.encryption` endpoint with an option whether it
|
||||
/// should return an encryption event or not.
|
||||
async fn mock_encryption_state(server: &MockServer, is_encrypted: bool) {
|
||||
let builder = Mock::given(method("GET"))
|
||||
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/state/m.*room.*encryption.?"))
|
||||
.and(header("authorization", "Bearer 1234"));
|
||||
|
||||
if is_encrypted {
|
||||
builder
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.set_body_json(&*test_json::sync_events::ENCRYPTION_CONTENT),
|
||||
)
|
||||
.mount(server)
|
||||
.await;
|
||||
} else {
|
||||
builder
|
||||
.respond_with(ResponseTemplate::new(404).set_body_json(&*test_json::NOT_FOUND))
|
||||
.mount(server)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,15 @@ use std::{sync::Arc, time::Duration};
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use futures_util::StreamExt;
|
||||
use matrix_sdk::{
|
||||
config::SyncSettings,
|
||||
room::timeline::{
|
||||
AnyOtherFullStateEventContent, Error as TimelineError, EventSendState, PaginationOptions,
|
||||
TimelineDetails, TimelineItem, TimelineItemContent, VirtualTimelineItem,
|
||||
},
|
||||
ruma::MilliSecondsSinceUnixEpoch,
|
||||
Error,
|
||||
};
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use matrix_sdk::{config::SyncSettings, executor::spawn, ruma::MilliSecondsSinceUnixEpoch};
|
||||
use matrix_sdk_test::{
|
||||
async_test, test_json, EventBuilder, JoinedRoomBuilder, RoomAccountDataTestEvent,
|
||||
StateTestEvent, TimelineTestEvent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
AnyOtherFullStateEventContent, Error as TimelineError, EventSendState, PaginationOptions,
|
||||
RoomExt, TimelineDetails, TimelineItem, TimelineItemContent, VirtualTimelineItem,
|
||||
};
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::{
|
||||
@@ -617,7 +612,7 @@ async fn in_reply_to_details() {
|
||||
// The event doesn't exist.
|
||||
assert_matches!(
|
||||
timeline.fetch_details_for_event(event_id!("$fakeevent")).await,
|
||||
Err(Error::Timeline(TimelineError::RemoteEventNotInTimeline))
|
||||
Err(TimelineError::RemoteEventNotInTimeline)
|
||||
);
|
||||
|
||||
ev_builder.add_joined_room(
|
||||
@@ -8,6 +8,7 @@ use matrix_sdk_test::{
|
||||
async_test, EphemeralTestEvent, EventBuilder, JoinedRoomBuilder, RoomAccountDataTestEvent,
|
||||
TimelineTestEvent,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::RoomExt;
|
||||
use ruma::{
|
||||
api::client::receipt::create_receipt::v3::ReceiptType, event_id,
|
||||
events::receipt::ReceiptThread, room_id, user_id,
|
||||
@@ -3,15 +3,12 @@ use std::{pin::Pin, sync::Arc};
|
||||
use anyhow::{Context, Result};
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::{Vector, VectorDiff};
|
||||
use futures::{pin_mut, Stream, StreamExt};
|
||||
use futures_util::{pin_mut, Stream, StreamExt};
|
||||
use matrix_sdk::{
|
||||
SlidingSync, SlidingSyncList, SlidingSyncListBuilder, SlidingSyncMode, UpdateSummary,
|
||||
};
|
||||
use matrix_sdk_test::async_test;
|
||||
use matrix_sdk_ui::{
|
||||
timeline::{TimelineItem, VirtualTimelineItem},
|
||||
SlidingSyncRoomExt,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{SlidingSyncRoomExt, TimelineItem, VirtualTimelineItem};
|
||||
use ruma::{room_id, RoomId};
|
||||
use serde_json::json;
|
||||
use wiremock::{http::Method, Match, Mock, MockServer, Request, ResponseTemplate};
|
||||
@@ -231,7 +228,7 @@ async fn test_timeline_basic() -> Result<()> {
|
||||
|
||||
let room_id = room_id!("!foo:bar.org");
|
||||
|
||||
create_one_room(&server, &sliding_sync, &mut stream, room_id, "Room Name".to_string()).await?;
|
||||
create_one_room(&server, &sliding_sync, &mut stream, room_id, "Room Name".to_owned()).await?;
|
||||
|
||||
let (timeline_items, mut timeline_stream) = timeline(&sliding_sync, room_id).await?;
|
||||
assert!(timeline_items.is_empty());
|
||||
@@ -278,7 +275,7 @@ async fn test_timeline_duplicated_events() -> Result<()> {
|
||||
|
||||
let room_id = room_id!("!foo:bar.org");
|
||||
|
||||
create_one_room(&server, &sliding_sync, &mut stream, room_id, "Room Name".to_string()).await?;
|
||||
create_one_room(&server, &sliding_sync, &mut stream, room_id, "Room Name".to_owned()).await?;
|
||||
|
||||
let (_, mut timeline_stream) = timeline(&sliding_sync, room_id).await?;
|
||||
|
||||
Reference in New Issue
Block a user