Files
k-photos/crates/application/tests/identity/queries/get_profile.rs
Gabriel Kaszewski fa36bb8c0e 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
2026-05-31 05:00:34 +02:00

29 lines
1.1 KiB
Rust

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(_))));
}