Files
movies-diary/crates/application/tests/users/update_profile_fields_test.rs
Gabriel Kaszewski 8526b77f18 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).
2026-10-25 22:36:52 +01:00

78 lines
2.0 KiB
Rust

use crate::support::TestContextBuilder;
use std::sync::Arc;
use domain::events::DomainEvent;
use domain::models::ProfileField;
use domain::testing::{InMemoryStore, NoopEventPublisher};
use uuid::Uuid;
use application::users::{
commands::UpdateProfileFieldsCommand, deps::UpdateProfileFieldsDeps, update_profile_fields,
};
#[tokio::test]
async fn saves_profile_fields() {
let fields_repo = InMemoryStore::new();
let events = NoopEventPublisher::new();
let b = TestContextBuilder::new()
.with_profile_fields(Arc::clone(&fields_repo) as _)
.with_event_publisher(Arc::clone(&events) as _);
let deps = UpdateProfileFieldsDeps {
profile_fields: b.profile_fields_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
update_profile_fields::execute(
&deps,
UpdateProfileFieldsCommand {
user_id: Uuid::nil(),
fields: vec![
ProfileField {
name: "Website".into(),
value: "https://example.com".into(),
},
ProfileField {
name: "Location".into(),
value: "Berlin".into(),
},
],
},
)
.await
.unwrap();
let published = events.published();
assert!(
published
.iter()
.any(|e| matches!(e, DomainEvent::UserUpdated { .. }))
);
}
#[tokio::test]
async fn rejects_more_than_four_fields() {
let b = TestContextBuilder::new();
let deps = UpdateProfileFieldsDeps {
profile_fields: b.profile_fields_repo.clone(),
event_publisher: b.event_publisher.clone(),
};
let fields: Vec<ProfileField> = (0..5)
.map(|i| ProfileField {
name: format!("field{i}"),
value: format!("val{i}"),
})
.collect();
let result = update_profile_fields::execute(
&deps,
UpdateProfileFieldsCommand {
user_id: Uuid::nil(),
fields,
},
)
.await;
assert!(result.is_err());
}