Skip to content

Commit b1d1ae8

Browse files
committed
Add test for matrix_sdk::room::Common::timeline()
The test is only run when the `sled_state_store` feature is enabled. This also changes the test_json::MORE_SYNC and test_json::MORE_SYNC_2 to not responsed with a limited timeline.
1 parent b923d2f commit b1d1ae8

File tree

2 files changed

+143
-2
lines changed

2 files changed

+143
-2
lines changed

crates/matrix-sdk-test/src/test_json/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ lazy_static! {
697697
}
698698
},
699699
],
700-
"limited": true,
700+
"limited": false,
701701
"prev_batch": "t392-516_47314_0_7_1_1_1_11444_1"
702702
},
703703
"unread_notifications": {
@@ -828,7 +828,7 @@ lazy_static! {
828828
}
829829
},
830830
],
831-
"limited": true,
831+
"limited": false,
832832
"prev_batch": "s526_47314_0_7_1_1_1_11444_2"
833833
},
834834
"unread_notifications": {

crates/matrix-sdk/src/client.rs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,8 @@ pub(crate) mod test {
23762376
};
23772377

23782378
use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType};
2379+
#[cfg(feature = "sled_state_store")]
2380+
use matrix_sdk_common::deserialized_responses::SyncRoomEvent;
23792381
use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
23802382
use mockito::{mock, Matcher};
23812383
use ruma::{
@@ -3684,4 +3686,143 @@ pub(crate) mod test {
36843686

36853687
matches::assert_matches!(encryption_event, AnySyncStateEvent::RoomEncryption(_));
36863688
}
3689+
3690+
#[async_test]
3691+
#[cfg(feature = "sled_state_store")]
3692+
async fn room_timeline() {
3693+
let client = logged_in_client().await;
3694+
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
3695+
//let mut expected_events = Vec::new();
3696+
3697+
let sync = mock("GET", Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()))
3698+
.with_status(200)
3699+
.with_body(test_json::SYNC.to_string())
3700+
.match_header("authorization", "Bearer 1234")
3701+
.create();
3702+
3703+
let _ = client.sync_once(sync_settings).await.unwrap();
3704+
sync.assert();
3705+
drop(sync);
3706+
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
3707+
let (forward_stream, backward_stream) = room.timeline().await.unwrap();
3708+
3709+
let sync_2 = mock(
3710+
"GET",
3711+
Matcher::Regex(
3712+
r"^/_matrix/client/r0/sync\?.*since=s526_47314_0_7_1_1_1_11444_1.*".to_string(),
3713+
),
3714+
)
3715+
.with_status(200)
3716+
.with_body(test_json::MORE_SYNC.to_string())
3717+
.match_header("authorization", "Bearer 1234")
3718+
.create();
3719+
3720+
let sync_3 = mock(
3721+
"GET",
3722+
Matcher::Regex(
3723+
r"^/_matrix/client/r0/sync\?.*since=s526_47314_0_7_1_1_1_11444_2.*".to_string(),
3724+
),
3725+
)
3726+
.with_status(200)
3727+
.with_body(test_json::MORE_SYNC_2.to_string())
3728+
.match_header("authorization", "Bearer 1234")
3729+
.create();
3730+
3731+
let mocked_messages = mock(
3732+
"GET",
3733+
Matcher::Regex(
3734+
r"^/_matrix/client/r0/rooms/.*/messages.*from=t392-516_47314_0_7_1_1_1_11444_1.*"
3735+
.to_string(),
3736+
),
3737+
)
3738+
.with_status(200)
3739+
.with_body(test_json::SYNC_ROOM_MESSAGES_BATCH_1.to_string())
3740+
.match_header("authorization", "Bearer 1234")
3741+
.create();
3742+
3743+
let mocked_messages_2 = mock(
3744+
"GET",
3745+
Matcher::Regex(
3746+
r"^/_matrix/client/r0/rooms/.*/messages.*from=t47409-4357353_219380_26003_2269.*"
3747+
.to_string(),
3748+
),
3749+
)
3750+
.with_status(200)
3751+
.with_body(test_json::SYNC_ROOM_MESSAGES_BATCH_2.to_string())
3752+
.match_header("authorization", "Bearer 1234")
3753+
.create();
3754+
3755+
assert_eq!(client.sync_token().await, Some("s526_47314_0_7_1_1_1_11444_1".to_string()));
3756+
let sync_settings = SyncSettings::new()
3757+
.timeout(Duration::from_millis(3000))
3758+
.token("s526_47314_0_7_1_1_1_11444_1");
3759+
let _ = client.sync_once(sync_settings).await.unwrap();
3760+
sync_2.assert();
3761+
let sync_settings = SyncSettings::new()
3762+
.timeout(Duration::from_millis(3000))
3763+
.token("s526_47314_0_7_1_1_1_11444_2");
3764+
let _ = client.sync_once(sync_settings).await.unwrap();
3765+
sync_3.assert();
3766+
3767+
let expected_events = vec![
3768+
"$152037280074GZeOm:localhost",
3769+
"$editevid:localhost",
3770+
"$151957878228ssqrJ:localhost",
3771+
"$15275046980maRLj:localhost",
3772+
"$15275047031IXQRi:localhost",
3773+
"$098237280074GZeOm:localhost",
3774+
"$152037280074GZeOm2:localhost",
3775+
"$editevid2:localhost",
3776+
"$151957878228ssqrJ2:localhost",
3777+
"$15275046980maRLj2:localhost",
3778+
"$15275047031IXQRi2:localhost",
3779+
"$098237280074GZeOm2:localhost",
3780+
];
3781+
3782+
use futures_util::StreamExt;
3783+
let forward_events =
3784+
forward_stream.take(expected_events.len()).collect::<Vec<SyncRoomEvent>>().await;
3785+
3786+
assert!(forward_events.into_iter().zip(expected_events.iter()).all(|(a, b)| &a
3787+
.event_id()
3788+
.unwrap()
3789+
.as_str()
3790+
== b));
3791+
3792+
let expected_events = vec![
3793+
"$152037280074GZeOm2:localhost",
3794+
"$editevid2:localhost",
3795+
"$151957878228ssqrJ2:localhost",
3796+
"$15275046980maRLj2:localhost",
3797+
"$15275047031IXQRi2:localhost",
3798+
"$098237280074GZeOm2:localhost",
3799+
"$152037280074GZeOm:localhost",
3800+
"$editevid:localhost",
3801+
"$151957878228ssqrJ:localhost",
3802+
"$15275046980maRLj:localhost",
3803+
"$15275047031IXQRi:localhost",
3804+
"$098237280074GZeOm:localhost",
3805+
"$1444812213350496Caaaf:example.com",
3806+
"$1444812213350496Cbbbf:example.com",
3807+
"$1444812213350496Ccccf:example.com",
3808+
"$1444812213350496Caaak:example.com",
3809+
"$1444812213350496Cbbbk:example.com",
3810+
"$1444812213350496Cccck:example.com",
3811+
];
3812+
3813+
let backward_events = backward_stream
3814+
.take(expected_events.len())
3815+
.collect::<Vec<crate::Result<SyncRoomEvent>>>()
3816+
.await;
3817+
3818+
assert!(backward_events.into_iter().zip(expected_events.iter()).all(|(a, b)| &a
3819+
.unwrap()
3820+
.event_id()
3821+
.unwrap()
3822+
.as_str()
3823+
== b));
3824+
3825+
mocked_messages.assert();
3826+
mocked_messages_2.assert();
3827+
}
36873828
}

0 commit comments

Comments
 (0)