style: cargo fmt --all
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use application::identity::{RegisterUserCommand, RegisterUserHandler};
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use domain::errors::DomainError;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn registers_new_user() {
|
||||
@@ -22,16 +22,21 @@ async fn registers_new_user() {
|
||||
async fn rejects_duplicate_email() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||
handler.execute(RegisterUserCommand {
|
||||
username: "user1".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "user2".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "different1".into(),
|
||||
}).await;
|
||||
handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user1".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user2".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "different1".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||
}
|
||||
|
||||
@@ -39,16 +44,21 @@ async fn rejects_duplicate_email() {
|
||||
async fn rejects_duplicate_username() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||
handler.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "a@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "b@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await;
|
||||
handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "a@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "b@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||
}
|
||||
|
||||
@@ -56,11 +66,13 @@ async fn rejects_duplicate_username() {
|
||||
async fn rejects_short_password() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "user".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "short".into(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "short".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -68,10 +80,12 @@ async fn rejects_short_password() {
|
||||
async fn rejects_empty_username() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
use std::sync::Arc;
|
||||
use application::identity::{
|
||||
GetProfileHandler, GetProfileQuery, RegisterUserCommand, RegisterUserHandler,
|
||||
};
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use application::identity::{RegisterUserCommand, RegisterUserHandler, GetProfileQuery, GetProfileHandler};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_existing_user() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let reg = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||
let user = reg.execute(RegisterUserCommand {
|
||||
username: "alice".into(),
|
||||
email: "alice@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await.unwrap();
|
||||
let user = reg
|
||||
.execute(RegisterUserCommand {
|
||||
username: "alice".into(),
|
||||
email: "alice@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let handler = GetProfileHandler::new(repo);
|
||||
let found = handler.execute(GetProfileQuery { user_id: user.id }).await.unwrap();
|
||||
let found = handler
|
||||
.execute(GetProfileQuery { user_id: user.id })
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(found.username, "alice");
|
||||
}
|
||||
|
||||
@@ -23,6 +31,10 @@ async fn returns_existing_user() {
|
||||
async fn returns_not_found_for_missing_user() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = GetProfileHandler::new(repo);
|
||||
let result = handler.execute(GetProfileQuery { user_id: SystemId::new() }).await;
|
||||
let result = handler
|
||||
.execute(GetProfileQuery {
|
||||
user_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user