use crate::core::config::Config;
pub mod v4;
use v4::V4;
pub struct CalendarService {
pub v4: V4,
}
impl CalendarService {
pub fn new(config: Config) -> Self {
Self {
v4: V4::new(config),
}
}
pub fn new_from_shared(shared: std::sync::Arc<Config>) -> Self {
Self {
v4: V4::new(shared.as_ref().clone()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;
#[test]
fn test_calendar_service_creation() {
let config = Config::default();
let service = CalendarService::new(config.clone());
assert_eq!(service.v4.calendar.config.app_id, config.app_id);
assert_eq!(service.v4.calendar.config.app_secret, config.app_secret);
assert_eq!(service.v4.calendar_acl.config.app_id, config.app_id);
assert_eq!(service.v4.calendar_event.config.app_id, config.app_id);
assert_eq!(service.v4.meeting_chat.config.app_secret, config.app_secret);
assert_eq!(service.v4.meeting_minute.config.app_id, config.app_id);
assert_eq!(service.v4.timeoff_event.config.app_id, config.app_id);
assert_eq!(
service.v4.meeting_room_event.config.app_secret,
config.app_secret
);
assert_eq!(service.v4.attendee.config.app_id, config.app_id);
assert_eq!(service.v4.setting.config.app_id, config.app_id);
assert_eq!(
service.v4.exchange_binding.config.app_secret,
config.app_secret
);
}
#[test]
fn test_calendar_service_with_custom_config() {
let config = Config::builder()
.app_id("calendar_test_app")
.app_secret("calendar_test_secret")
.req_timeout(Duration::from_secs(440))
.build();
let service = CalendarService::new(config.clone());
assert_eq!(service.v4.calendar.config.app_id, "calendar_test_app");
assert_eq!(
service.v4.calendar.config.app_secret,
"calendar_test_secret"
);
assert_eq!(
service.v4.calendar.config.req_timeout,
Some(Duration::from_secs(440))
);
assert_eq!(service.v4.calendar_acl.config.app_id, "calendar_test_app");
assert_eq!(
service.v4.calendar_event.config.req_timeout,
Some(Duration::from_secs(440))
);
assert_eq!(service.v4.meeting_chat.config.app_id, "calendar_test_app");
assert_eq!(
service.v4.meeting_minute.config.req_timeout,
Some(Duration::from_secs(440))
);
assert_eq!(service.v4.timeoff_event.config.app_id, "calendar_test_app");
assert_eq!(
service.v4.meeting_room_event.config.req_timeout,
Some(Duration::from_secs(440))
);
assert_eq!(service.v4.attendee.config.app_id, "calendar_test_app");
assert_eq!(
service.v4.setting.config.req_timeout,
Some(Duration::from_secs(440))
);
assert_eq!(
service.v4.exchange_binding.config.app_id,
"calendar_test_app"
);
}
#[test]
fn test_calendar_service_config_independence() {
let config1 = Config::builder().app_id("calendar_app_1").build();
let config2 = Config::builder().app_id("calendar_app_2").build();
let service1 = CalendarService::new(config1);
let service2 = CalendarService::new(config2);
assert_eq!(service1.v4.calendar.config.app_id, "calendar_app_1");
assert_eq!(service2.v4.calendar.config.app_id, "calendar_app_2");
assert_ne!(
service1.v4.calendar.config.app_id,
service2.v4.calendar.config.app_id
);
assert_ne!(
service1.v4.calendar_acl.config.app_id,
service2.v4.calendar_acl.config.app_id
);
assert_ne!(
service1.v4.calendar_event.config.app_id,
service2.v4.calendar_event.config.app_id
);
assert_ne!(
service1.v4.meeting_chat.config.app_id,
service2.v4.meeting_chat.config.app_id
);
assert_ne!(
service1.v4.meeting_minute.config.app_id,
service2.v4.meeting_minute.config.app_id
);
assert_ne!(
service1.v4.timeoff_event.config.app_id,
service2.v4.timeoff_event.config.app_id
);
assert_ne!(
service1.v4.meeting_room_event.config.app_id,
service2.v4.meeting_room_event.config.app_id
);
assert_ne!(
service1.v4.attendee.config.app_id,
service2.v4.attendee.config.app_id
);
assert_ne!(
service1.v4.setting.config.app_id,
service2.v4.setting.config.app_id
);
assert_ne!(
service1.v4.exchange_binding.config.app_id,
service2.v4.exchange_binding.config.app_id
);
}
#[test]
fn test_calendar_service_sub_services_accessible() {
let config = Config::default();
let service = CalendarService::new(config.clone());
assert_eq!(service.v4.calendar.config.app_id, config.app_id);
assert_eq!(service.v4.calendar_acl.config.app_id, config.app_id);
assert_eq!(service.v4.calendar_event.config.app_id, config.app_id);
assert_eq!(service.v4.meeting_chat.config.app_id, config.app_id);
assert_eq!(service.v4.meeting_minute.config.app_id, config.app_id);
assert_eq!(service.v4.timeoff_event.config.app_id, config.app_id);
assert_eq!(service.v4.meeting_room_event.config.app_id, config.app_id);
assert_eq!(service.v4.attendee.config.app_id, config.app_id);
assert_eq!(service.v4.setting.config.app_id, config.app_id);
assert_eq!(service.v4.exchange_binding.config.app_id, config.app_id);
}
#[test]
fn test_calendar_service_config_cloning() {
let config = Config::builder()
.app_id("clone_test_app")
.app_secret("clone_test_secret")
.build();
let service = CalendarService::new(config.clone());
assert_eq!(service.v4.calendar.config.app_id, "clone_test_app");
assert_eq!(service.v4.calendar.config.app_secret, "clone_test_secret");
assert_eq!(
service.v4.calendar_acl.config.app_secret,
"clone_test_secret"
);
assert_eq!(service.v4.calendar_event.config.app_id, "clone_test_app");
assert_eq!(
service.v4.meeting_chat.config.app_secret,
"clone_test_secret"
);
assert_eq!(service.v4.meeting_minute.config.app_id, "clone_test_app");
assert_eq!(
service.v4.timeoff_event.config.app_secret,
"clone_test_secret"
);
assert_eq!(
service.v4.meeting_room_event.config.app_id,
"clone_test_app"
);
assert_eq!(service.v4.attendee.config.app_secret, "clone_test_secret");
assert_eq!(service.v4.setting.config.app_id, "clone_test_app");
assert_eq!(
service.v4.exchange_binding.config.app_secret,
"clone_test_secret"
);
}
#[test]
fn test_calendar_service_timeout_propagation() {
let config = Config::builder()
.req_timeout(Duration::from_secs(450))
.build();
let service = CalendarService::new(config);
assert_eq!(
service.v4.calendar.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.calendar_acl.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.calendar_event.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.meeting_chat.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.meeting_minute.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.timeoff_event.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.meeting_room_event.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.attendee.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.setting.config.req_timeout,
Some(Duration::from_secs(450))
);
assert_eq!(
service.v4.exchange_binding.config.req_timeout,
Some(Duration::from_secs(450))
);
}
#[test]
fn test_calendar_service_multiple_instances() {
let config = Config::default();
let service1 = CalendarService::new(config.clone());
let service2 = CalendarService::new(config.clone());
assert_eq!(
service1.v4.calendar.config.app_id,
service2.v4.calendar.config.app_id
);
assert_eq!(
service1.v4.calendar.config.app_secret,
service2.v4.calendar.config.app_secret
);
assert_eq!(
service1.v4.calendar_acl.config.app_id,
service2.v4.calendar_acl.config.app_id
);
assert_eq!(
service1.v4.calendar_event.config.app_secret,
service2.v4.calendar_event.config.app_secret
);
assert_eq!(
service1.v4.meeting_chat.config.app_id,
service2.v4.meeting_chat.config.app_id
);
assert_eq!(
service1.v4.meeting_minute.config.app_secret,
service2.v4.meeting_minute.config.app_secret
);
assert_eq!(
service1.v4.timeoff_event.config.app_id,
service2.v4.timeoff_event.config.app_id
);
assert_eq!(
service1.v4.meeting_room_event.config.app_secret,
service2.v4.meeting_room_event.config.app_secret
);
assert_eq!(
service1.v4.attendee.config.app_id,
service2.v4.attendee.config.app_id
);
assert_eq!(
service1.v4.setting.config.app_secret,
service2.v4.setting.config.app_secret
);
assert_eq!(
service1.v4.exchange_binding.config.app_id,
service2.v4.exchange_binding.config.app_id
);
}
#[test]
fn test_calendar_service_config_consistency() {
let config = Config::builder()
.app_id("consistency_test")
.app_secret("consistency_secret")
.req_timeout(Duration::from_secs(460))
.build();
let service = CalendarService::new(config);
let configs = [
&service.v4.calendar.config,
&service.v4.calendar_acl.config,
&service.v4.calendar_event.config,
&service.v4.meeting_chat.config,
&service.v4.meeting_minute.config,
&service.v4.timeoff_event.config,
&service.v4.meeting_room_event.config,
&service.v4.attendee.config,
&service.v4.setting.config,
&service.v4.exchange_binding.config,
];
for config in &configs {
assert_eq!(config.app_id, "consistency_test");
assert_eq!(config.app_secret, "consistency_secret");
assert_eq!(config.req_timeout, Some(Duration::from_secs(460)));
}
}
}