Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove some uses of sync_timeline_event! in the base and sdk crates #4565

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 34 additions & 50 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1746,12 +1746,13 @@ fn handle_room_member_event_for_profiles(
#[cfg(test)]
mod tests {
use matrix_sdk_test::{
async_test, ruma_response_from_json, sync_timeline_event, InvitedRoomBuilder,
async_test, event_factory::EventFactory, ruma_response_from_json, InvitedRoomBuilder,
LeftRoomBuilder, StateTestEvent, StrippedStateTestEvent, SyncResponseBuilder,
};
#[cfg(feature = "e2e-encryption")]
use ruma::UserId;
use ruma::{api::client as api, room_id, serde::Raw, user_id};
use ruma::{
api::client as api, event_id, events::room::member::MembershipState, room_id, serde::Raw,
user_id,
};
use serde_json::{json, value::to_raw_value};

use super::BaseClient;
Expand All @@ -1771,17 +1772,15 @@ mod tests {
let mut sync_builder = SyncResponseBuilder::new();

let response = sync_builder
.add_left_room(LeftRoomBuilder::new(room_id).add_timeline_event(sync_timeline_event!({
"content": {
"displayname": "Alice",
"membership": "left",
},
"event_id": "$994173582443PhrSn:example.org",
"origin_server_ts": 1432135524678u64,
"sender": user_id,
"state_key": user_id,
"type": "m.room.member",
})))
.add_left_room(
LeftRoomBuilder::new(room_id).add_timeline_event(
EventFactory::new()
.member(user_id)
.membership(MembershipState::Leave)
.display_name("Alice")
.event_id(event_id!("$994173582443PhrSn:example.org")),
),
)
.build_sync_response();
client.receive_sync_response(response).await.unwrap();
assert_eq!(client.get_room(room_id).unwrap().state(), RoomState::Left);
Expand Down Expand Up @@ -1898,13 +1897,32 @@ mod tests {
async fn test_when_there_are_no_latest_encrypted_events_decrypting_them_does_nothing() {
use std::collections::BTreeMap;

use matrix_sdk_test::event_factory::EventFactory;
use ruma::{event_id, events::room::member::MembershipState};

use crate::{rooms::normal::RoomInfoNotableUpdateReasons, StateChanges};

// Given a room
let user_id = user_id!("@u:u.to");
let room_id = room_id!("!r:u.to");
let client = logged_in_base_client(Some(user_id)).await;
let room = process_room_join_test_helper(&client, room_id, "$1", user_id).await;

let mut sync_builder = SyncResponseBuilder::new();

let response = sync_builder
.add_joined_room(
matrix_sdk_test::JoinedRoomBuilder::new(room_id).add_timeline_event(
EventFactory::new()
.member(user_id)
.display_name("Alice")
.membership(MembershipState::Join)
.event_id(event_id!("$1")),
),
)
.build_sync_response();
client.receive_sync_response(response).await.unwrap();

let room = client.get_room(room_id).expect("Just-created room not found!");

// Sanity: it has no latest_encrypted_events or latest_event
assert!(room.latest_encrypted_events().is_empty());
Expand All @@ -1926,40 +1944,6 @@ mod tests {
.contains(RoomInfoNotableUpdateReasons::LATEST_EVENT));
}

// TODO: I wanted to write more tests here for decrypt_latest_events but I got
// lost trying to set up my OlmMachine to be able to encrypt and decrypt
// events. In the meantime, there are tests for the most difficult logic
// inside Room. --andyb

#[cfg(feature = "e2e-encryption")]
async fn process_room_join_test_helper(
client: &BaseClient,
room_id: &ruma::RoomId,
event_id: &str,
user_id: &UserId,
) -> crate::Room {
let mut sync_builder = SyncResponseBuilder::new();
let response = sync_builder
.add_joined_room(matrix_sdk_test::JoinedRoomBuilder::new(room_id).add_timeline_event(
sync_timeline_event!({
"content": {
"displayname": "Alice",
"membership": "join",
},
"event_id": event_id,
"origin_server_ts": 1432135524678u64,
"sender": user_id,
"state_key": user_id,
"type": "m.room.member",
}),
))
.build_sync_response();

client.receive_sync_response(response).await.unwrap();

client.get_room(room_id).expect("Just-created room not found!")
}

#[async_test]
async fn test_deserialization_failure() {
let user_id = user_id!("@alice:example.org");
Expand Down
Loading
Loading