From 35231eaf6d4f086ec6830e75e68cdb5894ebb3e4 Mon Sep 17 00:00:00 2001 From: torrybr <16907963+torrybr@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:19:11 -0400 Subject: [PATCH] test: validate body of request --- .../tests/integration/room/joined.rs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 1d7451815ff..f67a58aa284 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -776,9 +776,17 @@ async fn test_make_reply_event_doesnt_require_event_cache() { async fn test_start_live_location_share_for_room() { let (client, server) = logged_in_client_with_server().await; + // Validate request body and response, partial body matching due to auto-generated + // `org.matrix.msc3488.ts` Mock::given(method("PUT")) .and(path_regex(r"^/_matrix/client/r0/rooms/.*/state/org.matrix.msc3672.beacon_info/.*")) .and(header("authorization", "Bearer 1234")) + .and(body_partial_json(&json!({ + "description": "Live Share", + "live": true, + "timeout": 3000, + "org.matrix.msc3488.asset": { "type": "m.self" } + }))) .respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::EVENT_ID)) .mount(&server) .await; @@ -787,7 +795,7 @@ async fn test_start_live_location_share_for_room() { mock_sync(&server, &*test_json::SYNC, None).await; - let _response = client.sync_once(sync_settings.clone()).await.unwrap(); + client.sync_once(sync_settings.clone()).await.unwrap(); let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); @@ -834,7 +842,7 @@ async fn test_start_live_location_share_for_room() { ) .await; - let _response = client.sync_once(sync_settings.clone()).await.unwrap(); + client.sync_once(sync_settings.clone()).await.unwrap(); server.reset().await; let state_events = room.get_state_events(StateEventType::BeaconInfo).await.unwrap(); @@ -867,9 +875,17 @@ async fn test_start_live_location_share_for_room() { async fn test_stop_sharing_live_location() { let (client, server) = logged_in_client_with_server().await; + // Validate request body and response, partial body matching due to auto-generated + // `org.matrix.msc3488.ts` Mock::given(method("PUT")) .and(path_regex(r"^/_matrix/client/r0/rooms/.*/state/org.matrix.msc3672.beacon_info/.*")) .and(header("authorization", "Bearer 1234")) + .and(body_partial_json(&json!({ + "description": "Live Share", + "live": false, + "timeout": 3000, + "org.matrix.msc3488.asset": { "type": "m.self" } + }))) .respond_with(ResponseTemplate::new(200).set_body_json(&*test_json::EVENT_ID)) .mount(&server) .await; @@ -913,7 +929,7 @@ async fn test_stop_sharing_live_location() { ) .await; - let _response = client.sync_once(sync_settings.clone()).await.unwrap(); + client.sync_once(sync_settings.clone()).await.unwrap(); let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); @@ -959,7 +975,7 @@ async fn test_stop_sharing_live_location() { ) .await; - let _response = client.sync_once(sync_settings.clone()).await.unwrap(); + client.sync_once(sync_settings.clone()).await.unwrap(); server.reset().await; let state_events = room.get_state_events(StateEventType::BeaconInfo).await.unwrap();