koprogo_api/application/use_cases/
gdpr_art30_use_cases.rs

1use crate::application::ports::gdpr_art30_repository::GdprArt30Repository;
2use crate::domain::entities::gdpr_art30::{ProcessingActivity, ProcessorAgreement};
3use std::sync::Arc;
4
5pub struct GdprArt30UseCases {
6    repository: Arc<dyn GdprArt30Repository>,
7}
8
9impl GdprArt30UseCases {
10    pub fn new(repository: Arc<dyn GdprArt30Repository>) -> Self {
11        Self { repository }
12    }
13
14    pub async fn list_processing_activities(&self) -> Result<Vec<ProcessingActivity>, String> {
15        self.repository.list_processing_activities().await
16    }
17
18    pub async fn list_processor_agreements(&self) -> Result<Vec<ProcessorAgreement>, String> {
19        self.repository.list_processor_agreements().await
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use async_trait::async_trait;
27    use chrono::Utc;
28    use uuid::Uuid;
29
30    struct MockRepo;
31
32    #[async_trait]
33    impl GdprArt30Repository for MockRepo {
34        async fn list_processing_activities(&self) -> Result<Vec<ProcessingActivity>, String> {
35            let now = Utc::now();
36            Ok(vec![ProcessingActivity {
37                id: Uuid::new_v4(),
38                activity_name: "User management".to_string(),
39                controller_name: "KoproGo".to_string(),
40                purpose: "Contract performance".to_string(),
41                legal_basis: "Art. 6(1)(b)".to_string(),
42                data_categories: vec!["contact".to_string()],
43                data_subjects: vec!["owners".to_string()],
44                recipients: vec![],
45                retention_period: "7 years".to_string(),
46                security_measures: "Encryption".to_string(),
47                created_at: now,
48                updated_at: now,
49            }])
50        }
51
52        async fn list_processor_agreements(&self) -> Result<Vec<ProcessorAgreement>, String> {
53            Ok(vec![])
54        }
55    }
56
57    #[tokio::test]
58    async fn test_list_activities_returns_results() {
59        let uc = GdprArt30UseCases::new(Arc::new(MockRepo));
60        let activities = uc.list_processing_activities().await.unwrap();
61        assert_eq!(activities.len(), 1);
62        assert_eq!(activities[0].activity_name, "User management");
63    }
64
65    #[tokio::test]
66    async fn test_list_processors_empty() {
67        let uc = GdprArt30UseCases::new(Arc::new(MockRepo));
68        let processors = uc.list_processor_agreements().await.unwrap();
69        assert!(processors.is_empty());
70    }
71}