Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Nov 15, 2024
1 parent 116fe07 commit 4f52929
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
47 changes: 42 additions & 5 deletions crates/matrix-sdk/tests/integration/room/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use matrix_sdk_test::{
async_test,
mocks::{mock_encryption_state, mock_redaction},
test_json::{self, sync::CUSTOM_ROOM_POWER_LEVELS},
EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, SyncResponseBuilder,
DEFAULT_TEST_ROOM_ID,
EphemeralTestEvent, GlobalAccountDataTestEvent, JoinedRoomBuilder, StateTestEvent,
SyncResponseBuilder, DEFAULT_TEST_ROOM_ID,
};
use ruma::{
api::client::{membership::Invite3pidInit, receipt::create_receipt::v3::ReceiptType},
Expand Down Expand Up @@ -635,7 +635,8 @@ async fn test_call_notifications_ring_for_dms() {
let (client, server) = logged_in_client_with_server().await;

let mut sync_builder = SyncResponseBuilder::new();
sync_builder.add_joined_room(JoinedRoomBuilder::default());
let room_builder = JoinedRoomBuilder::default().add_state_event(StateTestEvent::PowerLevels);
sync_builder.add_joined_room(room_builder);
sync_builder.add_global_account_data_event(GlobalAccountDataTestEvent::Direct);

mock_sync(&server, sync_builder.build_json_sync_response(), None).await;
Expand Down Expand Up @@ -678,9 +679,10 @@ async fn test_call_notifications_notify_for_rooms() {
let (client, server) = logged_in_client_with_server().await;

let mut sync_builder = SyncResponseBuilder::new();
sync_builder.add_joined_room(JoinedRoomBuilder::default());

let room_builder = JoinedRoomBuilder::default().add_state_event(StateTestEvent::PowerLevels);
sync_builder.add_joined_room(room_builder);
mock_sync(&server, sync_builder.build_json_sync_response(), None).await;

mock_encryption_state(&server, false).await;

let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
Expand Down Expand Up @@ -715,6 +717,41 @@ async fn test_call_notifications_notify_for_rooms() {
room.send_call_notification_if_needed().await.unwrap();
}

#[async_test]
async fn test_call_notifications_dont_notify_room_without_mention_powerlevel() {
let (client, server) = logged_in_client_with_server().await;

let mut sync_builder = SyncResponseBuilder::new();
let mut power_level_event = StateTestEvent::PowerLevels.into_json_value();
// Allow noone to send room notify events.
*power_level_event.get_mut("content").unwrap().get_mut("notifications").unwrap() =
json!({"room": 101});

sync_builder.add_joined_room(
JoinedRoomBuilder::default().add_state_event(StateTestEvent::Custom(power_level_event)),
);

mock_sync(&server, sync_builder.build_json_sync_response(), None).await;
mock_encryption_state(&server, false).await;

let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
let _response = client.sync_once(sync_settings).await.unwrap();

let room = client.get_room(&DEFAULT_TEST_ROOM_ID).unwrap();
assert!(!room.is_direct().await.unwrap());
assert!(!room.has_active_room_call());

Mock::given(method("PUT"))
.and(path_regex(r"^/_matrix/client/r0/rooms/.*/send/.*"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"event_id": "$event_id"})))
// Expect no calls of the send because we dont have permission to notify.
.expect(0)
.mount(&server)
.await;

room.send_call_notification_if_needed().await.unwrap();
}

#[async_test]
async fn test_make_reply_event_doesnt_require_event_cache() {
// Even if we don't have enabled the event cache, we'll resort to using the
Expand Down
3 changes: 3 additions & 0 deletions testing/matrix-sdk-test/src/test_json/sync_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ pub static POWER_LEVELS: Lazy<JsonValue> = Lazy::new(|| {
"kick": 50,
"redact": 50,
"state_default": 50,
"notifications": {
"room": 0
},
"users": {
"@example:localhost": 100,
"@bob:localhost": 0
Expand Down

0 comments on commit 4f52929

Please sign in to comment.