From 12aed8dc67a0b17b92fcc7da005ec5d45b51f360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 28 May 2025 12:17:25 +0200 Subject: [PATCH] test: fix tests after adding the media config check --- .../tests/integration/timeline/media.rs | 2 ++ crates/matrix-sdk/src/test_utils/mocks/mod.rs | 7 ++++++ .../tests/integration/room/attachment/mod.rs | 22 +++++++++++++++++++ .../tests/integration/send_queue.rs | 15 +++++++++++++ 4 files changed, 46 insertions(+) diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/media.rs b/crates/matrix-sdk-ui/tests/integration/timeline/media.rs index 9e4489ba3..a7046d18c 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/media.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/media.rs @@ -62,6 +62,7 @@ async fn test_send_attachment_from_file() { let mock = MatrixMockServer::new().await; let client = mock.client_builder().build().await; + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; let room_id = room_id!("!a98sd12bjh:example.org"); @@ -168,6 +169,7 @@ async fn test_send_attachment_from_bytes() { let mock = MatrixMockServer::new().await; let client = mock.client_builder().build().await; + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; let room_id = room_id!("!a98sd12bjh:example.org"); diff --git a/crates/matrix-sdk/src/test_utils/mocks/mod.rs b/crates/matrix-sdk/src/test_utils/mocks/mod.rs index a25fd40ee..f06652bc0 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/mod.rs @@ -3024,4 +3024,11 @@ impl<'a> MockEndpoint<'a, AuthenticatedMediaConfigEndpoint> { "m.upload.size": max_upload_size, }))) } + + /// Returns a successful response with a maxed out max upload size. + pub fn ok_default(self) -> MatrixMock<'a> { + self.respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "m.upload.size": UInt::MAX, + }))) + } } diff --git a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs index 6ceb8b423..d83774424 100644 --- a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs +++ b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs @@ -21,6 +21,8 @@ use serde_json::json; async fn test_room_attachment_send() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); mock.mock_room_send() @@ -63,6 +65,8 @@ async fn test_room_attachment_send() { async fn test_room_attachment_send_in_encrypted_room_has_binary_mime_type() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); mock.mock_room_send().ok(expected_event_id).mock_once().mount().await; @@ -98,6 +102,8 @@ async fn test_room_attachment_send_in_encrypted_room_has_binary_mime_type() { async fn test_room_attachment_send_info() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); mock.mock_room_send() .body_matches_partial_json(json!({ @@ -143,6 +149,8 @@ async fn test_room_attachment_send_info() { async fn test_room_attachment_send_wrong_info() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + // Note: this mock is NOT called because the height and width are lost, because // we're trying to send the attachment as an image, while we provide a // `VideoInfo`. @@ -195,6 +203,8 @@ async fn test_room_attachment_send_wrong_info() { async fn test_room_attachment_send_info_thumbnail() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let media_mxc = owned_mxc_uri!("mxc://example.com/media"); let thumbnail_mxc = owned_mxc_uri!("mxc://example.com/thumbnail"); @@ -299,6 +309,8 @@ async fn test_room_attachment_send_info_thumbnail() { async fn test_room_attachment_send_mentions() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); mock.mock_room_send() @@ -344,6 +356,8 @@ async fn test_room_attachment_reply_outside_thread() { let expected_event_id = event_id!("$h29iv0s8:example.com"); let replied_to_event_id = event_id!("$foo:bar.com"); + mock.mock_authenticated_media_config().ok_default().mount().await; + mock.mock_room_send() .body_matches_partial_json(json!({ "m.relates_to": { @@ -405,6 +419,8 @@ async fn test_room_attachment_start_thread() { let expected_event_id = event_id!("$h29iv0s8:example.com"); let replied_to_event_id = event_id!("$foo:bar.com"); + mock.mock_authenticated_media_config().ok_default().mount().await; + mock.mock_room_send() .body_matches_partial_json(json!({ "m.relates_to": { @@ -470,6 +486,8 @@ async fn test_room_attachment_reply_on_thread_as_reply() { let thread_root_event_id = event_id!("$bar:foo.com"); let replied_to_event_id = event_id!("$foo:bar.com"); + mock.mock_authenticated_media_config().ok_default().mount().await; + mock.mock_room_send() .body_matches_partial_json(json!({ "m.relates_to": { @@ -531,6 +549,8 @@ async fn test_room_attachment_reply_on_thread_as_reply() { async fn test_room_attachment_reply_forwarding_thread() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); let thread_root_event_id = event_id!("$bar:foo.com"); let replied_to_event_id = event_id!("$foo:bar.com"); @@ -597,6 +617,8 @@ async fn test_room_attachment_reply_forwarding_thread() { async fn test_room_attachment_send_is_animated() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + let expected_event_id = event_id!("$h29iv0s8:example.com"); mock.mock_room_send() .body_matches_partial_json(json!({ diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index 11b161a4f..ba1096b29 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -1838,6 +1838,7 @@ async fn test_media_uploads() { // ---------------------- // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; mock.mock_room_send().ok(event_id!("$1")).mock_once().mount().await; @@ -2507,6 +2508,7 @@ async fn test_media_upload_retry() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // Fail for the first three attempts. @@ -2583,6 +2585,8 @@ async fn test_media_upload_retry_with_520_http_status_code() { // Prepare endpoints. mock.mock_room_state_encryption().plain().mount().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + // Fail with a 520 http status code mock.mock_upload() .expect_mime_type("image/jpeg") @@ -2622,6 +2626,7 @@ async fn test_unwedging_media_upload() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // Fail for the first attempt with an error indicating the media's too large, @@ -2729,6 +2734,7 @@ async fn test_media_event_is_sent_in_order() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; mock.mock_upload().ok(mxc_uri!("mxc://sdk.rs/media")).mock_once().mount().await; @@ -2859,6 +2865,7 @@ async fn test_cancel_upload_with_thumbnail_active() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; mock.mock_room_send().ok(event_id!("$msg")).mock_once().mount().await; @@ -2910,6 +2917,7 @@ async fn test_cancel_upload_with_uploaded_thumbnail_and_file_active() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; mock.mock_room_send().ok(event_id!("$msg")).mock_once().named("send event").mount().await; @@ -2973,6 +2981,7 @@ async fn test_cancel_upload_only_file_with_file_active() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; mock.mock_room_send().ok(event_id!("$msg")).mock_once().named("send event").mount().await; @@ -3038,6 +3047,7 @@ async fn test_cancel_upload_while_sending_event() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // File upload will succeed immediately. @@ -3141,6 +3151,7 @@ async fn test_update_caption_while_sending_media() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // File upload will take a second. @@ -3214,6 +3225,8 @@ async fn test_update_caption_while_sending_media() { async fn test_update_caption_before_event_is_sent() { let mock = MatrixMockServer::new().await; + mock.mock_authenticated_media_config().ok_default().mount().await; + // Mark the room as joined. let room_id = room_id!("!a:b.c"); let client = mock.client_builder().build().await; @@ -3327,6 +3340,7 @@ async fn test_add_mention_to_caption_before_media_sent() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // File upload will take a second. @@ -3426,6 +3440,7 @@ async fn test_update_caption_while_sending_media_event() { assert!(local_echoes.is_empty()); // Prepare endpoints. + mock.mock_authenticated_media_config().ok_default().mount().await; mock.mock_room_state_encryption().plain().mount().await; // File upload will resolve immediately.