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