ruma_client_api/delayed_events/update_delayed_event/
unstable_v1.rs1use ruma_common::{
8 api::{auth_scheme::AccessToken, request, response},
9 metadata,
10};
11
12use super::UpdateAction;
13
14metadata! {
15 method: POST,
16 rate_limited: true,
17 authentication: AccessToken,
18 history: {
19 unstable("org.matrix.msc4140") => "/_matrix/client/unstable/org.matrix.msc4140/delayed_events/{delay_id}",
20 }
21}
22
23#[request]
26pub struct Request {
27 #[ruma_api(path)]
29 pub delay_id: String,
30 pub action: UpdateAction,
32}
33
34impl Request {
35 pub fn new(delay_id: String, action: UpdateAction) -> Self {
37 Self { delay_id, action }
38 }
39}
40
41#[response]
44pub struct Response {}
45impl Response {
46 pub fn new() -> Self {
49 Self {}
50 }
51}
52
53#[cfg(all(test, feature = "client"))]
54mod tests {
55 use std::borrow::Cow;
56
57 use ruma_common::api::{
58 MatrixVersion, OutgoingRequest, SupportedVersions, auth_scheme::SendAccessToken,
59 };
60 use serde_json::{Value as JsonValue, json};
61
62 use super::{Request, UpdateAction};
63 #[test]
64 fn serialize_update_delayed_event_request() {
65 let supported = SupportedVersions {
66 versions: [MatrixVersion::V1_1].into(),
67 features: Default::default(),
68 };
69 let request: http::Request<Vec<u8>> = Request::new("1234".to_owned(), UpdateAction::Cancel)
70 .try_into_http_request(
71 "https://homeserver.tld",
72 SendAccessToken::IfRequired("auth_tok"),
73 Cow::Owned(supported),
74 )
75 .unwrap();
76
77 let (parts, body) = request.into_parts();
78
79 assert_eq!(
80 "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
81 parts.uri.to_string()
82 );
83 assert_eq!("POST", parts.method.to_string());
84 assert_eq!(
85 json!({"action": "cancel"}),
86 serde_json::from_str::<JsonValue>(std::str::from_utf8(&body).unwrap()).unwrap()
87 );
88 }
89}