use crate::Config;
use std::time::Duration;
pub trait LarkClient: Send + Sync {
fn config(&self) -> &Config;
fn is_configured(&self) -> bool {
!self.config().app_id.is_empty() && !self.config().app_secret.is_empty()
}
fn app_id(&self) -> &str {
&self.config().app_id
}
fn app_secret(&self) -> &str {
&self.config().app_secret
}
fn base_url(&self) -> &str {
&self.config().base_url
}
fn timeout(&self) -> Duration {
self.config().timeout
}
fn retry_count(&self) -> u32 {
self.config().retry_count
}
fn is_log_enabled(&self) -> bool {
self.config().enable_log
}
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use super::*;
use std::time::Duration;
struct TestClient {
config: Config,
}
impl LarkClient for TestClient {
fn config(&self) -> &Config {
&self.config
}
}
#[test]
fn test_lark_client_basic_methods() {
let config = Config {
app_id: "test_app_id".to_string(),
app_secret: "test_app_secret".to_string(),
app_type: openlark_core::constants::AppType::SelfBuild,
enable_token_cache: true,
base_url: "https://test.feishu.cn".to_string(),
timeout: Duration::from_secs(30),
retry_count: 3,
enable_log: true,
headers: std::collections::HashMap::new(),
core_config: None,
};
let client = TestClient { config };
assert_eq!(client.app_id(), "test_app_id");
assert_eq!(client.app_secret(), "test_app_secret");
assert_eq!(client.base_url(), "https://test.feishu.cn");
assert_eq!(client.timeout(), Duration::from_secs(30));
assert_eq!(client.retry_count(), 3);
assert!(client.is_log_enabled());
assert!(client.is_configured());
}
#[test]
fn test_not_configured_client() {
let config = Config {
app_id: String::new(),
app_secret: String::new(),
..Default::default()
};
let client = TestClient { config };
assert!(!client.is_configured());
}
}