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(_))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user