notionrs_schema/object/page/
button.rs

1use serde::{Deserialize, Serialize};
2
3/// - `$.['*'].id`: An underlying identifier for the property.
4///   `id` remains constant when the property name changes.
5/// - `$.['*'].type`: Always `"button"`
6/// - `$.['*'].button`: Always an empty object
7///
8/// **Note**: The `['*']` part represents the column name you set when creating the database.
9///
10/// Example button page property value
11///
12/// ```json
13/// {
14///     "Button": {
15///         "id": "c%60qZ",
16///         "type": "button",
17///         "button": {}
18///     }
19/// }
20/// ```
21#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Default, notionrs_macro::Setter)]
22pub struct PageButtonProperty {
23    /// An underlying identifier for the property.
24    /// `id` remains constant when the property name changes.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub id: Option<String>,
27
28    /// Always `"button"`
29    pub button: std::collections::HashMap<String, String>,
30}
31
32impl std::fmt::Display for PageButtonProperty {
33    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
34        write!(f, "")
35    }
36}
37
38// # --------------------------------------------------------------------------------
39//
40// unit test
41//
42// # --------------------------------------------------------------------------------
43
44#[cfg(test)]
45mod unit_tests {
46
47    use super::*;
48    use serde_json;
49
50    #[test]
51    fn deserialize_page_button_property() {
52        let json_data = r#"
53        {
54            "Button": {
55                "id": "c%60qZ",
56                "type": "button",
57                "button": {}
58            }
59        }
60        "#;
61
62        let button_map = serde_json::from_str::<
63            std::collections::HashMap<String, PageButtonProperty>,
64        >(json_data)
65        .unwrap();
66
67        let button = button_map.get("Button").unwrap();
68
69        assert_eq!(button.id, Some("c%60qZ".to_string()));
70        assert!(button.button.is_empty());
71    }
72}