refactor: fix HIGH+MEDIUM architectural violations from code review
HIGH: fix watch_medium data-loss bug, standardize error handling on ApiError, fix dep direction (rss/template-askama no longer dep on application), extract ImageFetcher port (remove reqwest from app layer), move event construction from save_review to use case, extract infra-wiring crate (DbPool/EventBusBackend dedup), deduplicate presentation helpers (encode_error, export streaming, multipart parsing) MEDIUM: split LocalApContentQuery god-trait 10→3 methods, dedup movie resolution orchestration, add RemoteActorDto/PersonDto mappers, move AppConfig to infra-wiring, fix SocialQueryPort Uuid→UserId, replace stringly-typed api-types with domain enums, move count_reviews_in_year to StatsRepository, dedup event publisher cfg blocks, extract should_enrich, move group_by_month to application, dedup count_local_posts, add FederationFlags Default, TUI input helper + ShowError rename + typed auth errors, api-types cleanup (UserSettingsDto/UserProfileBase/PreviewRowData) 102 files changed, -681 lines net
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::events::DomainEvent;
|
||||
use domain::testing::{InMemoryGoalRepository, NoopEventPublisher};
|
||||
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::goals::{commands::CreateGoalCommand, create};
|
||||
@@ -10,10 +10,12 @@ use crate::test_helpers::TestContextBuilder;
|
||||
#[tokio::test]
|
||||
async fn creates_goal_and_returns_progress() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
let stats = FakeStatsRepository::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
let result = create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -33,11 +35,13 @@ async fn creates_goal_and_returns_progress() {
|
||||
#[tokio::test]
|
||||
async fn creates_goal_with_review_count() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
goals.set_review_count(Uuid::nil(), 2025, 5);
|
||||
let stats = FakeStatsRepository::new();
|
||||
stats.set_review_count(Uuid::nil(), 2025, 5);
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
let result = create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -59,6 +63,7 @@ async fn emits_goal_created_event() {
|
||||
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -86,12 +91,18 @@ async fn rejects_duplicate_year() {
|
||||
target_count: 10,
|
||||
};
|
||||
|
||||
create::execute(b.goal_repo.clone(), b.event_publisher.clone(), cmd)
|
||||
.await
|
||||
.unwrap();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
cmd,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -109,6 +120,7 @@ async fn rejects_year_before_2020() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -126,6 +138,7 @@ async fn rejects_zero_target() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::testing::{InMemoryGoalRepository, NoopEventPublisher};
|
||||
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::goals::{
|
||||
@@ -12,10 +12,12 @@ use crate::test_helpers::TestContextBuilder;
|
||||
#[tokio::test]
|
||||
async fn deletes_existing_goal() {
|
||||
let goals = InMemoryGoalRepository::new();
|
||||
let stats = FakeStatsRepository::new();
|
||||
let events = NoopEventPublisher::new();
|
||||
|
||||
create::execute(
|
||||
Arc::clone(&goals) as _,
|
||||
Arc::clone(&stats) as _,
|
||||
Arc::clone(&events) as _,
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
@@ -8,6 +8,7 @@ async fn returns_goal_when_exists() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -20,6 +21,7 @@ async fn returns_goal_when_exists() {
|
||||
|
||||
let result = get::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
GetGoalQuery {
|
||||
user_id: Uuid::nil(),
|
||||
year: 2025,
|
||||
@@ -37,6 +39,7 @@ async fn returns_none_when_missing() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = get::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
GetGoalQuery {
|
||||
user_id: Uuid::nil(),
|
||||
year: 2025,
|
||||
|
||||
@@ -8,6 +8,7 @@ async fn returns_empty_when_no_goals() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = list::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
ListGoalsQuery {
|
||||
user_id: Uuid::nil(),
|
||||
},
|
||||
@@ -24,6 +25,7 @@ async fn returns_all_goals_for_user() {
|
||||
for year in [2023, 2024, 2025] {
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -37,6 +39,7 @@ async fn returns_all_goals_for_user() {
|
||||
|
||||
let result = list::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
ListGoalsQuery {
|
||||
user_id: Uuid::nil(),
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ async fn updates_target_count() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -23,6 +24,7 @@ async fn updates_target_count() {
|
||||
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -41,6 +43,7 @@ async fn fails_when_goal_not_found() {
|
||||
let b = TestContextBuilder::new();
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -58,6 +61,7 @@ async fn rejects_zero_target() {
|
||||
let b = TestContextBuilder::new();
|
||||
create::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
CreateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
@@ -70,6 +74,7 @@ async fn rejects_zero_target() {
|
||||
|
||||
let result = update::execute(
|
||||
b.goal_repo.clone(),
|
||||
b.stats_repo.clone(),
|
||||
b.event_publisher.clone(),
|
||||
UpdateGoalCommand {
|
||||
user_id: Uuid::nil(),
|
||||
|
||||
Reference in New Issue
Block a user