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:
62
crates/application/tests/wrapup/list_wrapups_test.rs
Normal file
62
crates/application/tests/wrapup/list_wrapups_test.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use chrono::NaiveDate;
|
||||
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
|
||||
use domain::testing::InMemoryWrapUpRepository;
|
||||
use domain::value_objects::WrapUpId;
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::wrapup::deps::ListWrapUpsDeps;
|
||||
use application::wrapup::list_wrapups::{self, ListWrapUpsQuery};
|
||||
|
||||
fn make_record(user_id: Option<Uuid>) -> WrapUpRecord {
|
||||
WrapUpRecord {
|
||||
id: WrapUpId::generate(),
|
||||
user_id,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn filters_by_user() {
|
||||
let repo = InMemoryWrapUpRepository::new();
|
||||
let uid = Uuid::new_v4();
|
||||
{
|
||||
let mut store = repo.store.lock().unwrap();
|
||||
store.push(make_record(Some(uid)));
|
||||
store.push(make_record(Some(Uuid::new_v4())));
|
||||
store.push(make_record(None));
|
||||
}
|
||||
|
||||
let deps = ListWrapUpsDeps {
|
||||
wrapup_repo: repo.clone(),
|
||||
};
|
||||
let result = list_wrapups::execute(&deps, ListWrapUpsQuery { user_id: Some(uid) })
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 1);
|
||||
assert_eq!(result[0].user_id, Some(uid));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_global_when_no_user() {
|
||||
let repo = InMemoryWrapUpRepository::new();
|
||||
{
|
||||
let mut store = repo.store.lock().unwrap();
|
||||
store.push(make_record(None));
|
||||
store.push(make_record(None));
|
||||
store.push(make_record(Some(Uuid::new_v4())));
|
||||
}
|
||||
|
||||
let deps = ListWrapUpsDeps {
|
||||
wrapup_repo: repo.clone(),
|
||||
};
|
||||
let result = list_wrapups::execute(&deps, ListWrapUpsQuery { user_id: None })
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 2);
|
||||
}
|
||||
Reference in New Issue
Block a user