test: cascading in-memory store
This commit is contained in:
@@ -4,15 +4,12 @@ use std::sync::Arc;
|
||||
|
||||
use domain::{
|
||||
ports::MovieCommand,
|
||||
testing::{InMemoryMovieRepository, InMemoryWatchlistRepository, NoopEventPublisher},
|
||||
testing::{InMemoryStore, NoopEventPublisher},
|
||||
};
|
||||
|
||||
use crate::watchlist::{add, commands::AddToWatchlistCommand, deps::WatchlistAddDeps};
|
||||
|
||||
fn make_deps(
|
||||
movies: Arc<InMemoryMovieRepository>,
|
||||
watchlist: Arc<InMemoryWatchlistRepository>,
|
||||
) -> WatchlistAddDeps {
|
||||
fn make_deps(movies: Arc<InMemoryStore>, watchlist: Arc<InMemoryStore>) -> WatchlistAddDeps {
|
||||
WatchlistAddDeps {
|
||||
movie_command: Arc::clone(&movies) as _,
|
||||
movie_query: movies,
|
||||
@@ -24,8 +21,8 @@ fn make_deps(
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_to_watchlist_resolves_and_saves() {
|
||||
let movies = InMemoryMovieRepository::new();
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let movies = InMemoryStore::new();
|
||||
let watchlist = Arc::clone(&movies);
|
||||
|
||||
let movie = test_movie_with_year("The Thing", 1982);
|
||||
let movie_uuid = movie.id().value();
|
||||
@@ -37,13 +34,13 @@ async fn test_add_to_watchlist_resolves_and_saves() {
|
||||
|
||||
add::execute(&deps, cmd).await.unwrap();
|
||||
|
||||
assert_eq!(watchlist.count(), 1);
|
||||
assert_eq!(watchlist.watchlist_count(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_to_watchlist_already_present_is_idempotent() {
|
||||
let movies = InMemoryMovieRepository::new();
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let movies = InMemoryStore::new();
|
||||
let watchlist = Arc::clone(&movies);
|
||||
|
||||
let movie = test_movie_with_year("RoboCop", 1987);
|
||||
let movie_uuid = movie.id().value();
|
||||
@@ -57,13 +54,17 @@ async fn test_add_to_watchlist_already_present_is_idempotent() {
|
||||
add::execute(&deps, make_cmd()).await.unwrap();
|
||||
add::execute(&deps, make_cmd()).await.unwrap();
|
||||
|
||||
assert_eq!(watchlist.count(), 1, "idempotent add should not duplicate");
|
||||
assert_eq!(
|
||||
watchlist.watchlist_count(),
|
||||
1,
|
||||
"idempotent add should not duplicate"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_to_watchlist_with_manual_movie() {
|
||||
let movies = InMemoryMovieRepository::new();
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let movies = InMemoryStore::new();
|
||||
let watchlist = Arc::clone(&movies);
|
||||
|
||||
let deps = make_deps(Arc::clone(&movies), Arc::clone(&watchlist));
|
||||
|
||||
@@ -74,14 +75,14 @@ async fn test_add_to_watchlist_with_manual_movie() {
|
||||
|
||||
add::execute(&deps, cmd).await.unwrap();
|
||||
|
||||
assert_eq!(watchlist.count(), 1);
|
||||
assert_eq!(movies.count(), 1);
|
||||
assert_eq!(watchlist.watchlist_count(), 1);
|
||||
assert_eq!(movies.movie_count(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_to_watchlist_movie_not_found_by_id() {
|
||||
let movies = InMemoryMovieRepository::new();
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let movies = InMemoryStore::new();
|
||||
let watchlist = Arc::clone(&movies);
|
||||
|
||||
let deps = make_deps(Arc::clone(&movies), Arc::clone(&watchlist));
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use domain::testing::{
|
||||
InMemoryRemoteWatchlistRepository, InMemoryUserRepository, InMemoryWatchlistRepository,
|
||||
PanicRemoteWatchlistRepository, PanicWatchlistRepository,
|
||||
};
|
||||
use domain::testing::{InMemoryStore, PanicRemoteWatchlistRepository, PanicWatchlistRepository};
|
||||
use domain::value_objects::Email;
|
||||
|
||||
use crate::auth::deps::RegisterDeps;
|
||||
@@ -37,7 +34,7 @@ async fn watchlist_for_owner_returns_local_when_user_row_exists() {
|
||||
|
||||
let deps = GetWatchlistForOwnerDeps {
|
||||
user: b.user_repo.clone(),
|
||||
watchlist: InMemoryWatchlistRepository::new(),
|
||||
watchlist: InMemoryStore::new(),
|
||||
remote_watchlist: Arc::new(PanicRemoteWatchlistRepository),
|
||||
};
|
||||
|
||||
@@ -52,20 +49,18 @@ async fn watchlist_for_owner_returns_local_when_user_row_exists() {
|
||||
async fn watchlist_for_owner_returns_remote_when_no_local_row() {
|
||||
let owner_id = Uuid::new_v4();
|
||||
|
||||
let remote = InMemoryRemoteWatchlistRepository::with_entries(vec![
|
||||
domain::models::RemoteWatchlistEntry {
|
||||
ap_id: "https://remote.example/ap/1".into(),
|
||||
actor_url: "https://remote.example/users/owner".into(),
|
||||
movie_title: "Remote Movie".into(),
|
||||
release_year: 2021,
|
||||
external_metadata_id: None,
|
||||
poster_url: None,
|
||||
added_at: chrono::Utc::now(),
|
||||
},
|
||||
]);
|
||||
let remote = InMemoryStore::with_remote_watchlist(vec![domain::models::RemoteWatchlistEntry {
|
||||
ap_id: "https://remote.example/ap/1".into(),
|
||||
actor_url: "https://remote.example/users/owner".into(),
|
||||
movie_title: "Remote Movie".into(),
|
||||
release_year: 2021,
|
||||
external_metadata_id: None,
|
||||
poster_url: None,
|
||||
added_at: chrono::Utc::now(),
|
||||
}]);
|
||||
|
||||
let deps = GetWatchlistForOwnerDeps {
|
||||
user: InMemoryUserRepository::new(),
|
||||
user: InMemoryStore::new(),
|
||||
watchlist: Arc::new(PanicWatchlistRepository),
|
||||
remote_watchlist: remote,
|
||||
};
|
||||
@@ -94,7 +89,7 @@ async fn watchlist_for_owner_local_arm_validates_limit() {
|
||||
|
||||
let deps = GetWatchlistForOwnerDeps {
|
||||
user: b.user_repo.clone(),
|
||||
watchlist: InMemoryWatchlistRepository::new(),
|
||||
watchlist: InMemoryStore::new(),
|
||||
remote_watchlist: Arc::new(PanicRemoteWatchlistRepository),
|
||||
};
|
||||
|
||||
@@ -111,10 +106,10 @@ async fn watchlist_for_owner_local_arm_validates_limit() {
|
||||
#[tokio::test]
|
||||
async fn watchlist_for_owner_remote_arm_ignores_invalid_limit() {
|
||||
let owner_id = Uuid::new_v4();
|
||||
let remote = InMemoryRemoteWatchlistRepository::new();
|
||||
let remote = InMemoryStore::new();
|
||||
|
||||
let deps = GetWatchlistForOwnerDeps {
|
||||
user: InMemoryUserRepository::new(),
|
||||
user: InMemoryStore::new(),
|
||||
watchlist: Arc::new(PanicWatchlistRepository),
|
||||
remote_watchlist: remote,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use domain::models::WatchlistEntry;
|
||||
use domain::ports::WatchlistRepository;
|
||||
use domain::testing::InMemoryWatchlistRepository;
|
||||
use domain::testing::InMemoryStore;
|
||||
use domain::value_objects::{MovieId, UserId};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::watchlist::{deps::IsOnWatchlistDeps, is_on, queries::IsOnWatchlistQue
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_true_when_present() {
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let watchlist = InMemoryStore::new();
|
||||
let uid = Uuid::new_v4();
|
||||
let mid = Uuid::new_v4();
|
||||
watchlist
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use domain::events::DomainEvent;
|
||||
use domain::models::WatchlistEntry;
|
||||
use domain::ports::WatchlistRepository;
|
||||
use domain::testing::{InMemoryWatchlistRepository, NoopEventPublisher};
|
||||
use domain::testing::{InMemoryStore, NoopEventPublisher};
|
||||
use domain::value_objects::{MovieId, UserId};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::watchlist::{
|
||||
|
||||
#[tokio::test]
|
||||
async fn removes_entry_and_emits_event() {
|
||||
let watchlist = InMemoryWatchlistRepository::new();
|
||||
let watchlist = InMemoryStore::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
let uid = Uuid::new_v4();
|
||||
let mid = Uuid::new_v4();
|
||||
@@ -40,7 +40,7 @@ async fn removes_entry_and_emits_event() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(watchlist.count(), 0);
|
||||
assert_eq!(watchlist.watchlist_count(), 0);
|
||||
let published = events.published();
|
||||
assert!(
|
||||
published
|
||||
|
||||
Reference in New Issue
Block a user