59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
use application::storage::{
|
|
RegisterLibraryPathCommand, RegisterLibraryPathHandler, RegisterVolumeCommand,
|
|
RegisterVolumeHandler,
|
|
};
|
|
use application::testing::{InMemoryLibraryPathRepository, InMemoryStorageVolumeRepository};
|
|
use domain::errors::DomainError;
|
|
use domain::value_objects::SystemId;
|
|
use std::sync::Arc;
|
|
|
|
#[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(_))));
|
|
}
|