ruma_client_api/delayed_events/update_delayed_event/
msc4140_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]
25pub struct Request {
26 #[ruma_api(path)]
28 pub delay_id: String,
29
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]
43pub struct Response {}
44impl Response {
45 pub fn new() -> Self {
47 Self {}
48 }
49}
50
51#[cfg(all(test, feature = "client"))]
52mod tests {
53 use std::borrow::Cow;
54
55 use ruma_common::api::{
56 MatrixVersion, OutgoingRequestExt as _, SupportedVersions, auth_scheme::SendAccessToken,
57 };
58 use serde_json::{Value as JsonValue, json};
59
60 use super::{Request, UpdateAction};
61 #[test]
62 fn serialize_update_delayed_event_request() {
63 let supported = SupportedVersions {
64 versions: [MatrixVersion::V1_1].into(),
65 features: Default::default(),
66 };
67 let request: http::Request<Vec<u8>> = Request::new("1234".to_owned(), UpdateAction::Cancel)
68 .try_into_http_request(
69 "https://homeserver.tld",
70 SendAccessToken::IfRequired("auth_tok"),
71 Cow::Owned(supported),
72 )
73 .unwrap();
74
75 let (parts, body) = request.into_parts();
76
77 assert_eq!(
78 "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
79 parts.uri
80 );
81 assert_eq!("POST", parts.method);
82 assert_eq!(
83 json!({"action": "cancel"}),
84 serde_json::from_slice::<JsonValue>(&body).unwrap()
85 );
86 }
87}