use application::processing::{ReportBatchProgressHandler, ReportBatchProgressQuery}; use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository}; use domain::entities::{Job, JobBatch, JobType}; use domain::errors::DomainError; use domain::ports::{JobBatchRepository, JobRepository}; use domain::value_objects::{StructuredData, SystemId}; use std::sync::Arc; #[tokio::test] async fn returns_progress() { let batch_repo = Arc::new(InMemoryJobBatchRepository::new()); let job_repo = Arc::new(InMemoryJobRepository::new()); let batch = JobBatch::new("import", 3); let batch_id = batch.batch_id; batch_repo.save(&batch).await.unwrap(); let j1 = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id); let j2 = Job::new(JobType::GenerateDerivative, 3, StructuredData::new()).with_batch(batch_id); job_repo.save(&j1).await.unwrap(); job_repo.save(&j2).await.unwrap(); let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone()); let progress = handler .execute(ReportBatchProgressQuery { batch_id }) .await .unwrap(); assert_eq!(progress.batch.batch_id, batch_id); assert_eq!(progress.jobs.len(), 2); } #[tokio::test] async fn rejects_nonexistent_batch() { let batch_repo = Arc::new(InMemoryJobBatchRepository::new()); let job_repo = Arc::new(InMemoryJobRepository::new()); let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone()); let result = handler .execute(ReportBatchProgressQuery { batch_id: SystemId::new(), }) .await; assert!(matches!(result, Err(DomainError::NotFound(_)))); }