feat: atomic goal, watchlist, profile writes
This commit is contained in:
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
use domain::events::DomainEvent;
|
||||
use domain::models::ProfileField;
|
||||
use domain::testing::{InMemoryStore, NoopEventPublisher};
|
||||
use domain::testing::{InMemoryStore, RefusingProfileFieldsRepository};
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::users::{
|
||||
@@ -11,15 +11,10 @@ use application::users::{
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn saves_profile_fields() {
|
||||
async fn saving_profile_fields_records_the_change_and_its_event_together() {
|
||||
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(),
|
||||
profile_fields: Arc::clone(&fields_repo) as _,
|
||||
};
|
||||
|
||||
update_profile_fields::execute(
|
||||
@@ -41,12 +36,9 @@ async fn saves_profile_fields() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let published = events.published();
|
||||
assert!(
|
||||
published
|
||||
.iter()
|
||||
.any(|e| matches!(e, DomainEvent::UserUpdated { .. }))
|
||||
);
|
||||
let recorded = fields_repo.recorded_events();
|
||||
assert_eq!(recorded.len(), 1);
|
||||
assert!(matches!(recorded[0], DomainEvent::UserUpdated { .. }));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -54,7 +46,6 @@ 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)
|
||||
@@ -75,3 +66,24 @@ async fn rejects_more_than_four_fields() {
|
||||
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn refused_profile_fields_propagate_and_record_nothing() {
|
||||
let deps = UpdateProfileFieldsDeps {
|
||||
profile_fields: Arc::new(RefusingProfileFieldsRepository),
|
||||
};
|
||||
|
||||
let result = update_profile_fields::execute(
|
||||
&deps,
|
||||
UpdateProfileFieldsCommand {
|
||||
user_id: Uuid::nil(),
|
||||
fields: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(domain::errors::DomainError::InfrastructureError(m)) if m == "refused"
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user