app: add catalog commands/queries (RegisterAsset, UpdateMetadata, GetTimeline, GetAsset)
This commit is contained in:
54
crates/application/tests/catalog/queries/get_timeline.rs
Normal file
54
crates/application/tests/catalog/queries/get_timeline.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{GetTimelineQuery, GetTimelineHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
||||
use domain::catalog::entities::{Asset, AssetType, SourceReference};
|
||||
use domain::ports::AssetRepository;
|
||||
use domain::value_objects::{Checksum, SystemId};
|
||||
|
||||
async fn seed_assets(repo: &InMemoryAssetRepository, owner: SystemId, count: usize) {
|
||||
for i in 0..count {
|
||||
let hex = format!("{:0>64x}", i + 1);
|
||||
let source = SourceReference {
|
||||
volume_id: SystemId::new(),
|
||||
relative_path: format!("photos/img{i}.jpg"),
|
||||
checksum: Checksum::new(hex).unwrap(),
|
||||
};
|
||||
let asset = Asset::new(source, AssetType::Image, "image/jpeg", 1024, owner);
|
||||
repo.save(&asset).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_paginated_assets() {
|
||||
let asset_repo = Arc::new(InMemoryAssetRepository::new());
|
||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||
let owner = SystemId::new();
|
||||
|
||||
seed_assets(&asset_repo, owner, 5).await;
|
||||
|
||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||
|
||||
let page = handler.execute(GetTimelineQuery {
|
||||
owner_id: owner,
|
||||
limit: 3,
|
||||
offset: 0,
|
||||
}).await.unwrap();
|
||||
|
||||
assert_eq!(page.len(), 3);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_empty_for_no_assets() {
|
||||
let asset_repo = Arc::new(InMemoryAssetRepository::new());
|
||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||
|
||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||
|
||||
let page = handler.execute(GetTimelineQuery {
|
||||
owner_id: SystemId::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
}).await.unwrap();
|
||||
|
||||
assert!(page.is_empty());
|
||||
}
|
||||
Reference in New Issue
Block a user