Files
k-photos/crates/application/tests/storage/commands/register_library_path.rs

48 lines
1.8 KiB
Rust

use std::sync::Arc;
use application::testing::{InMemoryStorageVolumeRepository, InMemoryLibraryPathRepository};
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler};
use domain::errors::DomainError;
use domain::value_objects::SystemId;
#[tokio::test]
async fn creates_path() {
let vol_repo = Arc::new(InMemoryStorageVolumeRepository::new());
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
let vol_handler = RegisterVolumeHandler::new(vol_repo.clone());
let vol = vol_handler.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await.unwrap();
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
let owner = SystemId::new();
let path = handler.execute(RegisterLibraryPathCommand {
volume_id: vol.volume_id,
relative_path: "photos/inbox".into(),
owner_id: owner,
is_ingest_destination: true,
}).await.unwrap();
assert_eq!(path.volume_id, vol.volume_id);
assert_eq!(path.relative_path, "photos/inbox");
assert!(path.is_ingest_destination);
assert_eq!(path.designated_owner_id, Some(owner));
}
#[tokio::test]
async fn rejects_nonexistent_volume() {
let vol_repo = Arc::new(InMemoryStorageVolumeRepository::new());
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
let result = handler.execute(RegisterLibraryPathCommand {
volume_id: SystemId::new(),
relative_path: "photos/inbox".into(),
owner_id: SystemId::new(),
is_ingest_destination: true,
}).await;
assert!(matches!(result, Err(DomainError::NotFound(_))));
}