Skip to content

Commit

Permalink
test: inline mock sync json and validate state store processing beacons
Browse files Browse the repository at this point in the history
  • Loading branch information
torrybr committed Jul 23, 2024
1 parent 02069b7 commit ffa4d48
Showing 1 changed file with 111 additions and 9 deletions.
120 changes: 111 additions & 9 deletions crates/matrix-sdk/tests/integration/room/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ 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},
assign, event_id,
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,
};
Expand Down Expand Up @@ -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_owned())).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_owned()));
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]
Expand All @@ -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));

Expand Down

0 comments on commit ffa4d48

Please sign in to comment.