azure_functions/send_grid/
unsubscribe_group.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents an unsubscribe group associated with an email message that specifies how to handle unsubscribes.
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
5pub struct UnsubscribeGroup {
6    /// The unsubscribe group id associated with the email message.
7    pub group_id: i32,
8    /// The list containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page.
9    /// See https://sendgrid.com/docs/User_Guide/Suppressions/recipient_subscription_preferences.html
10    #[serde(skip_serializing_if = "Vec::is_empty")]
11    pub groups_to_display: Vec<i32>,
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17    use serde_json::to_string;
18
19    #[test]
20    fn it_serializes_to_json() {
21        let json = to_string(&UnsubscribeGroup {
22            group_id: 12345,
23            groups_to_display: Vec::new(),
24        })
25        .unwrap();
26
27        assert_eq!(json, r#"{"group_id":12345}"#);
28
29        let json = to_string(&UnsubscribeGroup {
30            group_id: 12345,
31            groups_to_display: vec![1, 2, 3, 4, 5],
32        })
33        .unwrap();
34
35        assert_eq!(
36            json,
37            r#"{"group_id":12345,"groups_to_display":[1,2,3,4,5]}"#
38        );
39    }
40}