@@ -103,9 +103,6 @@ impl FakeDiaryQuery {
|
||||
.insert(movie.id().value(), (movie, reviews));
|
||||
}
|
||||
|
||||
/// Configures what `query_diary` returns. Without this, `query_diary` keeps
|
||||
/// its original always-empty behavior — this is purely opt-in for tests that
|
||||
/// need to prove entries actually flow through a use case.
|
||||
pub fn set_diary_page(&self, page: Paginated<DiaryEntry>) {
|
||||
*self.diary_page.lock().unwrap() = Some(page);
|
||||
}
|
||||
|
||||
@@ -347,9 +347,6 @@ impl WatchlistRepository for InMemoryWatchlistRepository {
|
||||
|
||||
// ── InMemoryRemoteWatchlistRepository ─────────────────────────────────────────
|
||||
|
||||
/// Unlike `NoopRemoteWatchlistRepository`, this actually stores what it's given —
|
||||
/// needed by tests that must prove a federated-watchlist read returns real seeded
|
||||
/// data, not just an empty default that happens to match by coincidence.
|
||||
pub struct InMemoryRemoteWatchlistRepository {
|
||||
store: Mutex<Vec<RemoteWatchlistEntry>>,
|
||||
}
|
||||
@@ -405,10 +402,6 @@ impl RemoteWatchlistRepository for InMemoryRemoteWatchlistRepository {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Real adapters derive `uuid` from the actor URL via a SQL-side hash — not
|
||||
/// domain logic, so this fake doesn't replicate it. It simply returns
|
||||
/// everything seeded, which is all callers in this workspace need: tests seed
|
||||
/// exactly the entries for the owner under test.
|
||||
async fn get_by_derived_uuid(
|
||||
&self,
|
||||
_uuid: Uuid,
|
||||
|
||||
52
crates/domain/src/testing/insights.rs
Normal file
52
crates/domain/src/testing/insights.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
errors::DomainError, models::insights::WatchRow, ports::InsightsQuery, value_objects::UserId,
|
||||
};
|
||||
|
||||
// ── PanicInsightsQuery ──────────────────────────────────────────────────────
|
||||
|
||||
pub struct PanicInsightsQuery;
|
||||
|
||||
#[async_trait]
|
||||
impl InsightsQuery for PanicInsightsQuery {
|
||||
async fn get_watch_rows(&self, _: &UserId) -> Result<Vec<WatchRow>, DomainError> {
|
||||
panic!("PanicInsightsQuery called")
|
||||
}
|
||||
}
|
||||
|
||||
// ── InMemoryInsightsQuery ───────────────────────────────────────────────────
|
||||
|
||||
pub struct InMemoryInsightsQuery {
|
||||
pub rows_by_user: Mutex<HashMap<uuid::Uuid, Vec<WatchRow>>>,
|
||||
}
|
||||
|
||||
impl InMemoryInsightsQuery {
|
||||
pub fn new() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
rows_by_user: Mutex::new(HashMap::new()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_rows(user_id: uuid::Uuid, rows: Vec<WatchRow>) -> Arc<Self> {
|
||||
let query = Self::new();
|
||||
query.rows_by_user.lock().unwrap().insert(user_id, rows);
|
||||
query
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl InsightsQuery for InMemoryInsightsQuery {
|
||||
async fn get_watch_rows(&self, user_id: &UserId) -> Result<Vec<WatchRow>, DomainError> {
|
||||
Ok(self
|
||||
.rows_by_user
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(&user_id.value())
|
||||
.cloned()
|
||||
.unwrap_or_default())
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
mod fakes;
|
||||
mod in_memory;
|
||||
mod insights;
|
||||
mod noops;
|
||||
mod panics;
|
||||
mod wrapup;
|
||||
|
||||
pub use fakes::*;
|
||||
pub use in_memory::*;
|
||||
pub use insights::*;
|
||||
pub use noops::*;
|
||||
pub use panics::*;
|
||||
pub use wrapup::*;
|
||||
|
||||
Reference in New Issue
Block a user