test: replace ENCRYPTION_CONTENT usages with EventFactory

Replace all usages of ENCRYPTION_CONTENT and
ENCRYPTION_WITH_ENCRYPTED_STATE_EVENTS_CONTENT static values
with EventFactory::room_encryption().into_content() calls.

This uses the new into_content() method to get just the event
content for HTTP response mocking.
This commit is contained in:
Benjamin Bouvier
2026-02-16 13:04:09 +01:00
parent 6b99f37268
commit 4c6d5f9654
5 changed files with 10 additions and 26 deletions
+2 -2
View File
@@ -2030,7 +2030,7 @@ mod tests {
use matrix_sdk_test::{
DEFAULT_TEST_ROOM_ID, JoinedRoomBuilder, SyncResponseBuilder, async_test,
event_factory::EventFactory, test_json,
event_factory::EventFactory,
};
use ruma::{
event_id,
@@ -2066,7 +2066,7 @@ mod tests {
.and(header("authorization", "Bearer 1234"))
.respond_with(
ResponseTemplate::new(200)
.set_body_json(&*test_json::sync_events::ENCRYPTION_CONTENT),
.set_body_json(EventFactory::new().room_encryption().into_content()),
)
.mount(&server)
.await;
+2 -2
View File
@@ -4887,7 +4887,7 @@ mod tests {
use matrix_sdk_base::{ComposerDraft, DraftAttachment, store::ComposerDraftType};
use matrix_sdk_test::{
JoinedRoomBuilder, SyncResponseBuilder, async_test, event_factory::EventFactory, test_json,
JoinedRoomBuilder, SyncResponseBuilder, async_test, event_factory::EventFactory,
};
use ruma::{
RoomVersionId, event_id,
@@ -4943,7 +4943,7 @@ mod tests {
.and(header("authorization", "Bearer 1234"))
.respond_with(
ResponseTemplate::new(200)
.set_body_json(&*test_json::sync_events::ENCRYPTION_CONTENT),
.set_body_json(EventFactory::new().room_encryption().into_content()),
)
.mount(&server)
.await;
@@ -28,7 +28,7 @@ use matrix_sdk_base::deserialized_responses::TimelineEvent;
use matrix_sdk_base::recent_emojis::RecentEmojisContent;
use matrix_sdk_test::{
InvitedRoomBuilder, JoinedRoomBuilder, KnockedRoomBuilder, LeftRoomBuilder,
SyncResponseBuilder, test_json,
SyncResponseBuilder, event_factory::EventFactory, test_json,
};
use percent_encoding::{AsciiSet, CONTROLS};
use ruma::{
@@ -2801,7 +2801,8 @@ impl<'a> MockEndpoint<'a, EncryptionStateEndpoint> {
/// ```
pub fn encrypted(self) -> MatrixMock<'a> {
self.respond_with(
ResponseTemplate::new(200).set_body_json(&*test_json::sync_events::ENCRYPTION_CONTENT),
ResponseTemplate::new(200)
.set_body_json(EventFactory::new().room_encryption().into_content()),
)
}
@@ -2831,7 +2832,7 @@ impl<'a> MockEndpoint<'a, EncryptionStateEndpoint> {
#[cfg(feature = "experimental-encrypted-state-events")]
pub fn state_encrypted(self) -> MatrixMock<'a> {
self.respond_with(ResponseTemplate::new(200).set_body_json(
&*test_json::sync_events::ENCRYPTION_WITH_ENCRYPTED_STATE_EVENTS_CONTENT,
EventFactory::new().room_encryption_with_state_encryption().into_content(),
))
}
+2 -2
View File
@@ -19,7 +19,7 @@ use wiremock::{
matchers::{header, method, path_regex},
};
use crate::test_json;
use crate::{event_factory::EventFactory, test_json};
/// Mount a Mock on the given server to handle the `GET
/// /rooms/.../state/m.room.encryption` endpoint with an option whether it
@@ -33,7 +33,7 @@ pub async fn mock_encryption_state(server: &MockServer, is_encrypted: bool) {
builder
.respond_with(
ResponseTemplate::new(200)
.set_body_json(&*test_json::sync_events::ENCRYPTION_CONTENT),
.set_body_json(EventFactory::new().room_encryption().into_content()),
)
.mount(server)
.await;
@@ -13,23 +13,6 @@ pub static FULLY_READ: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static ENCRYPTION_CONTENT: Lazy<JsonValue> = Lazy::new(|| {
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"rotation_period_ms": 604800000,
"rotation_period_msgs": 100
})
});
pub static ENCRYPTION_WITH_ENCRYPTED_STATE_EVENTS_CONTENT: Lazy<JsonValue> = Lazy::new(|| {
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"rotation_period_ms": 604800000,
"rotation_period_msgs": 100,
"io.element.msc4362.encrypt_state_events": true
})
});
// TODO: Move `prev_content` into `unsigned` once ruma supports it
pub static MEMBER: Lazy<JsonValue> = Lazy::new(|| {
json!({