Skip to content

Commit ce7e7b3

Browse files
committed
test: Refactor the pinned timeline integration test a bit
This should allow us in the future to create more such tests with many more events.
1 parent 8d0f9ff commit ce7e7b3

File tree

1 file changed

+44
-32
lines changed
  • testing/matrix-sdk-integration-testing/src/tests

1 file changed

+44
-32
lines changed

testing/matrix-sdk-integration-testing/src/tests/timeline.rs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use matrix_sdk::{
3333
reply::{EnforceThread, Reply},
3434
},
3535
ruma::{
36-
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId,
36+
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId, UserId,
3737
api::client::room::create_room::v3::{Request as CreateRoomRequest, RoomPreset},
3838
events::{
3939
InitialStateEvent,
@@ -47,7 +47,7 @@ use matrix_sdk::{
4747
},
4848
},
4949
};
50-
use matrix_sdk_test::TestResult;
50+
use matrix_sdk_test::{TestError, TestResult};
5151
use matrix_sdk_ui::{
5252
Timeline,
5353
notification_client::NotificationClient,
@@ -1083,6 +1083,41 @@ async fn test_local_echo_to_send_event_has_encryption_info() -> TestResult {
10831083
Ok(())
10841084
}
10851085

1086+
async fn prepare_room_with_pinned_events(
1087+
alice: &Client,
1088+
recovery_passphrase: &str,
1089+
) -> Result<(OwnedRoomId, OwnedEventId), TestError> {
1090+
let sync_service = SyncService::builder(alice.clone()).build().await?;
1091+
sync_service.start().await;
1092+
1093+
alice.encryption().wait_for_e2ee_initialization_tasks().await;
1094+
alice.encryption().recovery().enable().with_passphrase(recovery_passphrase).await?;
1095+
1096+
debug!("Creating room…");
1097+
let room = alice
1098+
.create_room(assign!(CreateRoomRequest::new(), {
1099+
is_direct: true,
1100+
initial_state: vec![],
1101+
preset: Some(RoomPreset::PrivateChat)
1102+
}))
1103+
.await?;
1104+
1105+
room.enable_encryption().await?;
1106+
1107+
// Send an event to the encrypted room and pin it.
1108+
let room_id = room.room_id().to_owned();
1109+
let result =
1110+
room.send(RoomMessageEventContent::text_plain("It's a secret to everybody")).await?;
1111+
let event_id = result.response.event_id;
1112+
1113+
let timeline = room.timeline().await?;
1114+
timeline.pin_event(&event_id).await?;
1115+
1116+
sync_service.stop().await;
1117+
1118+
Ok((room_id, event_id))
1119+
}
1120+
10861121
/// Test that pinned UTD events, once decrypted by R2D2 (the redecryptor), get
10871122
/// replaced in the timeline with the decrypted variant.
10881123
///
@@ -1110,33 +1145,7 @@ async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
11101145
.await?;
11111146
let user_id = alice.user_id().expect("We should have a user ID by now");
11121147

1113-
let sync_service = SyncService::builder(alice.clone()).build().await?;
1114-
sync_service.start().await;
1115-
1116-
alice.encryption().wait_for_e2ee_initialization_tasks().await;
1117-
alice.encryption().recovery().enable().with_passphrase(RECOVERY_PASSPHRASE).await?;
1118-
1119-
debug!("Creating room…");
1120-
let room = alice
1121-
.create_room(assign!(CreateRoomRequest::new(), {
1122-
is_direct: true,
1123-
initial_state: vec![],
1124-
preset: Some(RoomPreset::PrivateChat)
1125-
}))
1126-
.await?;
1127-
1128-
room.enable_encryption().await?;
1129-
1130-
// Send an event to the encrypted room and pin it.
1131-
let room_id = room.room_id().to_owned();
1132-
let result =
1133-
room.send(RoomMessageEventContent::text_plain("It's a secret to everybody")).await?;
1134-
let event_id = result.response.event_id;
1135-
1136-
let timeline = room.timeline().await?;
1137-
timeline.pin_event(&event_id).await?;
1138-
1139-
sync_service.stop().await;
1148+
let (room_id, event_id) = prepare_room_with_pinned_events(&alice, RECOVERY_PASSPHRASE).await?;
11401149

11411150
// Now `another_alice` comes into play.
11421151
let another_alice = TestClientBuilder::with_exact_username(user_id.localpart().to_owned())
@@ -1206,7 +1215,7 @@ async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
12061215
item.content().is_unable_to_decrypt(),
12071216
"The pinned event should be an UTD as we didn't recover yet"
12081217
);
1209-
assert_eq!(timeline.items().await.len(), 4);
1218+
assert_eq!(pinned_timeline.items().await.len(), 2);
12101219

12111220
// Let's now recover.
12121221
another_alice.encryption().recovery().recover(RECOVERY_PASSPHRASE).await?;
@@ -1226,8 +1235,11 @@ async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
12261235

12271236
// And we check that we don't have any more items in the timeline, the UTD item
12281237
// was indeed replaced.
1229-
let items = timeline.items().await;
1230-
assert_eq!(items.len(), 4);
1238+
let items = pinned_timeline.items().await;
1239+
assert_eq!(items.len(), 2);
1240+
1241+
Ok(())
1242+
}
12311243

12321244
Ok(())
12331245
}

0 commit comments

Comments
 (0)