test: shared factories and command builders

This commit is contained in:
2026-10-25 22:08:17 +01:00
parent 2ac1d4e0cf
commit 51d92e08a7
58 changed files with 784 additions and 1344 deletions

View File

@@ -1,11 +1,12 @@
use crate::test_support::create_goal_command;
use std::sync::Arc;
use domain::events::DomainEvent;
use domain::testing::{FakeStatsRepository, InMemoryGoalRepository, NoopEventPublisher};
use uuid::Uuid;
use crate::goals::create;
use crate::goals::deps::GoalCommandDeps;
use crate::goals::{commands::CreateGoalCommand, create};
use crate::test_helpers::TestContextBuilder;
#[tokio::test]
@@ -20,16 +21,9 @@ async fn creates_goal_and_returns_progress() {
event_publisher: Arc::clone(&events) as _,
};
let result = create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 50,
},
)
.await
.unwrap();
let result = create::execute(&deps, create_goal_command(2025, 50))
.await
.unwrap();
assert_eq!(result.goal.year(), 2025);
assert_eq!(result.goal.target_count(), 50);
@@ -50,16 +44,9 @@ async fn creates_goal_with_review_count() {
event_publisher: Arc::clone(&events) as _,
};
let result = create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 50,
},
)
.await
.unwrap();
let result = create::execute(&deps, create_goal_command(2025, 50))
.await
.unwrap();
assert_eq!(result.current_count, 5);
assert_eq!(goals.count(), 1);
@@ -76,16 +63,9 @@ async fn emits_goal_created_event() {
event_publisher: Arc::clone(&events) as _,
};
create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 10,
},
)
.await
.unwrap();
create::execute(&deps, create_goal_command(2025, 10))
.await
.unwrap();
let published = events.published();
assert!(
@@ -104,23 +84,11 @@ async fn rejects_duplicate_year() {
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let cmd = CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 10,
};
let cmd = create_goal_command(2025, 10);
create::execute(&deps, cmd).await.unwrap();
let result = create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 20,
},
)
.await;
let result = create::execute(&deps, create_goal_command(2025, 20)).await;
assert!(result.is_err());
}
@@ -134,15 +102,7 @@ async fn rejects_year_before_2020() {
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2019,
target_count: 10,
},
)
.await;
let result = create::execute(&deps, create_goal_command(2019, 10)).await;
assert!(result.is_err());
}
@@ -156,15 +116,7 @@ async fn rejects_zero_target() {
stats: b.stats_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let result = create::execute(
&deps,
CreateGoalCommand {
user_id: Uuid::nil(),
year: 2025,
target_count: 0,
},
)
.await;
let result = create::execute(&deps, create_goal_command(2025, 0)).await;
assert!(result.is_err());
}