diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 9bd59a911b5..e9cd648c10a 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -9,12 +9,10 @@ use matrix_sdk::{ room::{edit::EditedContent, Receipts, ReportedContentScore, RoomMemberRole}, test_utils::events::EventFactory, }; -use matrix_sdk_base::RoomState; +use matrix_sdk_base::{deserialized_responses::AnySyncOrStrippedState, RoomState}; use matrix_sdk_test::{ - async_test, test_json, - test_json::sync::{CUSTOM_ROOM_POWER_LEVELS, LIVE_LOCATION_SHARING_SYNC}, - EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, - DEFAULT_TEST_ROOM_ID, + async_test, test_json, test_json::sync::CUSTOM_ROOM_POWER_LEVELS, EphemeralTestEvent, + GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder, DEFAULT_TEST_ROOM_ID, }; use ruma::{ api::client::{membership::Invite3pidInit, receipt::create_receipt::v3::ReceiptType}, @@ -22,7 +20,7 @@ use ruma::{ events::{ receipt::ReceiptThread, room::message::{RoomMessageEventContent, RoomMessageEventContentWithoutRelation}, - StateEventType, TimelineEventType, + AnySyncStateEvent, StateEventType, TimelineEventType, }, int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId, TransactionId, }; @@ -782,16 +780,85 @@ async fn test_start_live_location_share_for_room() { .mount(&server) .await; + // Initial Sync with no beacon information mock_sync(&server, &*test_json::SYNC, None).await; let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000)); - let _response = client.sync_once(sync_settings).await.unwrap(); + let _response = client.sync_once(sync_settings.clone()).await.unwrap(); let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap(); - let response = room.start_live_location_share(3000, None).await.unwrap(); + let response = + room.start_live_location_share(3000, Some("Live Share".to_string())).await.unwrap(); + + // Verify the event is correctly sent. assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id); + server.reset().await; + + mock_sync( + &server, + json!({ + "next_batch": "s526_47314_0_7_1_1_1_1_1", + "rooms": { + "join": { + *DEFAULT_TEST_ROOM_ID: { + "state": { + "events": [ + { + "content": { + "description": "Live Share", + "live": true, + "org.matrix.msc3488.ts": 1436829458432_u64, + "timeout": 3000, + "org.matrix.msc3488.asset": { "type": "m.self" } + }, + "event_id": "$15139375514XsgmR:localhost", + "origin_server_ts": 151393755000000_u64, + "sender": "@example:localhost", + "state_key": "@example:localhost", + "type": "org.matrix.msc3672.beacon_info", + "unsigned": { + "age": 7034220 + } + }, + ] + } + } + } + } + + }), + None, + ) + .await; + + let _response = client.sync_once(sync_settings.clone()).await.unwrap(); + server.reset().await; + + // Verify the event is correctly processed in the state store. + let state_events = room.get_state_events(StateEventType::BeaconInfo).await.unwrap(); + assert_eq!(state_events.len(), 1); + + if let Some(raw_event) = state_events.first() { + match raw_event.deserialize() { + Ok(AnySyncOrStrippedState::Sync(AnySyncStateEvent::BeaconInfo(e))) => { + let content = e.as_original().unwrap().content.clone(); + assert_eq!(e.sender(), room.own_user_id()); + assert_eq!(e.state_key(), "@example:localhost"); + assert_eq!(e.event_id(), event_id!("$15139375514XsgmR:localhost")); + + assert_eq!(content.description, Some("Live Share".to_string())); + assert_eq!(content.timeout, Duration::from_millis(3000)); + assert!(content.live); + } + _ => { + panic!("Expected a BeaconInfo event"); + } + } + } else { + panic!("There should be a beacon_info state event"); + } } #[async_test] @@ -805,7 +872,42 @@ async fn test_stop_sharing_live_location() { .mount(&server) .await; - mock_sync(&server, &*LIVE_LOCATION_SHARING_SYNC, None).await; + mock_sync( + &server, + json!({ + "next_batch": "s526_47314_0_7_1_1_1_1_1", + "rooms": { + "join": { + *DEFAULT_TEST_ROOM_ID: { + "state": { + "events": [ + { + "content": { + "description": "Live Share", + "live": true, + "org.matrix.msc3488.ts": 1436829458432_u64, + "timeout": 86400000, + "org.matrix.msc3488.asset": { "type": "m.self" } + }, + "event_id": "$15139375514XsgmR:localhost", + "origin_server_ts": 151393755000000_u64, + "sender": "@example:localhost", + "state_key": "@example:localhost", + "type": "org.matrix.msc3672.beacon_info", + "unsigned": { + "age": 7034220 + } + }, + ] + } + } + } + } + + }), + None, + ) + .await; let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));