From 4d431b7c9ee4d8c68fbf54eaa09d8a416377346b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 15 Sep 2020 18:06:32 +0200 Subject: [PATCH] matrix-sdk: Test the attachment sending paths. --- matrix_sdk/src/client.rs | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 767bf55e..88412894 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1860,9 +1860,10 @@ mod test { }; use matrix_sdk_test::{test_json, EventBuilder, EventsJson}; use mockito::{mock, Matcher}; + use serde_json::json; use tempfile::tempdir; - use std::{convert::TryInto, path::Path, str::FromStr, time::Duration}; + use std::{convert::TryInto, io::Cursor, path::Path, str::FromStr, time::Duration}; async fn logged_in_client() -> Client { let session = Session { @@ -2405,6 +2406,45 @@ mod test { assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id) } + #[tokio::test] + async fn room_attachment_send() { + let client = logged_in_client().await; + + let _m = mock( + "PUT", + Matcher::Regex(r"^/_matrix/client/r0/rooms/.*/send/".to_string()), + ) + .with_status(200) + .match_header("authorization", "Bearer 1234") + .with_body(test_json::EVENT_ID.to_string()) + .create(); + + let _m = mock( + "POST", + Matcher::Regex(r"^/_matrix/media/r0/upload".to_string()), + ) + .with_status(200) + .match_header("content-type", "image/jpg") + .with_body( + json!({ + "content_uri": "mxc://example.com/AQwafuaFswefuhsfAFAgsw" + }) + .to_string(), + ) + .create(); + + let room_id = room_id!("!testroom:example.org"); + + let mut media = Cursor::new("Hello world"); + + let response = client + .room_send_attachment(&room_id, "image", "image/jpg", &mut media, None) + .await + .unwrap(); + + assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id) + } + #[tokio::test] async fn user_presence() { let client = logged_in_client().await;