Skip to main content

braze_sync/resource/
content_block.rs

1//! Content Block domain type. See IMPLEMENTATION.md §6.3.
2//!
3//! Liquid template bodies are treated as opaque text in v1.0; syntax
4//! validation is deferred to the server (§7.6).
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct ContentBlock {
10    pub name: String,
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    pub description: Option<String>,
13    /// Liquid template body. Opaque text in v1.0.
14    pub content: String,
15    #[serde(default)]
16    pub tags: Vec<String>,
17    pub state: ContentBlockState,
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22pub enum ContentBlockState {
23    Active,
24    Draft,
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn content_block_yaml_roundtrip() {
33        let cb = ContentBlock {
34            name: "promo".into(),
35            description: Some("Promo banner".into()),
36            content: "{{ user.${first_name} }}".into(),
37            tags: vec!["pr".into()],
38            state: ContentBlockState::Active,
39        };
40        let yaml = serde_yml::to_string(&cb).unwrap();
41        let parsed: ContentBlock = serde_yml::from_str(&yaml).unwrap();
42        assert_eq!(cb, parsed);
43    }
44
45    #[test]
46    fn state_serializes_snake_case() {
47        let s = serde_yml::to_string(&ContentBlockState::Draft).unwrap();
48        assert_eq!(s.trim(), "draft");
49    }
50}