mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-06-22 15:18:33 -04:00
test: reuse the internal EventFactory of the TestTimeline in more places
Also rename a few `factory` to `f`, for consistency with the rest of the testing code.
This commit is contained in:
committed by
Benjamin Bouvier
parent
b00f58a28d
commit
bbefad34bc
@@ -15,7 +15,6 @@
|
||||
use assert_matches::assert_matches;
|
||||
use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB, CAROL};
|
||||
use ruma::{
|
||||
events::{
|
||||
@@ -45,7 +44,7 @@ async fn test_initial_events() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline
|
||||
.inner
|
||||
.add_events_at(
|
||||
@@ -87,8 +86,8 @@ async fn test_replace_with_initial_events_and_read_marker() {
|
||||
)
|
||||
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
|
||||
|
||||
let factory = EventFactory::new();
|
||||
let ev = factory.text_msg("hey").sender(*ALICE).into_sync();
|
||||
let f = &timeline.factory;
|
||||
let ev = f.text_msg("hey").sender(*ALICE).into_sync();
|
||||
|
||||
timeline.inner.add_events_at(vec![ev], TimelineEnd::Back, RemoteEventOrigin::Sync).await;
|
||||
|
||||
@@ -97,7 +96,7 @@ async fn test_replace_with_initial_events_and_read_marker() {
|
||||
assert!(items[0].is_day_divider());
|
||||
assert_eq!(items[1].as_event().unwrap().content().as_message().unwrap().body(), "hey");
|
||||
|
||||
let ev = factory.text_msg("yo").sender(*BOB).into_sync();
|
||||
let ev = f.text_msg("yo").sender(*BOB).into_sync();
|
||||
timeline.inner.replace_with_initial_remote_events(vec![ev], RemoteEventOrigin::Sync).await;
|
||||
|
||||
let items = timeline.inner.items().await;
|
||||
@@ -298,10 +297,10 @@ async fn test_dedup_pagination() {
|
||||
async fn test_dedup_initial() {
|
||||
let timeline = TestTimeline::new();
|
||||
|
||||
let factory = EventFactory::new();
|
||||
let event_a = factory.text_msg("A").sender(*ALICE).into_sync();
|
||||
let event_b = factory.text_msg("B").sender(*BOB).into_sync();
|
||||
let event_c = factory.text_msg("C").sender(*CAROL).into_sync();
|
||||
let f = &timeline.factory;
|
||||
let event_a = f.text_msg("A").sender(*ALICE).into_sync();
|
||||
let event_b = f.text_msg("B").sender(*BOB).into_sync();
|
||||
let event_c = f.text_msg("C").sender(*CAROL).into_sync();
|
||||
|
||||
timeline
|
||||
.inner
|
||||
@@ -346,10 +345,10 @@ async fn test_dedup_initial() {
|
||||
async fn test_internal_id_prefix() {
|
||||
let timeline = TestTimeline::with_internal_id_prefix("le_prefix_".to_owned());
|
||||
|
||||
let factory = EventFactory::new();
|
||||
let ev_a = factory.text_msg("A").sender(*ALICE).into_sync();
|
||||
let ev_b = factory.text_msg("B").sender(*BOB).into_sync();
|
||||
let ev_c = factory.text_msg("C").sender(*CAROL).into_sync();
|
||||
let f = &timeline.factory;
|
||||
let ev_a = f.text_msg("A").sender(*ALICE).into_sync();
|
||||
let ev_b = f.text_msg("B").sender(*BOB).into_sync();
|
||||
let ev_c = f.text_msg("C").sender(*CAROL).into_sync();
|
||||
|
||||
timeline
|
||||
.inner
|
||||
@@ -380,7 +379,7 @@ async fn test_sanitized() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_event(
|
||||
@@ -424,7 +423,7 @@ async fn test_reply() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("I want you to reply").sender(&ALICE)).await;
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
@@ -476,7 +475,7 @@ async fn test_thread() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("I want you to reply").sender(&ALICE)).await;
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
@@ -131,7 +131,7 @@ async fn test_remote_echo_full_trip() {
|
||||
async fn test_remote_echo_new_position() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Given a local event…
|
||||
let txn_id = timeline
|
||||
@@ -234,7 +234,7 @@ async fn test_day_divider_duplication() {
|
||||
async fn test_day_divider_removed_after_local_echo_disappeared() {
|
||||
let timeline = TestTimeline::new();
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_event(
|
||||
@@ -282,8 +282,6 @@ async fn test_day_divider_removed_after_local_echo_disappeared() {
|
||||
|
||||
#[async_test]
|
||||
async fn test_read_marker_removed_after_local_echo_disappeared() {
|
||||
let f = EventFactory::new();
|
||||
|
||||
let event_id = event_id!("$1");
|
||||
|
||||
let timeline = TestTimeline::with_room_data_provider(
|
||||
@@ -291,6 +289,8 @@ async fn test_read_marker_removed_after_local_echo_disappeared() {
|
||||
)
|
||||
.with_settings(TimelineInnerSettings { track_read_receipts: true, ..Default::default() });
|
||||
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Use `replace_with_initial_remote_events` which initializes the read marker;
|
||||
// other methods don't, by default.
|
||||
timeline
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE};
|
||||
use ruma::{
|
||||
events::room::message::{MessageType, RedactedRoomMessageEventContent},
|
||||
@@ -30,7 +29,8 @@ async fn test_live_redacted() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_redacted_message_event(*ALICE, RedactedRoomMessageEventContent::new())
|
||||
.await;
|
||||
@@ -57,7 +57,7 @@ async fn test_live_sanitized() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline
|
||||
.handle_live_event(
|
||||
f.text_html("**original** message", "<strong>original</strong> message").sender(&ALICE),
|
||||
|
||||
@@ -25,7 +25,7 @@ use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::{
|
||||
crypto::{decrypt_room_key_export, types::events::UtdCause, OlmMachine},
|
||||
test_utils::{events::EventFactory, test_client_builder},
|
||||
test_utils::test_client_builder,
|
||||
};
|
||||
use matrix_sdk_test::{async_test, BOB};
|
||||
use ruma::{
|
||||
@@ -85,7 +85,7 @@ async fn test_retry_message_decryption() {
|
||||
let timeline = TestTimeline::with_unable_to_decrypt_hook(utd_hook.clone());
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline
|
||||
.handle_live_event(
|
||||
f.event(RoomEncryptedEventContent::new(
|
||||
@@ -200,7 +200,7 @@ async fn test_retry_edit_decryption() {
|
||||
-----END MEGOLM SESSION DATA-----";
|
||||
|
||||
let timeline = TestTimeline::new();
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
let encrypted = EncryptedEventScheme::MegolmV1AesSha2(
|
||||
MegolmV1AesSha2ContentInit {
|
||||
@@ -313,7 +313,7 @@ async fn test_retry_edit_and_more() {
|
||||
}
|
||||
|
||||
let timeline = TestTimeline::new();
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_event(
|
||||
@@ -401,7 +401,7 @@ async fn test_retry_message_decryption_highlighted() {
|
||||
-----END MEGOLM SESSION DATA-----";
|
||||
|
||||
let timeline = TestTimeline::new();
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
timeline
|
||||
|
||||
@@ -17,7 +17,6 @@ use std::sync::Arc;
|
||||
use assert_matches::assert_matches;
|
||||
use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB};
|
||||
use ruma::events::{
|
||||
room::{
|
||||
@@ -41,7 +40,7 @@ async fn test_default_filter() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Test edits work.
|
||||
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
|
||||
@@ -99,7 +98,7 @@ async fn test_filter_always_false() {
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
|
||||
|
||||
timeline
|
||||
@@ -131,7 +130,7 @@ async fn test_custom_filter() {
|
||||
});
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
|
||||
let _item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let _day_divider = assert_next_matches!(stream, VectorDiff::PushFront { value } => value);
|
||||
@@ -199,7 +198,7 @@ async fn test_event_type_filter_include_only_room_names() {
|
||||
event_filter: Arc::new(move |event, _| event_filter.filter(event)),
|
||||
..Default::default()
|
||||
});
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Add a non-encrypted message event
|
||||
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
|
||||
@@ -247,7 +246,7 @@ async fn test_event_type_filter_exclude_messages() {
|
||||
event_filter: Arc::new(move |event, _| event_filter.filter(event)),
|
||||
..Default::default()
|
||||
});
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Add a message event
|
||||
timeline.handle_live_event(f.text_msg("The first message").sender(&ALICE)).await;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE, BOB};
|
||||
use ruma::{
|
||||
events::{room::message::MessageType, MessageLikeEventType, StateEventType},
|
||||
@@ -30,7 +29,7 @@ async fn invalid_edit() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("test").sender(&ALICE)).await;
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
let msg = item.content().as_message().unwrap();
|
||||
|
||||
@@ -201,7 +201,6 @@ impl TestTimeline {
|
||||
}
|
||||
|
||||
async fn send_poll_start(&self, sender: &UserId, content: UnstablePollStartContentBlock) {
|
||||
// TODO: consider putting it in the `TestTimeline` itself?
|
||||
let event_content = AnyMessageLikeEventContent::UnstablePollStart(
|
||||
NewUnstablePollStartEventContent::new(content).into(),
|
||||
);
|
||||
|
||||
@@ -94,9 +94,9 @@ async fn test_add_reaction_success() {
|
||||
|
||||
#[async_test]
|
||||
async fn test_redact_reaction_success() {
|
||||
let f = EventFactory::new();
|
||||
|
||||
let timeline = TestTimeline::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
let mut stream = timeline.subscribe().await;
|
||||
let (msg_id, msg_pos) = send_first_message(&timeline, &mut stream).await;
|
||||
let reaction = create_reaction(&msg_id);
|
||||
@@ -127,7 +127,7 @@ async fn test_redact_reaction_failure() {
|
||||
let mut stream = timeline.subscribe().await;
|
||||
let (msg_id, msg_pos) = send_first_message(&timeline, &mut stream).await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
let event_id = event_id!("$1");
|
||||
timeline
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
use assert_matches::assert_matches;
|
||||
use assert_matches2::assert_let;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
|
||||
use matrix_sdk_test::{async_test, ALICE, BOB};
|
||||
use ruma::events::{
|
||||
@@ -39,7 +38,7 @@ async fn test_redact_state_event() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_state_event(
|
||||
@@ -71,7 +70,7 @@ async fn test_redact_replied_to_event() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline.handle_live_event(f.text_msg("Hello, world!").sender(&ALICE)).await;
|
||||
|
||||
@@ -110,7 +109,7 @@ async fn test_reaction_redaction() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline.handle_live_event(f.text_msg("hi!").sender(&ALICE)).await;
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
@@ -136,7 +135,7 @@ async fn test_reaction_redaction_timeline_filter() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe_events().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// Initialise a timeline with a redacted reaction.
|
||||
timeline
|
||||
@@ -183,7 +182,7 @@ async fn test_reaction_redaction_timeline_filter() {
|
||||
async fn test_receive_unredacted() {
|
||||
let timeline = TestTimeline::new();
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
// send two events, second one redacted
|
||||
timeline.handle_live_event(f.text_msg("about to be redacted").sender(&ALICE)).await;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use assert_matches::assert_matches;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_base::deserialized_responses::{ShieldState, ShieldStateCode};
|
||||
use matrix_sdk_test::{async_test, sync_timeline_event, ALICE};
|
||||
use ruma::{
|
||||
@@ -15,7 +14,7 @@ use crate::timeline::{tests::TestTimeline, EventSendState};
|
||||
async fn test_no_shield_in_unencrypted_room() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline.handle_live_event(f.text_msg("Unencrypted message.").sender(&ALICE)).await;
|
||||
|
||||
@@ -29,7 +28,7 @@ async fn test_sent_in_clear_shield() {
|
||||
let timeline = TestTimeline::with_is_room_encrypted(true);
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
timeline.handle_live_event(f.text_msg("Unencrypted message.").sender(&ALICE)).await;
|
||||
|
||||
let item = assert_next_matches!(stream, VectorDiff::PushBack { value } => value);
|
||||
|
||||
@@ -16,7 +16,6 @@ use assert_matches::assert_matches;
|
||||
use assert_matches2::assert_let;
|
||||
use chrono::{Datelike, Local, TimeZone};
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::test_utils::events::EventFactory;
|
||||
use matrix_sdk_test::{async_test, ALICE, BOB};
|
||||
use ruma::{
|
||||
event_id,
|
||||
@@ -32,7 +31,7 @@ async fn test_day_divider() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline
|
||||
.handle_live_event(f.text_msg("This is a first message on the first day").sender(*ALICE))
|
||||
@@ -92,7 +91,7 @@ async fn test_update_read_marker() {
|
||||
let timeline = TestTimeline::new();
|
||||
let mut stream = timeline.subscribe().await;
|
||||
|
||||
let f = EventFactory::new();
|
||||
let f = &timeline.factory;
|
||||
|
||||
timeline.handle_live_event(f.text_msg("A").sender(&ALICE)).await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user