Fix shared history test

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2025-08-12 15:44:45 +02:00
committed by Stefan Ceriu
parent e0feebdb2b
commit 1eb8f6ac16
2 changed files with 34 additions and 12 deletions

View File

@@ -1231,7 +1231,7 @@ impl MatrixMockServer {
&self,
) -> MockEndpoint<'_, AuthenticatedMediaConfigEndpoint> {
let mock = Mock::given(method("GET")).and(path("/_matrix/client/v1/media/config"));
self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint).expect_default_access_token()
self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint)
}
/// Create a prebuilt mock for the endpoint used to get the media config of
@@ -1559,6 +1559,15 @@ impl<'a, T> MockEndpoint<'a, T> {
self
}
/// Don't expect authentication with an access token on this endpoint.
///
/// This should be used to override the default behavior of the endpoint,
/// when the access token is unknown for example.
pub fn do_not_expect_access_token(mut self) -> Self {
self.expected_access_token = ExpectedAccessToken::None;
self
}
/// Specify how to respond to a query (viz., like
/// [`MockBuilder::respond_with`] does), when other predefined responses
/// aren't sufficient.
@@ -3763,13 +3772,6 @@ impl<'a> MockEndpoint<'a, MediaDownloadEndpoint> {
self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!"))
}
/// Returns a successful response with the given bytes.
pub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a> {
self.respond_with(
ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"),
)
}
/// Returns a successful response with a fake image content.
pub fn ok_image(self) -> MatrixMock<'a> {
self.respond_with(
@@ -3799,6 +3801,13 @@ impl<'a> MockEndpoint<'a, AuthedMediaDownloadEndpoint> {
self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!"))
}
/// Returns a successful response with the given bytes.
pub fn ok_bytes(self, bytes: Vec<u8>) -> MatrixMock<'a> {
self.respond_with(
ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"),
)
}
/// Returns a successful response with a fake image content.
pub fn ok_image(self) -> MatrixMock<'a> {
self.respond_with(

View File

@@ -72,7 +72,7 @@ async fn test_shared_history_out_of_order() {
let (event_receiver, mock) =
matrix_mock_server.mock_room_send().ok_with_capture(event_id, alice_user_id);
mock.mock_once().mount().await;
mock.mock_once().named("send").mount().await;
matrix_mock_server
.mock_get_members()
@@ -87,7 +87,13 @@ async fn test_shared_history_out_of_order() {
.expect("We should be able to send an initial message")
.event_id;
matrix_mock_server.mock_authenticated_media_config().ok_default().mock_once().mount().await;
matrix_mock_server
.mock_authenticated_media_config()
.ok_default()
.mock_once()
.named("media_config")
.mount()
.await;
let (receiver, upload_mock) = matrix_mock_server.mock_upload().ok_with_capture(mxid);
upload_mock.mock_once().mount().await;
@@ -118,7 +124,7 @@ async fn test_shared_history_out_of_order() {
let bob_room = bob.get_room(room_id).expect("Bob should have access to the invited room");
matrix_mock_server.mock_room_join(room_id).ok().mock_once().mount().await;
matrix_mock_server.mock_room_join(room_id).ok().mock_once().named("join").mount().await;
bob_room.join().await.expect("Bob should be able to join the room");
let details = bob_room
@@ -132,7 +138,14 @@ async fn test_shared_history_out_of_order() {
);
let bundle_info = bundle_info.await;
matrix_mock_server.mock_media_download().ok_bytes(bundle).mock_once().mount().await;
matrix_mock_server
.mock_authed_media_download()
.do_not_expect_access_token()
.ok_bytes(bundle)
.mock_once()
.named("media_download")
.mount()
.await;
let mut room_key_stream = bob
.encryption()