Files
movies-diary/crates/application/tests/watchlist/remove_test.rs
Gabriel Kaszewski 8526b77f18 test: move application tests to tests/
test_support/test_helpers -> tests/support; watched_at unified w/ domain test_watched_at (2024-03-15).
Kept inline: users::diary_filter tests (feed_sort_to_direction_all_variants, paged_user_filter_builds_correctly) - pub(super) helpers in private module.
Dropped stale never-compiled users/tests/get_users.rs (old execute signature).
2026-10-25 22:36:52 +01:00

70 lines
1.7 KiB
Rust

use std::sync::Arc;
use domain::events::DomainEvent;
use domain::models::WatchlistEntry;
use domain::ports::WatchlistRepository;
use domain::testing::{InMemoryStore, NoopEventPublisher};
use domain::value_objects::{MovieId, UserId};
use uuid::Uuid;
use crate::support::TestContextBuilder;
use application::watchlist::{
commands::RemoveFromWatchlistCommand, deps::RemoveFromWatchlistDeps, remove,
};
#[tokio::test]
async fn removes_entry_and_emits_event() {
let watchlist = InMemoryStore::new();
let events = NoopEventPublisher::new();
let uid = Uuid::new_v4();
let mid = Uuid::new_v4();
watchlist
.add(&WatchlistEntry::new(
UserId::from_uuid(uid),
MovieId::from_uuid(mid),
))
.await
.unwrap();
let deps = RemoveFromWatchlistDeps {
watchlist: Arc::clone(&watchlist) as _,
event_publisher: Arc::clone(&events) as _,
};
remove::execute(
&deps,
RemoveFromWatchlistCommand {
user_id: uid,
movie_id: mid,
},
)
.await
.unwrap();
assert_eq!(watchlist.watchlist_count(), 0);
let published = events.published();
assert!(
published
.iter()
.any(|e| matches!(e, DomainEvent::WatchlistEntryRemoved { .. }))
);
}
#[tokio::test]
async fn fails_when_not_on_watchlist() {
let b = TestContextBuilder::new();
let deps = RemoveFromWatchlistDeps {
watchlist: b.watchlist_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = remove::execute(
&deps,
RemoveFromWatchlistCommand {
user_id: Uuid::new_v4(),
movie_id: Uuid::new_v4(),
},
)
.await;
assert!(result.is_err());
}