use std::sync::{Arc, Mutex}; use async_trait::async_trait; use crate::{ errors::DomainError, events::{AckHandle, DomainEvent}, models::{Person, PersonEnrichmentData, PersonId}, ports::{EventPublisher, ObjectStorage, PersonCommand}, value_objects::UserId, }; // ── NoopEventPublisher ──────────────────────────────────────────────────────── pub struct NoopEventPublisher { pub events: Mutex>, } impl NoopEventPublisher { pub fn new() -> Arc { Arc::new(Self { events: Mutex::new(vec![]), }) } pub fn published(&self) -> Vec { self.events.lock().unwrap().clone() } } #[async_trait] impl EventPublisher for NoopEventPublisher { async fn publish(&self, event: &DomainEvent) -> Result<(), DomainError> { self.events.lock().unwrap().push(event.clone()); Ok(()) } } // ── NoopObjectStorage ────────────────────────────────────────────────────────── pub struct NoopObjectStorage; #[async_trait] impl ObjectStorage for NoopObjectStorage { async fn store(&self, key: &str, _image_bytes: &[u8]) -> Result { Ok(format!("noop://{key}")) } async fn get(&self, _key: &str) -> Result, DomainError> { Ok(vec![]) } async fn get_stream( &self, _key: &str, ) -> Result>, DomainError> { Ok(Box::pin(futures::stream::empty())) } async fn delete(&self, _key: &str) -> Result<(), DomainError> { Ok(()) } async fn exists(&self, _key: &str) -> Result { Ok(true) } } // Re-export production noop types so test code that imports from // `domain::testing` keeps compiling without changes. pub use crate::ports::noop::NoopFederationAdminQuery; pub use crate::ports::noop::NoopRemoteWatchlistRepository; // ── NoopGoalCommand ─────────────────────────────────────────────────────────── pub struct NoopGoalCommand; #[async_trait] impl crate::ports::GoalCommand for NoopGoalCommand { async fn save(&self, _: &crate::models::Goal, _: &[DomainEvent]) -> Result<(), DomainError> { Ok(()) } async fn update(&self, _: &crate::models::Goal, _: &[DomainEvent]) -> Result<(), DomainError> { Ok(()) } async fn delete( &self, _: &crate::value_objects::GoalId, _: &UserId, _: &[DomainEvent], ) -> Result<(), DomainError> { Ok(()) } } // ── NoopGoalQuery ───────────────────────────────────────────────────────────── pub struct NoopGoalQuery; #[async_trait] impl crate::ports::GoalQuery for NoopGoalQuery { async fn find_by_user_and_year( &self, _: &UserId, _: u16, ) -> Result, DomainError> { Ok(None) } async fn list_for_user(&self, _: &UserId) -> Result, DomainError> { Ok(vec![]) } } // ── NoopUserSettingsRepository ──────────────────────────────────────────────── pub struct NoopUserSettingsRepository; #[async_trait] impl crate::ports::UserSettingsRepository for NoopUserSettingsRepository { async fn get(&self, user_id: &UserId) -> Result { Ok(crate::models::UserSettings::new(user_id.clone())) } async fn save(&self, _: &crate::models::UserSettings) -> Result<(), DomainError> { Ok(()) } } // ── NoopRemoteGoalRepository ────────────────────────────────────────────────── pub struct NoopRemoteGoalRepository; #[async_trait] impl crate::ports::RemoteGoalRepository for NoopRemoteGoalRepository { async fn save(&self, _: crate::models::RemoteGoalEntry) -> Result<(), DomainError> { Ok(()) } async fn update_by_ap_id(&self, _: &str, _: u32, _: u32) -> Result<(), DomainError> { Ok(()) } async fn remove_by_ap_id(&self, _: &str, _: &str) -> Result<(), DomainError> { Ok(()) } async fn remove_all_by_actor(&self, _: &str) -> Result<(), DomainError> { Ok(()) } async fn get_by_actor_url( &self, _: &str, ) -> Result, DomainError> { Ok(vec![]) } } // ── NoopAckHandle ───────────────────────────────────────────────────────────── pub struct NoopAckHandle; #[async_trait] impl AckHandle for NoopAckHandle { async fn ack(&self) -> Result<(), DomainError> { Ok(()) } async fn nack(&self) -> Result<(), DomainError> { Ok(()) } async fn defer(&self, _: std::time::Duration) -> Result<(), DomainError> { Ok(()) } } // ── NoopPersonCommand ───────────────────────────────────────────────────────── pub struct NoopPersonCommand; #[async_trait] impl PersonCommand for NoopPersonCommand { async fn upsert_batch(&self, _: &[Person]) -> Result<(), DomainError> { Ok(()) } async fn backfill_from_credits_batch(&self, _: u32) -> Result<(u64, bool), DomainError> { Ok((0, false)) } async fn update_enrichment( &self, _: &PersonId, _: &PersonEnrichmentData, ) -> Result<(), DomainError> { Ok(()) } }