synapse_admin_api/background_updates/enabled/
v1.rs

1//! [POST /_synapse/admin/v1/background_updates/enabled](https://github.com/element-hq/synapse/blob/develop/docs/usage/administration/admin_api/background_updates.md#enabled)
2
3use ruma::{
4    api::{request, response, Metadata},
5    metadata,
6};
7use serde::{Deserialize, Serialize};
8
9const METADATA: Metadata = metadata! {
10    method: POST,
11    rate_limited: false,
12    authentication: AccessToken,
13    history: {
14        unstable => "/_synapse/admin/v1/background_updates/enabled",
15    }
16};
17
18#[request]
19pub struct Request {
20    /// Sets whether the background updates are enabled.
21    pub enabled: bool,
22}
23
24#[response]
25#[derive(Serialize, Deserialize, PartialEq)]
26pub struct Response {
27    /// Whether the background updates are enabled or disabled.
28    pub enabled: bool,
29}
30
31impl Request {
32    /// Creates a `Request` with the given `enabled` value.
33    pub fn new(enabled: bool) -> Self {
34        Self { enabled }
35    }
36}
37
38impl Response {
39    /// Creates a `Response` with the given `enabled` value.
40    pub fn new(enabled: bool) -> Self {
41        Self { enabled }
42    }
43}
44
45#[test]
46fn test_enabled_background_updates() {
47    let enabled = true;
48
49    // Check create request
50    let request = Request::new(enabled);
51    assert!(request.enabled);
52
53    // Check create response
54    let response = Response::new(enabled);
55    assert!(request.enabled);
56
57    // Serialize
58    let serialized = serde_json::to_string(&response).expect("Failed to serialize");
59    assert_eq!(serialized, "{\"enabled\":true}");
60
61    // Deserialize
62    let deserialized: Response = serde_json::from_str(&serialized).expect("Failed to deserialize");
63    assert_eq!(deserialized, response);
64    assert!(deserialized.enabled);
65}