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).
This commit is contained in:
2026-10-25 22:36:52 +01:00
parent a2c713c1fa
commit 8526b77f18
175 changed files with 541 additions and 695 deletions

View File

@@ -0,0 +1,110 @@
use crate::support::request_wrap_up_command;
use chrono::NaiveDate;
use domain::events::DomainEvent;
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
use domain::testing::{InMemoryWrapUpRepository, NoopEventPublisher};
use domain::value_objects::WrapUpId;
use uuid::Uuid;
use std::sync::Arc;
use application::wrapup::deps::GenerateWrapUpDeps;
use application::wrapup::{commands::RequestWrapUpCommand, generate};
fn deps(
repo: &Arc<InMemoryWrapUpRepository>,
events: &Arc<NoopEventPublisher>,
) -> GenerateWrapUpDeps {
GenerateWrapUpDeps {
wrapup_repo: Arc::clone(repo) as _,
event_publisher: Arc::clone(events) as _,
}
}
fn past_cmd() -> RequestWrapUpCommand {
request_wrap_up_command(Some(Uuid::nil()), 2024)
}
#[tokio::test]
async fn creates_pending_record_and_emits_event() {
let repo = InMemoryWrapUpRepository::new();
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
let stored = repo.store.lock().unwrap();
assert_eq!(stored.len(), 1);
assert_eq!(stored[0].id, id);
assert_eq!(stored[0].status, WrapUpStatus::Pending);
let published = events.published();
assert!(
published
.iter()
.any(|e| matches!(e, DomainEvent::WrapUpRequested { .. }))
);
}
#[tokio::test]
async fn reuses_existing_ready_wrapup() {
let repo = InMemoryWrapUpRepository::new();
let existing_id = WrapUpId::generate();
repo.store.lock().unwrap().push(WrapUpRecord {
id: existing_id.clone(),
user_id: Some(Uuid::nil()),
start_date: NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
end_date: NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
status: WrapUpStatus::Ready,
report: None,
error_message: None,
created_at: chrono::Utc::now().naive_utc(),
completed_at: None,
});
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
assert_eq!(id, existing_id);
assert_eq!(repo.store.lock().unwrap().len(), 1);
}
#[tokio::test]
async fn replaces_failed_wrapup() {
let repo = InMemoryWrapUpRepository::new();
repo.store.lock().unwrap().push(WrapUpRecord {
id: WrapUpId::generate(),
user_id: Some(Uuid::nil()),
start_date: NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
end_date: NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
status: WrapUpStatus::Failed,
report: None,
error_message: Some("boom".into()),
created_at: chrono::Utc::now().naive_utc(),
completed_at: None,
});
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
let stored = repo.store.lock().unwrap();
assert_eq!(stored.len(), 1);
assert_eq!(stored[0].id, id);
assert_eq!(stored[0].status, WrapUpStatus::Pending);
}
#[tokio::test]
async fn rejects_future_end_date() {
let repo = InMemoryWrapUpRepository::new();
let events = NoopEventPublisher::new();
let err = generate::execute(&deps(&repo, &events), request_wrap_up_command(None, 2030))
.await
.unwrap_err();
assert!(err.to_string().contains("future"));
}