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

@@ -966,26 +966,6 @@ impl UserRepository for ErroringUserRepo {
}
}
/// Builds a bare `User` with the given role, for the admin/non-admin extractor
/// tests — only `id()` and `role()` are read by `authorize_admin::execute`.
fn make_user_with_role(id: UserId, role: domain::models::UserRole) -> domain::models::User {
domain::models::User::from_persistence(
id,
domain::value_objects::Email::new("extractor-test@example.com".into()).unwrap(),
domain::value_objects::Username::new("extractor_test_user".into()).unwrap(),
domain::value_objects::PasswordHash::new("hashed".into()).unwrap(),
role,
domain::models::UserProfile {
display_name: None,
bio: None,
avatar_path: None,
banner_path: None,
also_known_as: None,
profile_fields: vec![],
},
)
}
/// Auth stub that accepts any bearer token and resolves it to a fixed user id,
/// for tests that need to authenticate as a specific user rather than merely
/// exercise the unauthenticated-request path.
@@ -1154,7 +1134,7 @@ async fn admin_api_user_allows_an_admin_user() {
let user_repo = InMemoryUserRepository::new();
user_repo.store.lock().unwrap().insert(
id.value(),
make_user_with_role(id.clone(), domain::models::UserRole::Admin),
domain::testing::test_user_with_role(id.clone(), domain::models::UserRole::Admin),
);
let app = router_admin_api(test_app_state_with_user(
user_repo as _,
@@ -1179,7 +1159,7 @@ async fn admin_api_user_rejects_a_non_admin_user() {
let user_repo = InMemoryUserRepository::new();
user_repo.store.lock().unwrap().insert(
id.value(),
make_user_with_role(id.clone(), domain::models::UserRole::Standard),
domain::testing::test_user_with_role(id.clone(), domain::models::UserRole::Standard),
);
let app = router_admin_api(test_app_state_with_user(
user_repo as _,
@@ -1245,7 +1225,7 @@ async fn admin_user_allows_an_admin_user() {
let user_repo = InMemoryUserRepository::new();
user_repo.store.lock().unwrap().insert(
id.value(),
make_user_with_role(id.clone(), domain::models::UserRole::Admin),
domain::testing::test_user_with_role(id.clone(), domain::models::UserRole::Admin),
);
let app = router_admin_cookie(test_app_state_with_user(
user_repo as _,
@@ -1270,7 +1250,7 @@ async fn admin_user_rejects_a_non_admin_user() {
let user_repo = InMemoryUserRepository::new();
user_repo.store.lock().unwrap().insert(
id.value(),
make_user_with_role(id.clone(), domain::models::UserRole::Standard),
domain::testing::test_user_with_role(id.clone(), domain::models::UserRole::Standard),
);
let app = router_admin_cookie(test_app_state_with_user(
user_repo as _,