Skip to content

Commit 9b742fd

Browse files
committed
test: comprehensive beacon_info testing
1 parent d77d387 commit 9b742fd

File tree

1 file changed

+98
-33
lines changed
  • crates/matrix-sdk/tests/integration/room

1 file changed

+98
-33
lines changed

crates/matrix-sdk/tests/integration/room/joined.rs

Lines changed: 98 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
};
55

66
use futures_util::future::join_all;
7+
use js_int::uint;
78
use matrix_sdk::{
89
config::SyncSettings,
910
room::{edit::EditedContent, Receipts, ReportedContentScore, RoomMemberRole},
@@ -18,11 +19,13 @@ use ruma::{
1819
api::client::{membership::Invite3pidInit, receipt::create_receipt::v3::ReceiptType},
1920
assign, event_id,
2021
events::{
22+
location::AssetType,
2123
receipt::ReceiptThread,
2224
room::message::{RoomMessageEventContent, RoomMessageEventContentWithoutRelation},
2325
AnySyncStateEvent, StateEventType, TimelineEventType,
2426
},
25-
int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId, TransactionId,
27+
int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, MilliSecondsSinceUnixEpoch,
28+
OwnedUserId, TransactionId,
2629
};
2730
use serde_json::{json, Value};
2831
use wiremock::{
@@ -780,19 +783,17 @@ async fn test_start_live_location_share_for_room() {
780783
.mount(&server)
781784
.await;
782785

783-
// Initial Sync with no beacon information
784-
mock_sync(&server, &*test_json::SYNC, None).await;
785-
786786
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
787787

788+
mock_sync(&server, &*test_json::SYNC, None).await;
789+
788790
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
789791

790792
let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
791793

792794
let response =
793795
room.start_live_location_share(3000, Some("Live Share".to_owned())).await.unwrap();
794796

795-
// Verify the event is correctly sent.
796797
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);
797798
server.reset().await;
798799

@@ -809,12 +810,12 @@ async fn test_start_live_location_share_for_room() {
809810
"content": {
810811
"description": "Live Share",
811812
"live": true,
812-
"org.matrix.msc3488.ts": 1436829458432_u64,
813+
"org.matrix.msc3488.ts": 1_636_829_458,
813814
"timeout": 3000,
814815
"org.matrix.msc3488.asset": { "type": "m.self" }
815816
},
816817
"event_id": "$15139375514XsgmR:localhost",
817-
"origin_server_ts": 151393755000000_u64,
818+
"origin_server_ts": 1_636_829_458,
818819
"sender": "@example:localhost",
819820
"state_key": "@example:localhost",
820821
"type": "org.matrix.msc3672.beacon_info",
@@ -836,29 +837,30 @@ async fn test_start_live_location_share_for_room() {
836837
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
837838
server.reset().await;
838839

839-
// Verify the event is correctly processed in the state store.
840840
let state_events = room.get_state_events(StateEventType::BeaconInfo).await.unwrap();
841841
assert_eq!(state_events.len(), 1);
842842

843-
if let Some(raw_event) = state_events.first() {
844-
match raw_event.deserialize() {
845-
Ok(AnySyncOrStrippedState::Sync(AnySyncStateEvent::BeaconInfo(e))) => {
846-
let content = e.as_original().unwrap().content.clone();
847-
assert_eq!(e.sender(), room.own_user_id());
848-
assert_eq!(e.state_key(), "@example:localhost");
849-
assert_eq!(e.event_id(), event_id!("$15139375514XsgmR:localhost"));
850-
851-
assert_eq!(content.description, Some("Live Share".to_owned()));
852-
assert_eq!(content.timeout, Duration::from_millis(3000));
853-
assert!(content.live);
854-
}
855-
_ => {
856-
panic!("Expected a BeaconInfo event");
857-
}
858-
}
859-
} else {
860-
panic!("There should be a beacon_info state event");
861-
}
843+
let raw_event = state_events.first().expect("There should be a beacon_info state event");
844+
845+
let ev = match raw_event.deserialize().expect("Failed to deserialize event") {
846+
AnySyncOrStrippedState::Sync(AnySyncStateEvent::BeaconInfo(ev)) => ev,
847+
_ => panic!("Expected a BeaconInfo event"),
848+
};
849+
850+
let content = ev.as_original().unwrap().content.clone();
851+
852+
assert_eq!(ev.sender(), room.own_user_id());
853+
assert_eq!(ev.state_key(), "@example:localhost");
854+
assert_eq!(ev.event_id(), event_id!("$15139375514XsgmR:localhost"));
855+
assert_eq!(ev.event_type(), StateEventType::BeaconInfo);
856+
assert_eq!(ev.origin_server_ts(), MilliSecondsSinceUnixEpoch(uint!(1_636_829_458)));
857+
858+
assert_eq!(content.description, Some("Live Share".to_owned()));
859+
assert_eq!(content.timeout, Duration::from_millis(3000));
860+
assert_eq!(content.ts, MilliSecondsSinceUnixEpoch(uint!(1_636_829_458)));
861+
assert_eq!(content.asset.type_, AssetType::Self_);
862+
863+
assert!(content.live);
862864
}
863865

864866
#[async_test]
@@ -872,6 +874,8 @@ async fn test_stop_sharing_live_location() {
872874
.mount(&server)
873875
.await;
874876

877+
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
878+
875879
mock_sync(
876880
&server,
877881
json!({
@@ -885,12 +889,12 @@ async fn test_stop_sharing_live_location() {
885889
"content": {
886890
"description": "Live Share",
887891
"live": true,
888-
"org.matrix.msc3488.ts": 1436829458432_u64,
889-
"timeout": 86400000,
892+
"org.matrix.msc3488.ts": 1_636_829_458,
893+
"timeout": 3000,
890894
"org.matrix.msc3488.asset": { "type": "m.self" }
891895
},
892896
"event_id": "$15139375514XsgmR:localhost",
893-
"origin_server_ts": 151393755000000_u64,
897+
"origin_server_ts": 1_636_829_458,
894898
"sender": "@example:localhost",
895899
"state_key": "@example:localhost",
896900
"type": "org.matrix.msc3672.beacon_info",
@@ -909,16 +913,77 @@ async fn test_stop_sharing_live_location() {
909913
)
910914
.await;
911915

912-
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
913-
914-
let _response = client.sync_once(sync_settings).await.unwrap();
916+
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
915917

916918
let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
917919

918920
let response = room.stop_live_location_share().await.unwrap();
919921

920922
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);
923+
server.reset().await;
924+
925+
mock_sync(
926+
&server,
927+
json!({
928+
"next_batch": "s526_47314_1_7_1_1_1_1_1",
929+
"rooms": {
930+
"join": {
931+
*DEFAULT_TEST_ROOM_ID: {
932+
"state": {
933+
"events": [
934+
{
935+
"content": {
936+
"description": "Live Share",
937+
"live": false,
938+
"org.matrix.msc3488.ts": 1_636_829_458,
939+
"timeout": 3000,
940+
"org.matrix.msc3488.asset": { "type": "m.self" }
941+
},
942+
"event_id": "$15139375514XsgmR:localhost",
943+
"origin_server_ts": 1_636_829_458,
944+
"sender": "@example:localhost",
945+
"state_key": "@example:localhost",
946+
"type": "org.matrix.msc3672.beacon_info",
947+
"unsigned": {
948+
"age": 7034220
949+
}
950+
},
951+
]
952+
}
953+
}
954+
}
955+
}
956+
957+
}),
958+
None,
959+
)
960+
.await;
961+
962+
let _response = client.sync_once(sync_settings.clone()).await.unwrap();
963+
server.reset().await;
921964

922965
let state_events = room.get_state_events(StateEventType::BeaconInfo).await.unwrap();
923966
assert_eq!(state_events.len(), 1);
967+
968+
let raw_event = state_events.first().expect("There should be a beacon_info state event");
969+
970+
let ev = match raw_event.deserialize().expect("Failed to deserialize event") {
971+
AnySyncOrStrippedState::Sync(AnySyncStateEvent::BeaconInfo(ev)) => ev,
972+
_ => panic!("Expected a BeaconInfo event"),
973+
};
974+
975+
let content = ev.as_original().unwrap().content.clone();
976+
977+
assert_eq!(ev.sender(), room.own_user_id());
978+
assert_eq!(ev.state_key(), "@example:localhost");
979+
assert_eq!(ev.event_id(), event_id!("$15139375514XsgmR:localhost"));
980+
assert_eq!(ev.event_type(), StateEventType::BeaconInfo);
981+
assert_eq!(ev.origin_server_ts(), MilliSecondsSinceUnixEpoch(uint!(1_636_829_458)));
982+
983+
assert_eq!(content.description, Some("Live Share".to_owned()));
984+
assert_eq!(content.timeout, Duration::from_millis(3000));
985+
assert_eq!(content.ts, MilliSecondsSinceUnixEpoch(uint!(1_636_829_458)));
986+
assert_eq!(content.asset.type_, AssetType::Self_);
987+
988+
assert!(!content.live);
924989
}

0 commit comments

Comments
 (0)