From 378776ed5ea2e4bfe9aaca44b51a8f3f5fbf196a Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 19 Nov 2024 16:53:50 +0100 Subject: [PATCH] task: move the `EventFactory` to the `matrix-sdk-test` crate This makes it available to the crypto crate, by lowering it into the local dependency tree. --- Cargo.lock | 4 +++- benchmarks/benches/room_bench.rs | 9 +++++---- crates/matrix-sdk-ui/src/timeline/event_item/mod.rs | 6 ++++-- crates/matrix-sdk-ui/src/timeline/tests/echo.rs | 7 ++----- crates/matrix-sdk-ui/src/timeline/tests/mod.rs | 5 +++-- crates/matrix-sdk-ui/src/timeline/tests/reactions.rs | 4 ++-- .../src/timeline/tests/read_receipts.rs | 3 +-- .../matrix-sdk-ui/tests/integration/timeline/echo.rs | 10 ++++------ .../matrix-sdk-ui/tests/integration/timeline/edit.rs | 7 +++---- .../tests/integration/timeline/focus_event.rs | 8 ++++---- .../tests/integration/timeline/media.rs | 6 ++---- .../matrix-sdk-ui/tests/integration/timeline/mod.rs | 5 ++--- .../tests/integration/timeline/pinned_event.rs | 12 ++++++------ .../tests/integration/timeline/reactions.rs | 6 ++---- .../tests/integration/timeline/replies.rs | 9 +++------ .../tests/integration/timeline/subscribe.rs | 9 +++------ crates/matrix-sdk/src/event_cache/deduplicator.rs | 2 +- crates/matrix-sdk/src/event_cache/mod.rs | 4 ++-- crates/matrix-sdk/src/event_cache/paginator.rs | 4 ++-- crates/matrix-sdk/src/event_cache/room/events.rs | 2 +- crates/matrix-sdk/src/event_cache/room/mod.rs | 4 ++-- crates/matrix-sdk/src/room/edit.rs | 4 ++-- crates/matrix-sdk/src/test_utils/mod.rs | 2 -- crates/matrix-sdk/tests/integration/event_cache.rs | 5 +++-- crates/matrix-sdk/tests/integration/room/common.rs | 11 ++++------- crates/matrix-sdk/tests/integration/room/joined.rs | 3 ++- crates/matrix-sdk/tests/integration/send_queue.rs | 10 +++++----- testing/matrix-sdk-test/Cargo.toml | 5 ++++- .../matrix-sdk-test/src/event_factory.rs | 10 ++++------ testing/matrix-sdk-test/src/lib.rs | 1 + 30 files changed, 82 insertions(+), 95 deletions(-) rename crates/matrix-sdk/src/test_utils/events.rs => testing/matrix-sdk-test/src/event_factory.rs (97%) diff --git a/Cargo.lock b/Cargo.lock index cd2a9412829..b6be9f73202 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3005,7 +3005,7 @@ dependencies = [ "gloo-timers", "imbl", "js-sys", - "matrix-sdk-test", + "matrix-sdk-test-macros", "proptest", "ruma", "serde", @@ -3275,9 +3275,11 @@ dependencies = [ name = "matrix-sdk-test" version = "0.7.0" dependencies = [ + "as_variant", "ctor", "getrandom", "http", + "matrix-sdk-common", "matrix-sdk-test-macros", "once_cell", "ruma", diff --git a/benchmarks/benches/room_bench.rs b/benchmarks/benches/room_bench.rs index 57342857285..feebf4019a5 100644 --- a/benchmarks/benches/room_bench.rs +++ b/benchmarks/benches/room_bench.rs @@ -2,15 +2,16 @@ use std::{sync::Arc, time::Duration}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use matrix_sdk::{ - config::SyncSettings, - test_utils::{events::EventFactory, logged_in_client_with_server}, - utils::IntoRawStateEventContent, + config::SyncSettings, test_utils::logged_in_client_with_server, utils::IntoRawStateEventContent, }; use matrix_sdk_base::{ store::StoreConfig, BaseClient, RoomInfo, RoomState, SessionMeta, StateChanges, StateStore, }; use matrix_sdk_sqlite::SqliteStateStore; -use matrix_sdk_test::{EventBuilder, JoinedRoomBuilder, StateTestEvent, SyncResponseBuilder}; +use matrix_sdk_test::{ + event_factory::EventFactory, EventBuilder, JoinedRoomBuilder, StateTestEvent, + SyncResponseBuilder, +}; use matrix_sdk_ui::{timeline::TimelineFocus, Timeline}; use ruma::{ api::client::membership::get_member_events, diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs index 6860d0cb600..b90613d53d0 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/mod.rs @@ -726,12 +726,14 @@ impl ReactionsByKeyBySender { mod tests { use assert_matches::assert_matches; use assert_matches2::assert_let; - use matrix_sdk::test_utils::{events::EventFactory, logged_in_client}; + use matrix_sdk::test_utils::logged_in_client; use matrix_sdk_base::{ deserialized_responses::SyncTimelineEvent, latest_event::LatestEvent, sliding_sync::http, MinimalStateEvent, OriginalMinimalStateEvent, }; - use matrix_sdk_test::{async_test, sync_state_event, sync_timeline_event}; + use matrix_sdk_test::{ + async_test, event_factory::EventFactory, sync_state_event, sync_timeline_event, + }; use ruma::{ event_id, events::{ diff --git a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs index a5475b6eb06..b68ccedc5b1 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs @@ -16,12 +16,9 @@ use std::sync::Arc; use assert_matches::assert_matches; use eyeball_im::VectorDiff; -use matrix_sdk::{ - assert_next_matches_with_timeout, send_queue::RoomSendQueueUpdate, - test_utils::events::EventFactory, -}; +use matrix_sdk::{assert_next_matches_with_timeout, send_queue::RoomSendQueueUpdate}; use matrix_sdk_base::store::QueueWedgeError; -use matrix_sdk_test::{async_test, ALICE, BOB}; +use matrix_sdk_test::{async_test, event_factory::EventFactory, ALICE, BOB}; use ruma::{ event_id, events::{room::message::RoomMessageEventContent, AnyMessageLikeEventContent}, diff --git a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs index 356a2ad2228..e212a82d6be 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/mod.rs @@ -31,11 +31,12 @@ use matrix_sdk::{ event_cache::paginator::{PaginableRoom, PaginatorError}, room::{EventWithContextResponse, Messages, MessagesOptions}, send_queue::RoomSendQueueUpdate, - test_utils::events::EventFactory, BoxFuture, }; use matrix_sdk_base::{latest_event::LatestEvent, RoomInfo, RoomState}; -use matrix_sdk_test::{EventBuilder, ALICE, BOB, DEFAULT_TEST_ROOM_ID}; +use matrix_sdk_test::{ + event_factory::EventFactory, EventBuilder, ALICE, BOB, DEFAULT_TEST_ROOM_ID, +}; use ruma::{ event_id, events::{ diff --git a/crates/matrix-sdk-ui/src/timeline/tests/reactions.rs b/crates/matrix-sdk-ui/src/timeline/tests/reactions.rs index bb0a8ab51da..d1e92e4ca49 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/reactions.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/reactions.rs @@ -18,8 +18,8 @@ use assert_matches2::{assert_let, assert_matches}; use eyeball_im::VectorDiff; use futures_core::Stream; use futures_util::{FutureExt as _, StreamExt as _}; -use matrix_sdk::{deserialized_responses::SyncTimelineEvent, test_utils::events::EventFactory}; -use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB}; +use matrix_sdk::deserialized_responses::SyncTimelineEvent; +use matrix_sdk_test::{async_test, event_factory::EventFactory, sync_timeline_event, ALICE, BOB}; use ruma::{ event_id, events::AnyMessageLikeEventContent, server_name, uint, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, diff --git a/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs b/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs index 6f0c2e02a17..2da7584f949 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/read_receipts.rs @@ -15,8 +15,7 @@ use std::sync::Arc; use eyeball_im::VectorDiff; -use matrix_sdk::test_utils::events::EventFactory; -use matrix_sdk_test::{async_test, ALICE, BOB, CAROL}; +use matrix_sdk_test::{async_test, event_factory::EventFactory, ALICE, BOB, CAROL}; use ruma::{ event_id, events::{ diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs b/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs index 97366d6e9a6..69db503f269 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs @@ -19,14 +19,12 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::StreamExt; use matrix_sdk::{ - assert_next_matches_with_timeout, - config::SyncSettings, - executor::spawn, - ruma::MilliSecondsSinceUnixEpoch, - test_utils::{events::EventFactory, logged_in_client_with_server}, + assert_next_matches_with_timeout, config::SyncSettings, executor::spawn, + ruma::MilliSecondsSinceUnixEpoch, test_utils::logged_in_client_with_server, }; use matrix_sdk_test::{ - async_test, mocks::mock_encryption_state, JoinedRoomBuilder, SyncResponseBuilder, + async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder, + SyncResponseBuilder, }; use matrix_sdk_ui::timeline::{EventSendState, RoomExt, TimelineItemContent}; use ruma::{ diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs index 3d848cc2116..ddafabe5cdb 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/edit.rs @@ -20,13 +20,12 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::{FutureExt, StreamExt}; use matrix_sdk::{ - config::SyncSettings, - room::edit::EditedContent, - test_utils::{events::EventFactory, logged_in_client_with_server}, + config::SyncSettings, room::edit::EditedContent, test_utils::logged_in_client_with_server, Client, }; use matrix_sdk_test::{ - async_test, mocks::mock_encryption_state, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, + async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder, + SyncResponseBuilder, ALICE, BOB, }; use matrix_sdk_ui::{ timeline::{ diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/focus_event.rs b/crates/matrix-sdk-ui/tests/integration/timeline/focus_event.rs index fa47850034e..240586a7ad0 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/focus_event.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/focus_event.rs @@ -20,12 +20,12 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::StreamExt; use matrix_sdk::{ - assert_next_matches_with_timeout, - config::SyncSettings, - test_utils::{events::EventFactory, logged_in_client_with_server}, + assert_next_matches_with_timeout, config::SyncSettings, + test_utils::logged_in_client_with_server, }; use matrix_sdk_test::{ - async_test, mocks::mock_encryption_state, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, + async_test, event_factory::EventFactory, mocks::mock_encryption_state, JoinedRoomBuilder, + SyncResponseBuilder, ALICE, BOB, }; use matrix_sdk_ui::{timeline::TimelineFocus, Timeline}; use ruma::{event_id, events::room::message::RoomMessageEventContent, room_id}; diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/media.rs b/crates/matrix-sdk-ui/tests/integration/timeline/media.rs index a6065e5f3d9..e11ea3a8283 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/media.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/media.rs @@ -19,11 +19,9 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::{FutureExt, StreamExt}; use matrix_sdk::{ - assert_let_timeout, - attachment::AttachmentConfig, - test_utils::{events::EventFactory, mocks::MatrixMockServer}, + assert_let_timeout, attachment::AttachmentConfig, test_utils::mocks::MatrixMockServer, }; -use matrix_sdk_test::{async_test, JoinedRoomBuilder, ALICE}; +use matrix_sdk_test::{async_test, event_factory::EventFactory, JoinedRoomBuilder, ALICE}; use matrix_sdk_ui::timeline::{EventSendState, RoomExt, TimelineItemContent}; use ruma::{ event_id, diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs b/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs index a70f3a499ff..df1319c7066 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs @@ -19,12 +19,11 @@ use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::StreamExt; use matrix_sdk::{ - assert_let_timeout, - config::SyncSettings, - test_utils::{events::EventFactory, logged_in_client_with_server}, + assert_let_timeout, config::SyncSettings, test_utils::logged_in_client_with_server, }; use matrix_sdk_test::{ async_test, + event_factory::EventFactory, mocks::{mock_encryption_state, mock_redaction}, sync_timeline_event, JoinedRoomBuilder, RoomAccountDataTestEvent, StateTestEvent, SyncResponseBuilder, BOB, diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs b/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs index b67661a73d0..044b8cc354d 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs @@ -3,14 +3,14 @@ use std::time::Duration; use assert_matches::assert_matches; use eyeball_im::VectorDiff; use matrix_sdk::{ - assert_next_matches_with_timeout, - config::SyncSettings, - sync::SyncResponse, - test_utils::{events::EventFactory, logged_in_client_with_server}, - Client, + assert_next_matches_with_timeout, config::SyncSettings, sync::SyncResponse, + test_utils::logged_in_client_with_server, Client, }; use matrix_sdk_base::deserialized_responses::TimelineEvent; -use matrix_sdk_test::{async_test, JoinedRoomBuilder, StateTestEvent, SyncResponseBuilder, BOB}; +use matrix_sdk_test::{ + async_test, event_factory::EventFactory, JoinedRoomBuilder, StateTestEvent, + SyncResponseBuilder, BOB, +}; use matrix_sdk_ui::{ timeline::{RoomExt, TimelineFocus, TimelineItemContent}, Timeline, diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/reactions.rs b/crates/matrix-sdk-ui/tests/integration/timeline/reactions.rs index 671750aea23..cbc8c04fe50 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/reactions.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/reactions.rs @@ -17,12 +17,10 @@ use std::{sync::Mutex, time::Duration}; use assert_matches2::{assert_let, assert_matches}; use eyeball_im::VectorDiff; use futures_util::{FutureExt as _, StreamExt as _}; -use matrix_sdk::{ - assert_next_matches_with_timeout, - test_utils::{events::EventFactory, logged_in_client_with_server}, -}; +use matrix_sdk::{assert_next_matches_with_timeout, test_utils::logged_in_client_with_server}; use matrix_sdk_test::{ async_test, + event_factory::EventFactory, mocks::{mock_encryption_state, mock_redaction}, JoinedRoomBuilder, SyncResponseBuilder, ALICE, }; diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs index 08b9cd2a638..580bdc92860 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs @@ -4,14 +4,11 @@ use assert_matches::assert_matches; use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::StreamExt; -use matrix_sdk::{ - config::SyncSettings, - test_utils::{events::EventFactory, logged_in_client_with_server}, -}; +use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server}; use matrix_sdk_base::timeout::timeout; use matrix_sdk_test::{ - async_test, mocks::mock_encryption_state, EventBuilder, JoinedRoomBuilder, SyncResponseBuilder, - ALICE, BOB, CAROL, + async_test, event_factory::EventFactory, mocks::mock_encryption_state, EventBuilder, + JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, CAROL, }; use matrix_sdk_ui::timeline::{ Error as TimelineError, EventSendState, RoomExt, TimelineDetails, TimelineItemContent, diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs b/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs index 4a11af83569..4989d51c3b2 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/subscribe.rs @@ -18,13 +18,10 @@ use assert_matches::assert_matches; use assert_matches2::assert_let; use eyeball_im::VectorDiff; use futures_util::{pin_mut, StreamExt}; -use matrix_sdk::{ - config::SyncSettings, - test_utils::{events::EventFactory, logged_in_client_with_server}, -}; +use matrix_sdk::{config::SyncSettings, test_utils::logged_in_client_with_server}; use matrix_sdk_test::{ - async_test, mocks::mock_encryption_state, sync_timeline_event, EventBuilder, - GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, + async_test, event_factory::EventFactory, mocks::mock_encryption_state, sync_timeline_event, + EventBuilder, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, ALICE, BOB, }; use matrix_sdk_ui::timeline::{RoomExt, TimelineDetails, TimelineItemContent}; use ruma::{ diff --git a/crates/matrix-sdk/src/event_cache/deduplicator.rs b/crates/matrix-sdk/src/event_cache/deduplicator.rs index 57d4126afef..9a6e8d933eb 100644 --- a/crates/matrix-sdk/src/event_cache/deduplicator.rs +++ b/crates/matrix-sdk/src/event_cache/deduplicator.rs @@ -142,10 +142,10 @@ pub enum Decoration { mod tests { use assert_matches2::{assert_let, assert_matches}; use matrix_sdk_base::deserialized_responses::SyncTimelineEvent; + use matrix_sdk_test::event_factory::EventFactory; use ruma::{owned_event_id, user_id, EventId}; use super::*; - use crate::test_utils::events::EventFactory; fn sync_timeline_event(event_id: &EventId) -> SyncTimelineEvent { EventFactory::new() diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index 8f0c2f19212..035b6b0f631 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -502,12 +502,12 @@ mod tests { use assert_matches::assert_matches; use futures_util::FutureExt as _; use matrix_sdk_base::sync::{JoinedRoomUpdate, RoomUpdates, Timeline}; - use matrix_sdk_test::async_test; + use matrix_sdk_test::{async_test, event_factory::EventFactory}; use ruma::{event_id, room_id, serde::Raw, user_id}; use serde_json::json; use super::{EventCacheError, RoomEventCacheUpdate}; - use crate::test_utils::{assert_event_matches_msg, events::EventFactory, logged_in_client}; + use crate::test_utils::{assert_event_matches_msg, logged_in_client}; #[async_test] async fn test_must_explicitly_subscribe() { diff --git a/crates/matrix-sdk/src/event_cache/paginator.rs b/crates/matrix-sdk/src/event_cache/paginator.rs index 259074d2e88..280d033c50e 100644 --- a/crates/matrix-sdk/src/event_cache/paginator.rs +++ b/crates/matrix-sdk/src/event_cache/paginator.rs @@ -559,7 +559,7 @@ mod tests { use futures_core::Future; use futures_util::FutureExt as _; use matrix_sdk_base::deserialized_responses::TimelineEvent; - use matrix_sdk_test::async_test; + use matrix_sdk_test::{async_test, event_factory::EventFactory}; use once_cell::sync::Lazy; use ruma::{api::Direction, event_id, room_id, uint, user_id, EventId, RoomId, UInt, UserId}; use tokio::{ @@ -572,7 +572,7 @@ mod tests { use crate::{ event_cache::paginator::Paginator, room::{EventWithContextResponse, Messages, MessagesOptions}, - test_utils::{assert_event_matches_msg, events::EventFactory}, + test_utils::assert_event_matches_msg, }; #[derive(Clone)] diff --git a/crates/matrix-sdk/src/event_cache/room/events.rs b/crates/matrix-sdk/src/event_cache/room/events.rs index d9168bdca63..50813c3f0e1 100644 --- a/crates/matrix-sdk/src/event_cache/room/events.rs +++ b/crates/matrix-sdk/src/event_cache/room/events.rs @@ -316,10 +316,10 @@ impl RoomEvents { #[cfg(test)] mod tests { use assert_matches2::assert_let; + use matrix_sdk_test::event_factory::EventFactory; use ruma::{user_id, EventId, OwnedEventId}; use super::*; - use crate::test_utils::events::EventFactory; macro_rules! assert_events_eq { ( $events_iterator:expr, [ $( ( $event_id:ident at ( $chunk_identifier:literal, $index:literal ) ) ),* $(,)? ] ) => { diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 7a3e8476869..7b007547016 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -559,14 +559,14 @@ impl RoomEventCacheState { #[cfg(test)] mod tests { use matrix_sdk_common::deserialized_responses::SyncTimelineEvent; - use matrix_sdk_test::async_test; + use matrix_sdk_test::{async_test, event_factory::EventFactory}; use ruma::{ event_id, events::{relation::RelationType, room::message::RoomMessageEventContentWithoutRelation}, room_id, user_id, RoomId, }; - use crate::test_utils::{events::EventFactory, logged_in_client}; + use crate::test_utils::logged_in_client; #[async_test] async fn test_event_with_redaction_relation() { diff --git a/crates/matrix-sdk/src/room/edit.rs b/crates/matrix-sdk/src/room/edit.rs index 2c4e4e64c89..fcb3533559f 100644 --- a/crates/matrix-sdk/src/room/edit.rs +++ b/crates/matrix-sdk/src/room/edit.rs @@ -353,7 +353,7 @@ mod tests { use assert_matches2::{assert_let, assert_matches}; use matrix_sdk_base::deserialized_responses::SyncTimelineEvent; - use matrix_sdk_test::async_test; + use matrix_sdk_test::{async_test, event_factory::EventFactory}; use ruma::{ event_id, events::{ @@ -367,7 +367,7 @@ mod tests { use serde_json::json; use super::{make_edit_event, EditError, EventSource}; - use crate::{room::edit::EditedContent, test_utils::events::EventFactory}; + use crate::room::edit::EditedContent; #[derive(Default)] struct TestEventCache { diff --git a/crates/matrix-sdk/src/test_utils/mod.rs b/crates/matrix-sdk/src/test_utils/mod.rs index 900a60af036..649e0501639 100644 --- a/crates/matrix-sdk/src/test_utils/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mod.rs @@ -12,8 +12,6 @@ use ruma::{ }; use url::Url; -pub mod events; - pub mod client; #[cfg(not(target_arch = "wasm32"))] pub mod mocks; diff --git a/crates/matrix-sdk/tests/integration/event_cache.rs b/crates/matrix-sdk/tests/integration/event_cache.rs index 40c03c67d79..f6fc42dd2ad 100644 --- a/crates/matrix-sdk/tests/integration/event_cache.rs +++ b/crates/matrix-sdk/tests/integration/event_cache.rs @@ -6,10 +6,11 @@ use matrix_sdk::{ paginator::PaginatorState, BackPaginationOutcome, EventCacheError, RoomEventCacheUpdate, TimelineHasBeenResetWhilePaginating, }, - test_utils::{assert_event_matches_msg, events::EventFactory, logged_in_client_with_server}, + test_utils::{assert_event_matches_msg, logged_in_client_with_server}, }; use matrix_sdk_test::{ - async_test, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, + async_test, event_factory::EventFactory, GlobalAccountDataTestEvent, JoinedRoomBuilder, + SyncResponseBuilder, }; use ruma::{event_id, events::AnyTimelineEvent, room_id, serde::Raw, user_id}; use serde_json::json; diff --git a/crates/matrix-sdk/tests/integration/room/common.rs b/crates/matrix-sdk/tests/integration/room/common.rs index 33efb813eac..f525f497436 100644 --- a/crates/matrix-sdk/tests/integration/room/common.rs +++ b/crates/matrix-sdk/tests/integration/room/common.rs @@ -2,14 +2,11 @@ use std::{iter, time::Duration}; use assert_matches2::{assert_let, assert_matches}; use js_int::uint; -use matrix_sdk::{ - config::SyncSettings, room::RoomMember, test_utils::events::EventFactory, RoomDisplayName, - RoomMemberships, -}; +use matrix_sdk::{config::SyncSettings, room::RoomMember, RoomDisplayName, RoomMemberships}; use matrix_sdk_test::{ - async_test, bulk_room_members, sync_state_event, sync_timeline_event, test_json, - GlobalAccountDataTestEvent, JoinedRoomBuilder, LeftRoomBuilder, StateTestEvent, - SyncResponseBuilder, BOB, DEFAULT_TEST_ROOM_ID, + async_test, bulk_room_members, event_factory::EventFactory, sync_state_event, + sync_timeline_event, test_json, GlobalAccountDataTestEvent, JoinedRoomBuilder, LeftRoomBuilder, + StateTestEvent, SyncResponseBuilder, BOB, DEFAULT_TEST_ROOM_ID, }; use ruma::{ event_id, diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 440d1a9030d..322b0269488 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -7,11 +7,12 @@ use futures_util::future::join_all; use matrix_sdk::{ config::SyncSettings, room::{edit::EditedContent, Receipts, ReportedContentScore, RoomMemberRole}, - test_utils::{events::EventFactory, mocks::MatrixMockServer}, + test_utils::mocks::MatrixMockServer, }; use matrix_sdk_base::RoomState; use matrix_sdk_test::{ async_test, + event_factory::EventFactory, mocks::{mock_encryption_state, mock_redaction}, test_json::{self, sync::CUSTOM_ROOM_POWER_LEVELS}, EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, StateTestEvent, diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index eb737895c0d..a0c2c9e412b 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -10,13 +10,13 @@ use matrix_sdk::{ LocalEcho, LocalEchoContent, RoomSendQueue, RoomSendQueueError, RoomSendQueueStorageError, RoomSendQueueUpdate, SendHandle, }, - test_utils::{ - events::EventFactory, - mocks::{MatrixMock, MatrixMockServer}, - }, + test_utils::mocks::{MatrixMock, MatrixMockServer}, Client, MemoryStore, }; -use matrix_sdk_test::{async_test, InvitedRoomBuilder, KnockedRoomBuilder, LeftRoomBuilder}; +use matrix_sdk_test::{ + async_test, event_factory::EventFactory, InvitedRoomBuilder, KnockedRoomBuilder, + LeftRoomBuilder, +}; use ruma::{ event_id, events::{ diff --git a/testing/matrix-sdk-test/Cargo.toml b/testing/matrix-sdk-test/Cargo.toml index 7c1aa7391dd..d18256db996 100644 --- a/testing/matrix-sdk-test/Cargo.toml +++ b/testing/matrix-sdk-test/Cargo.toml @@ -16,10 +16,13 @@ test = false doctest = false [dependencies] +as_variant = { workspace = true } http = { workspace = true } +matrix-sdk-common = { path = "../../crates/matrix-sdk-common" } matrix-sdk-test-macros = { version = "0.7.0", path = "../matrix-sdk-test-macros" } once_cell = { workspace = true } -ruma = { workspace = true, features = ["rand"] } +# Enabling the unstable feature for polls support. +ruma = { workspace = true, features = ["rand", "unstable-msc3381"] } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/matrix-sdk/src/test_utils/events.rs b/testing/matrix-sdk-test/src/event_factory.rs similarity index 97% rename from crates/matrix-sdk/src/test_utils/events.rs rename to testing/matrix-sdk-test/src/event_factory.rs index 6f447a64bcc..1a8b8dbe8df 100644 --- a/crates/matrix-sdk/src/test_utils/events.rs +++ b/testing/matrix-sdk-test/src/event_factory.rs @@ -17,8 +17,9 @@ use std::sync::atomic::{AtomicU64, Ordering::SeqCst}; use as_variant::as_variant; -use matrix_sdk_base::deserialized_responses::{SyncTimelineEvent, TimelineEvent}; -use matrix_sdk_common::deserialized_responses::UnableToDecryptReason; +use matrix_sdk_common::deserialized_responses::{ + SyncTimelineEvent, TimelineEvent, UnableToDecryptInfo, UnableToDecryptReason, +}; use ruma::{ events::{ message::TextContentBlock, @@ -200,10 +201,7 @@ impl EventBuilder { SyncTimelineEvent::new_utd_event( self.into(), - crate::deserialized_responses::UnableToDecryptInfo { - session_id, - reason: UnableToDecryptReason::MissingMegolmSession, - }, + UnableToDecryptInfo { session_id, reason: UnableToDecryptReason::MissingMegolmSession }, ) } } diff --git a/testing/matrix-sdk-test/src/lib.rs b/testing/matrix-sdk-test/src/lib.rs index 1b06e142d56..5a3c5d721e8 100644 --- a/testing/matrix-sdk-test/src/lib.rs +++ b/testing/matrix-sdk-test/src/lib.rs @@ -114,6 +114,7 @@ mod event_builder; #[cfg(not(target_arch = "wasm32"))] pub mod mocks; +pub mod event_factory; pub mod notification_settings; mod sync_builder; pub mod test_json;