Skip to content

Commit 47e8181

Browse files
jmartinespHywan
authored andcommitted
test: Add extra test for the active call state
Also, adapt the other tests to the new return type
1 parent fe015b7 commit 47e8181

File tree

1 file changed

+73
-5
lines changed
  • crates/matrix-sdk/tests/integration/room

1 file changed

+73
-5
lines changed

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

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ use ruma::{
2727
api::client::{membership::Invite3pidInit, receipt::create_receipt::v3::ReceiptType},
2828
assign, event_id,
2929
events::{
30+
call::{
31+
member::{
32+
ActiveFocus, ActiveLivekitFocus, Application, CallApplicationContent,
33+
CallMemberEventContent, CallScope,
34+
},
35+
notify::{ApplicationType, CallNotifyEventContent, NotifyType},
36+
},
3037
direct::DirectUserIdentifier,
3138
receipt::ReceiptThread,
3239
room::{
3340
member::MembershipState,
3441
message::{RoomMessageEventContent, RoomMessageEventContentWithoutRelation},
3542
},
36-
RoomAccountDataEventType, TimelineEventType,
43+
Mentions, RoomAccountDataEventType, TimelineEventType,
3744
},
38-
int, mxc_uri, owned_event_id, room_id, thirdparty, user_id, OwnedUserId, TransactionId,
45+
int, mxc_uri, owned_device_id, owned_event_id, room_id, thirdparty, user_id, OwnedUserId,
46+
TransactionId,
3947
};
4048
use serde_json::{from_value, json, Value};
4149
use stream_assert::assert_pending;
@@ -828,7 +836,8 @@ async fn test_call_notifications_ring_for_dms() {
828836
.mount(&server)
829837
.await;
830838

831-
room.send_call_notification_if_needed().await.unwrap();
839+
let sent_event = room.send_call_notification_if_needed().await.unwrap();
840+
assert!(sent_event);
832841
}
833842

834843
#[async_test]
@@ -871,7 +880,8 @@ async fn test_call_notifications_notify_for_rooms() {
871880
.mount(&server)
872881
.await;
873882

874-
room.send_call_notification_if_needed().await.unwrap();
883+
let sent_event = room.send_call_notification_if_needed().await.unwrap();
884+
assert!(sent_event);
875885
}
876886

877887
#[async_test]
@@ -906,7 +916,65 @@ async fn test_call_notifications_dont_notify_room_without_mention_powerlevel() {
906916
.mount(&server)
907917
.await;
908918

909-
room.send_call_notification_if_needed().await.unwrap();
919+
let sent_event = room.send_call_notification_if_needed().await.unwrap();
920+
assert!(!sent_event);
921+
}
922+
923+
#[async_test]
924+
async fn test_call_notifications_dont_notify_room_with_an_existing_call() {
925+
let (client, server) = logged_in_client_with_server().await;
926+
927+
let mut sync_builder = SyncResponseBuilder::new();
928+
let event_factory = EventFactory::new().room(&DEFAULT_TEST_ROOM_ID);
929+
let call_notify_event = event_factory
930+
.event(CallNotifyEventContent::new(
931+
"call_id".to_owned(),
932+
ApplicationType::Call,
933+
NotifyType::Notify,
934+
Mentions::new(),
935+
))
936+
.sender(user_id!("@alice:example.org"))
937+
.into_raw_sync();
938+
939+
let call_member_event = event_factory
940+
.event(CallMemberEventContent::new(
941+
Application::Call(CallApplicationContent::new("call_id".to_owned(), CallScope::Room)),
942+
owned_device_id!("a-device-id"),
943+
ActiveFocus::Livekit(ActiveLivekitFocus::new()),
944+
Vec::new(),
945+
None,
946+
))
947+
.sender(user_id!("@alice:example.org"))
948+
.state_key("_@alice:example.org_a-device-id")
949+
.into_raw_sync()
950+
.cast();
951+
952+
sync_builder.add_joined_room(
953+
JoinedRoomBuilder::default()
954+
.add_timeline_bulk([call_notify_event])
955+
.add_state_bulk([call_member_event]),
956+
);
957+
958+
mock_sync(&server, sync_builder.build_json_sync_response(), None).await;
959+
mock_encryption_state(&server, false).await;
960+
961+
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
962+
let _response = client.sync_once(sync_settings).await.unwrap();
963+
964+
let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
965+
assert!(room.has_active_room_call());
966+
assert!(!room.is_direct().await.unwrap());
967+
968+
Mock::given(method("PUT"))
969+
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/send/.*"))
970+
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"event_id": "$event_id"})))
971+
// Expect no calls of the send because we dont have permission to notify.
972+
.expect(0)
973+
.mount(&server)
974+
.await;
975+
976+
let sent_event = room.send_call_notification_if_needed().await.unwrap();
977+
assert!(!sent_event);
910978
}
911979

912980
#[async_test]

0 commit comments

Comments
 (0)