31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1 | mod support; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | use macltok::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 4 | ClientHandle, CreateRoomOptions, Engine, EngineConfig, EngineError, ErrorKind, EventStream, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 5 | RoomPreset, RoomVisibility, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | use matrix_sdk::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | ruma::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | api::client::sync::sync_events::v5, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | events::{GlobalAccountDataEventType, RoomAccountDataEventType}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | room_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | serde::Raw, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | server_name, user_id, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 14 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 15 | test_utils::mocks::MatrixMockServer, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 16 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | use matrix_sdk_test::{InvitedRoomBuilder, JoinedRoomBuilder}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 18 | use serde_json::json; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | use tokio::task::JoinHandle; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 20 | use wiremock::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 21 | Mock, ResponseTemplate, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 22 | matchers::{body_partial_json, method, path, path_regex, query_param}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 23 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 24 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 25 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 26 | async fn joining_by_room_id_forwards_via_servers() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 27 | let room_id = room_id!("!join:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 28 | let (server, handle, mut events, running) = start_engine().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | Mock::given(method("POST")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 30 | .and(path(format!("/_matrix/client/v3/join/{room_id}"))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 31 | .and(query_param("via", "relay.example")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 32 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({ "room_id": room_id }))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 35 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 36 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | let joined_room = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | .join_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | room_id.to_owned().into(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 40 | vec![server_name!("relay.example").to_owned()], |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 44 | assert_eq!(joined_room, room_id); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 45 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 46 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 47 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 48 | #[tokio::test] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 49 | async fn leaving_then_forgetting_a_room_hits_the_expected_endpoints() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 50 | let room_id = room_id!("!leave:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 51 | let (server, client) = configured_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | server.sync_joined_room(&client, room_id).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 53 | server.mock_room_leave().ok(room_id).expect(1).mount().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 54 | server.mock_room_forget().ok().expect(1).mount().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 55 | let (handle, mut events, running) = run_client(client).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 56 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 57 | handle.leave_room(room_id.to_owned()).await.unwrap(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 58 | handle.forget_room(room_id.to_owned()).await.unwrap(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 59 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 60 | support::shut_down(&handle, &mut events, running).await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 61 | drop(server); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 62 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 63 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 64 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 65 | async fn accepting_and_rejecting_invites_use_the_expected_endpoints() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 66 | let accepted = room_id!("!accepted:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 67 | let rejected = room_id!("!rejected:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 68 | let (server, client) = configured_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 69 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 70 | .sync_room(&client, InvitedRoomBuilder::new(accepted)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 71 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 72 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 73 | .sync_room(&client, InvitedRoomBuilder::new(rejected)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 74 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 75 | server.mock_room_join(accepted).ok().expect(1).mount().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 76 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 77 | .mock_room_leave() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 78 | .ok(rejected) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 79 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 80 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 81 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 82 | let (handle, mut events, running) = run_client(client).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 83 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 84 | handle.accept_invite(accepted.to_owned()).await.unwrap(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | handle.reject_invite(rejected.to_owned()).await.unwrap(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 86 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 87 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 88 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 89 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 90 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 91 | async fn creating_a_room_forwards_options() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 92 | let (server, handle, mut events, running) = start_engine().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 93 | Mock::given(method("POST")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 94 | .and(path("/_matrix/client/v3/createRoom")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 95 | .and(body_partial_json(json!({ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 96 | "name": "Planning", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 97 | "topic": "Next release", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 98 | "room_alias_name": "planning", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 99 | "invite": ["@partner:localhost"], |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 100 | "visibility": "public", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 101 | "preset": "public_chat" |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 102 | }))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 103 | .respond_with( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 104 | ResponseTemplate::new(200).set_body_json(json!({ "room_id": "!created:localhost" })), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 105 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 106 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 107 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 108 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 109 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 110 | let created_room = handle |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 111 | .create_room( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 112 | CreateRoomOptions::default() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 113 | .with_name("Planning") |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 114 | .with_topic("Next release") |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 115 | .with_alias_localpart("planning") |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 116 | .with_invite(vec![user_id!("@partner:localhost").to_owned()]) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 117 | .with_visibility(RoomVisibility::Public) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 118 | .with_preset(RoomPreset::PublicChat), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 119 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 120 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 121 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 122 | assert_eq!(created_room, room_id!("!created:localhost").to_owned()); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 123 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 124 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 125 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 126 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 127 | async fn creating_a_direct_room_invites_the_other_user() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 128 | let (server, handle, mut events, running) = start_engine().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 129 | Mock::given(method("POST")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 130 | .and(path("/_matrix/client/v3/createRoom")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 131 | .and(body_partial_json(json!({ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 132 | "invite": ["@partner:localhost"], |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 133 | "is_direct": true, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 134 | "preset": "trusted_private_chat" |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 135 | }))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 136 | .respond_with( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 137 | ResponseTemplate::new(200).set_body_json(json!({ "room_id": "!direct:localhost" })), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 138 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 139 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 140 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 142 | Mock::given(method("GET")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 143 | .and(path_regex( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 144 | r"^/_matrix/client/v3/user/.*/account_data/m\.direct$", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 145 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 146 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 147 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 148 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 149 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 150 | Mock::given(method("PUT")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 151 | .and(path_regex( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 152 | r"^/_matrix/client/v3/user/.*/account_data/m\.direct$", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 153 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 154 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 155 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 156 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 157 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 158 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 159 | let direct_room = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 160 | .create_direct(user_id!("@partner:localhost").to_owned()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 161 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 162 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 163 | assert_eq!(direct_room, room_id!("!direct:localhost").to_owned()); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 164 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 165 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 166 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 167 | #[tokio::test] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 168 | async fn unknown_rooms_fail_membership_commands_with_room_unknown() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 169 | let (server, handle, mut events, running) = start_engine().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 170 | let unknown = room_id!("!unknown:localhost"); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 171 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | assert_eq!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | handle |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | .leave_room(unknown.to_owned()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 175 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 176 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 177 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 179 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 180 | assert_eq!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 181 | handle |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 182 | .forget_room(unknown.to_owned()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 183 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 184 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 185 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 186 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 187 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 188 | assert_eq!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 189 | handle |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 190 | .accept_invite(unknown.to_owned()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 191 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 192 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 193 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 194 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 195 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 196 | assert_eq!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 197 | handle |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 198 | .reject_invite(unknown.to_owned()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 199 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 200 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 201 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 202 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 203 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 204 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 205 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 206 | drop(server); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 207 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 208 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 209 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 210 | async fn account_data_reads_synced_values_and_writes_raw_content() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 211 | let room_id = room_id!("!account-data:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 212 | let (server, client) = configured_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 213 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 214 | .sync_room( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 215 | &client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 216 | JoinedRoomBuilder::new(room_id).add_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 217 | Raw::new(&json!({ "type": "m.fully_read", "content": { "event_id": "$seen:localhost" } })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 218 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 219 | .cast_unchecked(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 220 | ), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 221 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 222 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 223 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 224 | .mock_sync() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 225 | .ok_and_run(&client, |builder| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 226 | builder.add_custom_global_account_data(json!({ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 227 | "type": "com.example.preferences", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 228 | "content": { "theme": "dark" } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 229 | })); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 230 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 231 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 232 | let (engine, handle, mut events) = Engine::from_client(client, EngineConfig::default()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 233 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 234 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 235 | let running = tokio::spawn(engine.run()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 236 | let global_type = GlobalAccountDataEventType::from("com.example.preferences".to_owned()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 237 | let room_type = RoomAccountDataEventType::FullyRead; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 238 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 239 | let global = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 240 | .global_account_data(global_type.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 241 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 242 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 243 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 244 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 245 | global.deserialize_as::<serde_json::Value>().unwrap()["theme"], |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 246 | "dark" |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 247 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 248 | let room = handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 249 | .room_account_data(room_id, room_type.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 250 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 251 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 252 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 253 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 254 | room.deserialize_as::<serde_json::Value>().unwrap()["content"]["event_id"], |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 255 | "$seen:localhost" |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 256 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 257 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 258 | handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 259 | .room_account_data(room_id!("!missing:localhost"), room_type.clone()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 260 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 261 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 262 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 263 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 264 | ); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 265 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 266 | Mock::given(method("PUT")) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 267 | .and(path( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 268 | "/_matrix/client/v3/user/@example:localhost/account_data/com.example.preferences", |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 269 | )) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 270 | .and(body_partial_json(json!({ "theme": "light" }))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 271 | .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 272 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 273 | .mount(server.server()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 274 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 275 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 276 | .mock_set_room_account_data(room_type.clone()) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 277 | .ok() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 278 | .expect(1) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 279 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 280 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 281 | handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 282 | .set_global_account_data( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 283 | global_type, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 284 | Raw::new(&json!({ "theme": "light" })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 285 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 286 | .cast_unchecked(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 287 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 288 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 289 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 290 | handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 291 | .set_room_account_data( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 292 | room_id.to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 293 | room_type, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 294 | Raw::new(&json!({ "event_id": "$later:localhost" })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 295 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 296 | .cast_unchecked(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 297 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 298 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 299 | .unwrap(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 300 | assert_eq!( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 301 | handle |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 302 | .set_room_account_data( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 303 | room_id!("!missing:localhost").to_owned(), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 304 | RoomAccountDataEventType::FullyRead, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 305 | Raw::new(&json!({ "event_id": "$later:localhost" })) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 306 | .unwrap() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 307 | .cast_unchecked() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 308 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 309 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 310 | .unwrap_err() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 311 | .kind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 312 | ErrorKind::RoomUnknown |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 313 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 314 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 315 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 316 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 317 | async fn configured_client() -> (MatrixMockServer, matrix_sdk::Client) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 318 | let server = MatrixMockServer::new().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 319 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 320 | .mock_sliding_sync() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 321 | .ok(v5::Response::new("1".to_owned())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 322 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 323 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 324 | let client = server.client_builder().build().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 325 | server.mock_room_state_encryption().plain().mount().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 326 | (server, client) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 327 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 328 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 329 | async fn start_engine() -> ( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 330 | MatrixMockServer, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 331 | ClientHandle, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 332 | EventStream, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 333 | JoinHandle<Result<(), EngineError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 334 | ) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 335 | let (server, client) = configured_client().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 336 | let (handle, events, running) = run_client(client).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 337 | (server, handle, events, running) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 338 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 339 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 340 | async fn run_client( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 341 | client: matrix_sdk::Client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 342 | ) -> ( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 343 | ClientHandle, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 344 | EventStream, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 345 | JoinHandle<Result<(), EngineError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 346 | ) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 347 | let config = EngineConfig::default().with_initial_history_limit(0); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 348 | let (engine, handle, events) = Engine::from_client(client, config).await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 349 | let running = tokio::spawn(engine.run()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 350 | (handle, events, running) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 351 | } |