app: add catalog commands/queries (RegisterAsset, UpdateMetadata, GetTimeline, GetAsset)
This commit is contained in:
58
crates/application/tests/catalog/queries/get_asset.rs
Normal file
58
crates/application/tests/catalog/queries/get_asset.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{GetAssetQuery, GetAssetHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
||||
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{AssetRepository, AssetMetadataRepository};
|
||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_asset_with_resolved_metadata() {
|
||||
let asset_repo = Arc::new(InMemoryAssetRepository::new());
|
||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||
|
||||
let source = SourceReference {
|
||||
volume_id: SystemId::new(),
|
||||
relative_path: "photos/img.jpg".into(),
|
||||
checksum: Checksum::new("a".repeat(64)).unwrap(),
|
||||
};
|
||||
let asset = Asset::new(source, AssetType::Image, "image/jpeg", 1024, SystemId::new());
|
||||
asset_repo.save(&asset).await.unwrap();
|
||||
|
||||
// Add exif layer
|
||||
let mut exif_data = StructuredData::new();
|
||||
exif_data.insert("camera", MetadataValue::String("Nikon".into()));
|
||||
exif_data.insert("title", MetadataValue::String("EXIF title".into()));
|
||||
let exif = AssetMetadata::new(asset.asset_id, MetadataSource::ExifExtracted, exif_data);
|
||||
meta_repo.save(&exif).await.unwrap();
|
||||
|
||||
// Add user layer (overrides title)
|
||||
let mut user_data = StructuredData::new();
|
||||
user_data.insert("title", MetadataValue::String("My Photo".into()));
|
||||
let user_meta = AssetMetadata::new(asset.asset_id, MetadataSource::UserEdited, user_data);
|
||||
meta_repo.save(&user_meta).await.unwrap();
|
||||
|
||||
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
||||
let (returned, resolved) = handler.execute(GetAssetQuery {
|
||||
asset_id: asset.asset_id,
|
||||
}).await.unwrap();
|
||||
|
||||
assert_eq!(returned.asset_id, asset.asset_id);
|
||||
// UserEdited overrides ExifExtracted
|
||||
assert_eq!(resolved.get_string("title"), Some("My Photo"));
|
||||
// ExifExtracted field preserved
|
||||
assert_eq!(resolved.get_string("camera"), Some("Nikon"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejects_nonexistent() {
|
||||
let asset_repo = Arc::new(InMemoryAssetRepository::new());
|
||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||
|
||||
let handler = GetAssetHandler::new(asset_repo, meta_repo);
|
||||
let result = handler.execute(GetAssetQuery {
|
||||
asset_id: SystemId::new(),
|
||||
}).await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
Reference in New Issue
Block a user