Skip to content

Commit

Permalink
test: validate body of request
Browse files Browse the repository at this point in the history
  • Loading branch information
torrybr committed Jul 25, 2024
1 parent 9b742fd commit 35231ea
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/matrix-sdk/tests/integration/room/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 35231ea

Please sign in to comment.