pub mod acct_item;
pub mod cost_allocation_plan;
pub mod cost_allocation_report;
pub mod datasource;
pub mod datasource_record;
pub mod models;
pub mod paygroup;
pub mod payment_activity;
pub mod payment_detail;
pub mod v1;
use crate::core::config::Config;
use acct_item::AcctItemService;
use cost_allocation_plan::CostAllocationPlanService;
use cost_allocation_report::CostAllocationReportService;
use datasource::DatasourceService;
use datasource_record::DatasourceRecordService;
use paygroup::PaygroupService;
use payment_activity::PaymentActivityService;
use payment_detail::PaymentDetailService;
pub struct PayrollService {
pub payment_detail: PaymentDetailService,
pub payment_activity: PaymentActivityService,
pub datasource_record: DatasourceRecordService,
pub datasource: DatasourceService,
pub acct_item: AcctItemService,
pub cost_allocation_report: CostAllocationReportService,
pub cost_allocation_plan: CostAllocationPlanService,
pub paygroup: PaygroupService,
}
impl PayrollService {
pub fn new(config: Config) -> Self {
Self {
payment_detail: PaymentDetailService::new(config.clone()),
payment_activity: PaymentActivityService::new(config.clone()),
datasource_record: DatasourceRecordService::new(config.clone()),
datasource: DatasourceService::new(config.clone()),
acct_item: AcctItemService::new(config.clone()),
cost_allocation_report: CostAllocationReportService::new(config.clone()),
cost_allocation_plan: CostAllocationPlanService::new(config.clone()),
paygroup: PaygroupService::new(config),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;
#[test]
fn test_payroll_service_creation() {
let config = Config::default();
let service = PayrollService::new(config.clone());
assert_eq!(service.payment_detail.config.app_id, config.app_id);
assert_eq!(service.payment_detail.config.app_secret, config.app_secret);
assert_eq!(service.payment_activity.config.app_id, config.app_id);
assert_eq!(service.datasource_record.config.app_id, config.app_id);
assert_eq!(service.datasource.config.app_id, config.app_id);
assert_eq!(service.acct_item.config.app_id, config.app_id);
assert_eq!(service.cost_allocation_report.config.app_id, config.app_id);
assert_eq!(service.cost_allocation_plan.config.app_id, config.app_id);
assert_eq!(service.paygroup.config.app_id, config.app_id);
}
#[test]
fn test_payroll_service_with_custom_config() {
let config = Config::builder()
.app_id("payroll_test_app")
.app_secret("payroll_test_secret")
.req_timeout(Duration::from_secs(240))
.build();
let service = PayrollService::new(config.clone());
assert_eq!(service.payment_detail.config.app_id, "payroll_test_app");
assert_eq!(
service.payment_detail.config.app_secret,
"payroll_test_secret"
);
assert_eq!(
service.payment_detail.config.req_timeout,
Some(Duration::from_secs(240))
);
assert_eq!(service.payment_activity.config.app_id, "payroll_test_app");
assert_eq!(
service.datasource.config.req_timeout,
Some(Duration::from_secs(240))
);
assert_eq!(service.acct_item.config.app_secret, "payroll_test_secret");
assert_eq!(
service.cost_allocation_report.config.req_timeout,
Some(Duration::from_secs(240))
);
assert_eq!(service.paygroup.config.app_id, "payroll_test_app");
}
#[test]
fn test_payroll_service_config_independence() {
let config1 = Config::builder().app_id("payroll_app_1").build();
let config2 = Config::builder().app_id("payroll_app_2").build();
let service1 = PayrollService::new(config1);
let service2 = PayrollService::new(config2);
assert_eq!(service1.payment_detail.config.app_id, "payroll_app_1");
assert_eq!(service2.payment_detail.config.app_id, "payroll_app_2");
assert_ne!(
service1.payment_detail.config.app_id,
service2.payment_detail.config.app_id
);
assert_ne!(
service1.datasource.config.app_id,
service2.paygroup.config.app_id
);
}
#[test]
fn test_payroll_service_sub_services_accessible() {
let config = Config::default();
let service = PayrollService::new(config.clone());
assert_eq!(service.payment_detail.config.app_id, config.app_id);
assert_eq!(service.payment_activity.config.app_id, config.app_id);
assert_eq!(service.datasource_record.config.app_id, config.app_id);
assert_eq!(service.datasource.config.app_id, config.app_id);
assert_eq!(service.acct_item.config.app_id, config.app_id);
assert_eq!(service.cost_allocation_report.config.app_id, config.app_id);
assert_eq!(service.cost_allocation_plan.config.app_id, config.app_id);
assert_eq!(service.paygroup.config.app_id, config.app_id);
}
#[test]
fn test_payroll_service_config_cloning() {
let config = Config::builder()
.app_id("clone_test_app")
.app_secret("clone_test_secret")
.build();
let service = PayrollService::new(config.clone());
assert_eq!(service.payment_detail.config.app_id, "clone_test_app");
assert_eq!(
service.payment_detail.config.app_secret,
"clone_test_secret"
);
assert_eq!(
service.payment_activity.config.app_secret,
"clone_test_secret"
);
assert_eq!(service.datasource_record.config.app_id, "clone_test_app");
assert_eq!(service.datasource.config.app_secret, "clone_test_secret");
assert_eq!(service.acct_item.config.app_id, "clone_test_app");
assert_eq!(
service.cost_allocation_plan.config.app_secret,
"clone_test_secret"
);
assert_eq!(service.paygroup.config.app_id, "clone_test_app");
}
#[test]
fn test_payroll_service_timeout_propagation() {
let config = Config::builder()
.req_timeout(Duration::from_secs(220))
.build();
let service = PayrollService::new(config);
assert_eq!(
service.payment_detail.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.payment_activity.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.datasource_record.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.datasource.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.acct_item.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.cost_allocation_report.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.cost_allocation_plan.config.req_timeout,
Some(Duration::from_secs(220))
);
assert_eq!(
service.paygroup.config.req_timeout,
Some(Duration::from_secs(220))
);
}
#[test]
fn test_payroll_service_multiple_instances() {
let config = Config::default();
let service1 = PayrollService::new(config.clone());
let service2 = PayrollService::new(config.clone());
assert_eq!(
service1.payment_detail.config.app_id,
service2.payment_detail.config.app_id
);
assert_eq!(
service1.payment_detail.config.app_secret,
service2.payment_detail.config.app_secret
);
assert_eq!(
service1.payment_activity.config.app_id,
service2.payment_activity.config.app_id
);
assert_eq!(
service1.datasource.config.app_secret,
service2.datasource.config.app_secret
);
assert_eq!(
service1.acct_item.config.app_id,
service2.acct_item.config.app_id
);
assert_eq!(
service1.cost_allocation_report.config.app_secret,
service2.cost_allocation_report.config.app_secret
);
assert_eq!(
service1.paygroup.config.app_id,
service2.paygroup.config.app_id
);
}
#[test]
fn test_payroll_service_config_consistency() {
let config = Config::builder()
.app_id("consistency_test")
.app_secret("consistency_secret")
.req_timeout(Duration::from_secs(190))
.build();
let service = PayrollService::new(config);
assert_eq!(service.payment_detail.config.app_id, "consistency_test");
assert_eq!(
service.payment_detail.config.app_secret,
"consistency_secret"
);
assert_eq!(
service.payment_detail.config.req_timeout,
Some(Duration::from_secs(190))
);
assert_eq!(service.payment_activity.config.app_id, "consistency_test");
assert_eq!(
service.datasource_record.config.app_secret,
"consistency_secret"
);
assert_eq!(
service.datasource.config.req_timeout,
Some(Duration::from_secs(190))
);
assert_eq!(service.acct_item.config.app_id, "consistency_test");
assert_eq!(
service.cost_allocation_plan.config.app_secret,
"consistency_secret"
);
assert_eq!(
service.paygroup.config.req_timeout,
Some(Duration::from_secs(190))
);
}
}