use ruma::{
OwnedUserId,
api::{auth_scheme::AccessToken, request, response},
metadata,
};
use serde::{Deserialize, Serialize};
use crate::experimental_features::enable_features::v1::ExperimentalFeatures;
metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
path: "/_synapse/admin/v1/experimental_features/{user_id}",
}
#[request]
#[derive(Serialize, Deserialize, PartialEq)]
pub struct Request {
#[ruma_api(path)]
pub user_id: OwnedUserId,
}
#[response]
#[derive(Serialize, Deserialize, PartialEq)]
pub struct Response {
pub features: ExperimentalFeatures,
}
impl Request {
pub fn new(user_id: OwnedUserId) -> Self {
Self { user_id }
}
}
impl Response {
pub fn new(features: ExperimentalFeatures) -> Self {
Self { features }
}
}
#[test]
fn test_list_features() {
let response = Response {
features: ExperimentalFeatures {
msc3026: Option::from(false),
msc3881: None,
msc3967: None,
},
};
let json_str = "{\"features\":{\"msc3026\":false}}";
let deserialized: Response = serde_json::from_str(json_str).expect("Failed to deserialize");
assert_eq!(deserialized, response);
let serialized = serde_json::to_string(&response).expect("Failed to serialize");
assert_eq!(serialized, json_str);
}