feat: idempotent handlers, deterministic activity ids

This commit is contained in:
2026-10-26 01:27:03 +01:00
parent 7f9c252d35
commit 4cb2972f63
11 changed files with 719 additions and 19 deletions

View File

@@ -136,3 +136,29 @@ pub fn create(config: &::config::StorageConfig) -> anyhow::Result<Arc<dyn Object
StorageConfig::from_config(config)?,
)))
}
#[cfg(test)]
mod tests {
use super::*;
use domain::value_objects::{MovieId, PosterPath};
use object_store::memory::InMemory;
#[tokio::test]
async fn image_cleanup_is_idempotent_when_run_twice() {
let storage = Arc::new(ObjectStorageAdapter::new(Arc::new(InMemory::new())));
storage.store("posters/m1.webp", b"img").await.unwrap();
let handler = ImageCleanupHandler::new(storage.clone());
let event = DomainEvent::MovieDeleted {
movie_id: MovieId::from_uuid(uuid::Uuid::new_v4()),
poster_path: Some(PosterPath::new("posters/m1.webp".into()).unwrap()),
};
handler.handle(&event).await.unwrap();
handler.handle(&event).await.unwrap();
assert!(matches!(
storage.get("posters/m1.webp").await,
Err(DomainError::NotFound(_))
));
}
}