Skip to content

Commit 1eb8f6a

Browse files
zecakehstefanceriu
authored andcommitted
Fix shared history test
Signed-off-by: Kévin Commaille <[email protected]>
1 parent e0feebd commit 1eb8f6a

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

crates/matrix-sdk/src/test_utils/mocks/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ impl MatrixMockServer {
12311231
&self,
12321232
) -> MockEndpoint<'_, AuthenticatedMediaConfigEndpoint> {
12331233
let mock = Mock::given(method("GET")).and(path("/_matrix/client/v1/media/config"));
1234-
self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint).expect_default_access_token()
1234+
self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint)
12351235
}
12361236

12371237
/// Create a prebuilt mock for the endpoint used to get the media config of
@@ -1559,6 +1559,15 @@ impl<'a, T> MockEndpoint<'a, T> {
15591559
self
15601560
}
15611561

1562+
/// Don't expect authentication with an access token on this endpoint.
1563+
///
1564+
/// This should be used to override the default behavior of the endpoint,
1565+
/// when the access token is unknown for example.
1566+
pub fn do_not_expect_access_token(mut self) -> Self {
1567+
self.expected_access_token = ExpectedAccessToken::None;
1568+
self
1569+
}
1570+
15621571
/// Specify how to respond to a query (viz., like
15631572
/// [`MockBuilder::respond_with`] does), when other predefined responses
15641573
/// aren't sufficient.
@@ -3763,13 +3772,6 @@ impl<'a> MockEndpoint<'a, MediaDownloadEndpoint> {
37633772
self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!"))
37643773
}
37653774

3766-
/// Returns a successful response with the given bytes.
3767-
pub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a> {
3768-
self.respond_with(
3769-
ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"),
3770-
)
3771-
}
3772-
37733775
/// Returns a successful response with a fake image content.
37743776
pub fn ok_image(self) -> MatrixMock<'a> {
37753777
self.respond_with(
@@ -3799,6 +3801,13 @@ impl<'a> MockEndpoint<'a, AuthedMediaDownloadEndpoint> {
37993801
self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!"))
38003802
}
38013803

3804+
/// Returns a successful response with the given bytes.
3805+
pub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a> {
3806+
self.respond_with(
3807+
ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"),
3808+
)
3809+
}
3810+
38023811
/// Returns a successful response with a fake image content.
38033812
pub fn ok_image(self) -> MatrixMock<'a> {
38043813
self.respond_with(

crates/matrix-sdk/tests/integration/encryption/shared_history.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn test_shared_history_out_of_order() {
7272
let (event_receiver, mock) =
7373
matrix_mock_server.mock_room_send().ok_with_capture(event_id, alice_user_id);
7474

75-
mock.mock_once().mount().await;
75+
mock.mock_once().named("send").mount().await;
7676

7777
matrix_mock_server
7878
.mock_get_members()
@@ -87,7 +87,13 @@ async fn test_shared_history_out_of_order() {
8787
.expect("We should be able to send an initial message")
8888
.event_id;
8989

90-
matrix_mock_server.mock_authenticated_media_config().ok_default().mock_once().mount().await;
90+
matrix_mock_server
91+
.mock_authenticated_media_config()
92+
.ok_default()
93+
.mock_once()
94+
.named("media_config")
95+
.mount()
96+
.await;
9197

9298
let (receiver, upload_mock) = matrix_mock_server.mock_upload().ok_with_capture(mxid);
9399
upload_mock.mock_once().mount().await;
@@ -118,7 +124,7 @@ async fn test_shared_history_out_of_order() {
118124

119125
let bob_room = bob.get_room(room_id).expect("Bob should have access to the invited room");
120126

121-
matrix_mock_server.mock_room_join(room_id).ok().mock_once().mount().await;
127+
matrix_mock_server.mock_room_join(room_id).ok().mock_once().named("join").mount().await;
122128
bob_room.join().await.expect("Bob should be able to join the room");
123129

124130
let details = bob_room
@@ -132,7 +138,14 @@ async fn test_shared_history_out_of_order() {
132138
);
133139

134140
let bundle_info = bundle_info.await;
135-
matrix_mock_server.mock_media_download().ok_bytes(bundle).mock_once().mount().await;
141+
matrix_mock_server
142+
.mock_authed_media_download()
143+
.do_not_expect_access_token()
144+
.ok_bytes(bundle)
145+
.mock_once()
146+
.named("media_download")
147+
.mount()
148+
.await;
136149

137150
let mut room_key_stream = bob
138151
.encryption()

0 commit comments

Comments
 (0)