refactor: restructure application to CQRS, update api-types + presentation
- application: replace flat use_cases/ with identity/{commands,queries}/ and organization/commands/
- each use case now split into Command/Query struct + Handler struct
- api-types: add username to RegisterRequest/UserResponse, add CreateAlbumRequest/AlbumResponse
- presentation: update state, handlers, factory to use new handler types
- tests: restructured to match CQRS module layout, added get_profile tests
This commit is contained in:
28
crates/application/tests/identity/queries/get_profile.rs
Normal file
28
crates/application/tests/identity/queries/get_profile.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use application::identity::{RegisterUserCommand, RegisterUserHandler, GetProfileQuery, GetProfileHandler};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
|
||||
#[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 handler = GetProfileHandler::new(repo);
|
||||
let found = handler.execute(GetProfileQuery { user_id: user.id }).await.unwrap();
|
||||
assert_eq!(found.username, "alice");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
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;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
Reference in New Issue
Block a user