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, Default, PartialEq, Eq, Serialize, Deserialize)]
21#[serde(rename_all = "snake_case")]
22pub enum ContentBlockState {
23    #[default]
24    Active,
25    Draft,
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn content_block_yaml_roundtrip() {
34        let cb = ContentBlock {
35            name: "promo".into(),
36            description: Some("Promo banner".into()),
37            content: "{{ user.${first_name} }}".into(),
38            tags: vec!["pr".into()],
39            state: ContentBlockState::Active,
40        };
41        let yaml = serde_norway::to_string(&cb).unwrap();
42        let parsed: ContentBlock = serde_norway::from_str(&yaml).unwrap();
43        assert_eq!(cb, parsed);
44    }
45
46    #[test]
47    fn state_serializes_snake_case() {
48        let s = serde_norway::to_string(&ContentBlockState::Draft).unwrap();
49        assert_eq!(s.trim(), "draft");
50    }
51}