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,3 +1,4 @@
use crate::test_support::register_command;
use std::sync::Arc;
use domain::models::UserRole;
@@ -23,10 +24,8 @@ async fn register_user(
register::execute(
&reg_deps,
RegisterCommand {
email: email.into(),
username: username.into(),
password: "password123".into(),
role,
..register_command(email, username)
},
)
.await

View File

@@ -1,3 +1,4 @@
use crate::test_support::register_command;
use std::sync::Arc;
use domain::models::{ProfileField, User, UserProfile, UserRole};
@@ -7,7 +8,7 @@ use domain::value_objects::{Email, PasswordHash, UserId, Username};
use uuid::Uuid;
use crate::{
auth::{commands::RegisterCommand, deps::RegisterDeps, register},
auth::{deps::RegisterDeps, register},
test_helpers::TestContextBuilder,
users::{deps::GetCurrentProfileDeps, get_current_profile, queries::GetCurrentProfileQuery},
};
@@ -23,17 +24,9 @@ async fn returns_profile_for_existing_user() {
config: b.config.clone(),
};
register::execute(
&reg_deps,
RegisterCommand {
email: "alice@example.com".into(),
username: "alice".into(),
password: "password123".into(),
role: UserRole::Standard,
},
)
.await
.unwrap();
register::execute(&reg_deps, register_command("alice@example.com", "alice"))
.await
.unwrap();
let user = users
.find_by_email(&domain::value_objects::Email::new("alice@example.com".into()).unwrap())

View File

@@ -1,8 +1,7 @@
use crate::test_support::{register_command, update_profile_command};
use domain::errors::DomainError;
use domain::models::UserRole;
use domain::value_objects::Email;
use crate::auth::commands::RegisterCommand;
use crate::auth::deps::RegisterDeps;
use crate::auth::register;
use crate::test_helpers::TestContextBuilder;
@@ -18,17 +17,9 @@ async fn setup_user(b: &TestContextBuilder, email: &str, username: &str) {
password_hasher: b.password_hasher.clone(),
config: b.config.clone(),
};
register::execute(
&deps,
RegisterCommand {
email: email.into(),
username: username.into(),
password: "password123".into(),
role: UserRole::Standard,
},
)
.await
.unwrap();
register::execute(&deps, register_command(email, username))
.await
.unwrap();
}
fn deps(b: &TestContextBuilder) -> GetLocalProfileDeps {
@@ -276,14 +267,9 @@ async fn populates_handle_and_actor_url_for_a_local_user() {
update_profile::execute(
&update_deps,
UpdateProfileCommand {
user_id: uid,
display_name: Some("Gabriel K".into()),
bio: Some("Movies and diaries.".into()),
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(uid)
},
)
.await

View File

@@ -1,7 +1,6 @@
use domain::models::UserRole;
use crate::test_support::register_command;
use domain::value_objects::{Email, FollowTarget, SocialIdentity, UserId};
use crate::auth::commands::RegisterCommand;
use crate::auth::deps::RegisterDeps;
use crate::auth::register;
use crate::test_helpers::TestContextBuilder;
@@ -14,17 +13,9 @@ async fn setup_user(b: &TestContextBuilder, email: &str, username: &str) -> uuid
password_hasher: b.password_hasher.clone(),
config: b.config.clone(),
};
register::execute(
&deps,
RegisterCommand {
email: email.into(),
username: username.into(),
password: "password123".into(),
role: UserRole::Standard,
},
)
.await
.unwrap();
register::execute(&deps, register_command(email, username))
.await
.unwrap();
let user = b
.user_repo
.find_by_email(&Email::new(email.into()).unwrap())

View File

@@ -1,7 +1,7 @@
use domain::models::{ProfileField, UserRole};
use crate::test_support::register_command;
use domain::models::ProfileField;
use domain::value_objects::{Email, UserId};
use crate::auth::commands::RegisterCommand;
use crate::auth::deps::RegisterDeps;
use crate::auth::register;
use crate::test_helpers::TestContextBuilder;
@@ -18,12 +18,7 @@ async fn get_profile_settings_includes_profile_fields() {
};
register::execute(
&register_deps,
RegisterCommand {
email: "settings@test.com".into(),
username: "settingsuser".into(),
password: "password123".into(),
role: UserRole::Standard,
},
register_command("settings@test.com", "settingsuser"),
)
.await
.unwrap();

View File

@@ -1,13 +1,13 @@
use crate::test_support::{register_command, update_profile_command};
use std::sync::Arc;
use domain::events::DomainEvent;
use domain::models::UserRole;
use domain::ports::UserRepository;
use domain::testing::{InMemoryUserRepository, NoopEventPublisher};
use uuid::Uuid;
use crate::{
auth::{commands::RegisterCommand, deps::RegisterDeps, register},
auth::{deps::RegisterDeps, register},
test_helpers::TestContextBuilder,
users::{commands::UpdateProfileCommand, deps::UpdateProfileDeps, update_profile},
};
@@ -18,17 +18,9 @@ async fn register_user(b: &TestContextBuilder, users: &Arc<InMemoryUserRepositor
password_hasher: b.password_hasher.clone(),
config: b.config.clone(),
};
register::execute(
&reg_deps,
RegisterCommand {
email: "alice@example.com".into(),
username: "alice".into(),
password: "password123".into(),
role: UserRole::Standard,
},
)
.await
.unwrap();
register::execute(&reg_deps, register_command("alice@example.com", "alice"))
.await
.unwrap();
let user = users
.find_by_email(&domain::value_objects::Email::new("alice@example.com".into()).unwrap())
@@ -55,14 +47,8 @@ async fn updates_display_name() {
update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: Some("Alice W.".into()),
bio: None,
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(uid)
},
)
.await
@@ -90,14 +76,9 @@ async fn rejects_invalid_avatar_content_type() {
let result = update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: None,
bio: None,
avatar_bytes: Some(vec![0u8; 10]),
avatar_content_type: Some("image/gif".into()),
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(uid)
},
)
.await;
@@ -122,14 +103,9 @@ async fn uploads_avatar() {
update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: None,
bio: None,
avatar_bytes: Some(vec![0xFFu8, 0xD8, 0xFF]),
avatar_content_type: Some("image/jpeg".into()),
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(uid)
},
)
.await
@@ -165,14 +141,9 @@ async fn uploads_banner() {
update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: None,
bio: None,
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: Some(vec![0x89, 0x50, 0x4E]),
banner_content_type: Some("image/png".into()),
also_known_as: None,
..update_profile_command(uid)
},
)
.await
@@ -203,14 +174,8 @@ async fn fails_for_nonexistent_user() {
let result = update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: Uuid::new_v4(),
display_name: Some("Ghost".into()),
bio: None,
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(Uuid::new_v4())
},
)
.await;
@@ -232,14 +197,9 @@ async fn rejects_invalid_banner_content_type() {
let result = update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: None,
bio: None,
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: Some(vec![0u8; 10]),
banner_content_type: Some("text/plain".into()),
also_known_as: None,
..update_profile_command(uid)
},
)
.await;
@@ -264,14 +224,9 @@ async fn text_only_update_emits_user_updated_no_image_stored() {
update_profile::execute(
&deps,
UpdateProfileCommand {
user_id: uid,
display_name: Some("Alice Updated".into()),
bio: Some("Hello world".into()),
avatar_bytes: None,
avatar_content_type: None,
banner_bytes: None,
banner_content_type: None,
also_known_as: None,
..update_profile_command(uid)
},
)
.await

View File

@@ -1,3 +1,4 @@
use crate::test_support::update_user_settings_command;
use std::sync::Arc;
use domain::testing::InMemoryUserSettingsRepository;
@@ -24,10 +25,8 @@ async fn updates_federate_goals() {
user_settings: user_settings.clone(),
},
UpdateUserSettingsCommand {
user_id: uid,
federate_goals: false,
federate_reviews: true,
federate_watchlist: true,
..update_user_settings_command(uid)
},
)
.await
@@ -53,10 +52,8 @@ async fn updates_federate_reviews() {
user_settings: user_settings.clone(),
},
UpdateUserSettingsCommand {
user_id: uid,
federate_goals: true,
federate_reviews: false,
federate_watchlist: true,
..update_user_settings_command(uid)
},
)
.await
@@ -82,10 +79,8 @@ async fn updates_federate_watchlist() {
user_settings: user_settings.clone(),
},
UpdateUserSettingsCommand {
user_id: uid,
federate_goals: true,
federate_reviews: true,
federate_watchlist: false,
..update_user_settings_command(uid)
},
)
.await