feat: atomic goal, watchlist, profile writes

This commit is contained in:
2026-10-26 00:49:28 +01:00
parent c8a1e8bfe4
commit 62ad9f4017
48 changed files with 1296 additions and 264 deletions

View File

@@ -3,8 +3,9 @@ use domain::testing::test_movie_with_year;
use std::sync::Arc;
use domain::{
events::DomainEvent,
ports::MovieCommand,
testing::{InMemoryStore, NoopEventPublisher},
testing::{InMemoryStore, NoopEventPublisher, RefusingWatchlistRepository},
};
use application::watchlist::{add, commands::AddToWatchlistCommand, deps::WatchlistAddDeps};
@@ -108,3 +109,50 @@ async fn adding_the_same_movie_to_a_watchlist_twice_keeps_a_single_entry_and_suc
assert_eq!(movies.watchlist_count(), 1);
}
#[tokio::test]
async fn adding_an_entry_records_the_entry_and_its_event_together() {
let movies = InMemoryStore::new();
let movie = test_movie_with_year("Heat", 1995);
movies.upsert_movie(&movie).await.unwrap();
let deps = make_deps(Arc::clone(&movies), Arc::clone(&movies));
add::execute(
&deps,
add_to_watchlist_command(uuid::Uuid::new_v4(), movie.id().value()),
)
.await
.unwrap();
assert_eq!(movies.watchlist_count(), 1);
let recorded = movies.recorded_events();
assert_eq!(recorded.len(), 1);
assert!(matches!(
recorded[0],
DomainEvent::WatchlistEntryAdded { .. }
));
}
#[tokio::test]
async fn a_refused_add_propagates_and_records_nothing() {
let movies = InMemoryStore::new();
let movie = test_movie_with_year("Heat", 1995);
movies.upsert_movie(&movie).await.unwrap();
let deps = WatchlistAddDeps {
watchlist: Arc::new(RefusingWatchlistRepository),
..make_deps(Arc::clone(&movies), Arc::clone(&movies))
};
let result = add::execute(
&deps,
add_to_watchlist_command(uuid::Uuid::new_v4(), movie.id().value()),
)
.await;
assert!(matches!(
result,
Err(domain::errors::DomainError::InfrastructureError(m)) if m == "refused"
));
assert_eq!(movies.watchlist_count(), 0);
assert!(movies.recorded_events().is_empty());
}