Skip to main content

openlark_mail/
service.rs

1use openlark_core::config::Config;
2use std::sync::Arc;
3
4/// MailService:邮件服务的统一入口
5///
6/// 提供对邮件 API v1 的访问能力
7#[derive(Clone)]
8#[allow(dead_code)]
9pub struct MailService {
10    config: Arc<Config>,
11}
12
13impl MailService {
14    /// 创建新的邮件服务实例。
15    pub fn new(config: Config) -> Self {
16        Self {
17            config: Arc::new(config),
18        }
19    }
20
21    #[cfg(feature = "v1")]
22    /// 访问邮件 API。
23    pub fn mail(&self) -> crate::mail::mail::Mail {
24        crate::mail::mail::Mail::new(self.config.clone())
25    }
26
27    #[cfg(feature = "v1")]
28    /// 访问邮件组 API。
29    pub fn mailgroup(&self) -> crate::mail::mail::v1::mailgroup::MailGroup {
30        crate::mail::mail::v1::mailgroup::MailGroup::new(self.config.clone())
31    }
32}
33
34#[cfg(test)]
35#[allow(unused_imports)]
36mod tests {
37
38    #[test]
39    fn test_serialization_roundtrip() {
40        // 基础序列化测试
41        let json = r#"{"test": "value"}"#;
42        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
43    }
44
45    #[test]
46    fn test_deserialization_from_json() {
47        // 基础反序列化测试
48        let json = r#"{"field": "data"}"#;
49        let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
50        assert_eq!(value["field"], "data");
51    }
52}