ruma_client_api/delayed_events/
get_all_delayed_events.rs1pub mod unstable {
6 use ruma_common::{
11 api::{auth_scheme::AccessToken, request, response},
12 metadata,
13 };
14
15 use crate::delayed_events::DelayedEventData;
16
17 metadata! {
18 method: GET,
19 rate_limited: true,
20 authentication: AccessToken,
21 history: {
22 unstable("org.matrix.msc4140") => "/_matrix/client/unstable/org.matrix.msc4140/delayed_events",
23 }
24 }
25
26 #[request]
29 pub struct Request {}
30
31 #[response]
34 pub struct Response {
35 pub delayed_events: Vec<DelayedEventData>,
37 }
38
39 impl Request {
40 pub fn new() -> Self {
42 Self {}
43 }
44 }
45
46 impl Default for Request {
47 fn default() -> Self {
48 Self::new()
49 }
50 }
51
52 impl Response {
53 pub fn new(delayed_events: Vec<DelayedEventData>) -> Self {
55 Self { delayed_events }
56 }
57 }
58
59 #[cfg(all(test, feature = "server"))]
60 mod server_tests {
61
62 use std::time::Duration;
63
64 use js_int::UInt;
65 use ruma_common::{
66 MilliSecondsSinceUnixEpoch, api::OutgoingResponse, owned_event_id, owned_room_id,
67 serde::Raw,
68 };
69 use ruma_events::TimelineEventType;
70 use serde_json::{Value as JsonValue, json};
71
72 use super::Response;
73 use crate::delayed_events::DelayedEventData;
74
75 #[test]
76 fn serialize_get_all_delayed_events_response() {
77 let content = json!({
78 "topic": "test topic"
79 })
80 .to_string();
81
82 let mut event0 = DelayedEventData::new(
83 "a_delay_id".to_owned(),
84 owned_room_id!("!roomid:example.org"),
85 TimelineEventType::RoomTopic,
86 Some("a_state_key".to_owned()),
87 Raw::from_json_string(content).unwrap(),
88 Duration::from_millis(103),
89 MilliSecondsSinceUnixEpoch(UInt::new(70000).unwrap()),
90 );
91
92 event0.event_id = Some(owned_event_id!("$event:imaginary.hs"));
93 event0.finalized_ts = Some(MilliSecondsSinceUnixEpoch(UInt::new(70103).unwrap()));
94
95 let response = Response::new(vec![event0]);
96
97 let response: http::Response<Vec<u8>> = response.try_into_http_response().unwrap();
98
99 assert_eq!(
100 json!({
101 "delayed_events" : [{
102 "content": {
103 "topic": "test topic"
104 },
105 "delay": 103,
106 "delay_id": "a_delay_id",
107 "event_id": "$event:imaginary.hs",
108 "finalised_ts": 70103,
109 "room_id": "!roomid:example.org",
110 "running_since": 70000,
111 "state_key": "a_state_key",
112 "type": "m.room.topic"
113 }]
114 }),
115 serde_json::from_slice::<JsonValue>(response.body()).unwrap()
116 );
117 }
118 }
119}