style: cargo fmt --all
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
mod catalog;
|
||||
mod identity;
|
||||
mod organization;
|
||||
mod storage;
|
||||
mod catalog;
|
||||
mod processing;
|
||||
mod sharing;
|
||||
mod sidecar;
|
||||
mod processing;
|
||||
mod storage;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{RegisterAssetCommand, RegisterAssetHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryDuplicateRepository, StubEventPublisher};
|
||||
use application::testing::{
|
||||
InMemoryAssetRepository, InMemoryDuplicateRepository, StubEventPublisher,
|
||||
};
|
||||
use domain::catalog::entities::AssetType;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn valid_checksum() -> String {
|
||||
"a".repeat(64)
|
||||
@@ -14,24 +16,23 @@ async fn registers_asset() {
|
||||
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
||||
let events = Arc::new(StubEventPublisher::new());
|
||||
|
||||
let handler = RegisterAssetHandler::new(
|
||||
asset_repo.clone(),
|
||||
dup_repo.clone(),
|
||||
events.clone(),
|
||||
);
|
||||
let handler = RegisterAssetHandler::new(asset_repo.clone(), dup_repo.clone(), events.clone());
|
||||
|
||||
let owner = SystemId::new();
|
||||
let volume = SystemId::new();
|
||||
|
||||
let (asset, dup) = handler.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
}).await.unwrap();
|
||||
let (asset, dup) = handler
|
||||
.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(asset.mime_type, "image/jpeg");
|
||||
assert_eq!(asset.file_size, 1024);
|
||||
@@ -46,37 +47,39 @@ async fn flags_duplicate_when_checksum_exists() {
|
||||
let dup_repo = Arc::new(InMemoryDuplicateRepository::new());
|
||||
let events = Arc::new(StubEventPublisher::new());
|
||||
|
||||
let handler = RegisterAssetHandler::new(
|
||||
asset_repo.clone(),
|
||||
dup_repo.clone(),
|
||||
events.clone(),
|
||||
);
|
||||
let handler = RegisterAssetHandler::new(asset_repo.clone(), dup_repo.clone(), events.clone());
|
||||
|
||||
let owner = SystemId::new();
|
||||
let volume = SystemId::new();
|
||||
let checksum = valid_checksum();
|
||||
|
||||
// First asset
|
||||
let (first, _) = handler.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img1.jpg".into(),
|
||||
checksum: checksum.clone(),
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
}).await.unwrap();
|
||||
let (first, _) = handler
|
||||
.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img1.jpg".into(),
|
||||
checksum: checksum.clone(),
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Second asset with same checksum
|
||||
let (second, dup) = handler.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img2.jpg".into(),
|
||||
checksum,
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
}).await.unwrap();
|
||||
let (second, dup) = handler
|
||||
.execute(RegisterAssetCommand {
|
||||
volume_id: volume,
|
||||
relative_path: "photos/img2.jpg".into(),
|
||||
checksum,
|
||||
asset_type: AssetType::Image,
|
||||
mime_type: "image/jpeg".into(),
|
||||
file_size: 1024,
|
||||
owner_id: owner,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let group = dup.expect("should flag duplicate");
|
||||
let candidate_ids: Vec<_> = group.candidates.iter().map(|c| c.asset_id).collect();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{UpdateMetadataCommand, UpdateMetadataHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository, StubEventPublisher};
|
||||
use domain::catalog::entities::{Asset, AssetType, SourceReference, MetadataSource};
|
||||
use application::testing::{
|
||||
InMemoryAssetMetadataRepository, InMemoryAssetRepository, StubEventPublisher,
|
||||
};
|
||||
use domain::catalog::entities::{Asset, AssetType, MetadataSource, SourceReference};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn seed_asset(repo: &InMemoryAssetRepository) -> Asset {
|
||||
let source = SourceReference {
|
||||
@@ -11,7 +13,13 @@ async fn seed_asset(repo: &InMemoryAssetRepository) -> Asset {
|
||||
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());
|
||||
let asset = Asset::new(
|
||||
source,
|
||||
AssetType::Image,
|
||||
"image/jpeg",
|
||||
1024,
|
||||
SystemId::new(),
|
||||
);
|
||||
repo.save(&asset).await.unwrap();
|
||||
asset
|
||||
}
|
||||
@@ -26,20 +34,19 @@ async fn updates_metadata() {
|
||||
|
||||
let asset = seed_asset(&asset_repo).await;
|
||||
|
||||
let handler = UpdateMetadataHandler::new(
|
||||
asset_repo.clone(),
|
||||
meta_repo.clone(),
|
||||
events.clone(),
|
||||
);
|
||||
let handler = UpdateMetadataHandler::new(asset_repo.clone(), meta_repo.clone(), events.clone());
|
||||
|
||||
let mut data = StructuredData::new();
|
||||
data.insert("title", MetadataValue::String("Sunset".into()));
|
||||
|
||||
let result = handler.execute(UpdateMetadataCommand {
|
||||
asset_id: asset.asset_id,
|
||||
user_id: SystemId::new(),
|
||||
data,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(UpdateMetadataCommand {
|
||||
asset_id: asset.asset_id,
|
||||
user_id: SystemId::new(),
|
||||
data,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.metadata_source, MetadataSource::UserEdited);
|
||||
assert_eq!(result.data.get_string("title"), Some("Sunset"));
|
||||
@@ -54,11 +61,13 @@ async fn rejects_nonexistent_asset() {
|
||||
|
||||
let handler = UpdateMetadataHandler::new(asset_repo, meta_repo, events);
|
||||
|
||||
let result = handler.execute(UpdateMetadataCommand {
|
||||
asset_id: SystemId::new(),
|
||||
user_id: SystemId::new(),
|
||||
data: StructuredData::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(UpdateMetadataCommand {
|
||||
asset_id: SystemId::new(),
|
||||
user_id: SystemId::new(),
|
||||
data: StructuredData::new(),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{GetAssetQuery, GetAssetHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
||||
use application::catalog::{GetAssetHandler, GetAssetQuery};
|
||||
use application::testing::{InMemoryAssetMetadataRepository, InMemoryAssetRepository};
|
||||
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{AssetRepository, AssetMetadataRepository};
|
||||
use domain::ports::{AssetMetadataRepository, AssetRepository};
|
||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_asset_with_resolved_metadata() {
|
||||
@@ -16,7 +16,13 @@ async fn returns_asset_with_resolved_metadata() {
|
||||
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());
|
||||
let asset = Asset::new(
|
||||
source,
|
||||
AssetType::Image,
|
||||
"image/jpeg",
|
||||
1024,
|
||||
SystemId::new(),
|
||||
);
|
||||
asset_repo.save(&asset).await.unwrap();
|
||||
|
||||
// Add exif layer
|
||||
@@ -33,9 +39,12 @@ async fn returns_asset_with_resolved_metadata() {
|
||||
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();
|
||||
let (returned, resolved) = handler
|
||||
.execute(GetAssetQuery {
|
||||
asset_id: asset.asset_id,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(returned.asset_id, asset.asset_id);
|
||||
// UserEdited overrides ExifExtracted
|
||||
@@ -50,9 +59,11 @@ async fn rejects_nonexistent() {
|
||||
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;
|
||||
let result = handler
|
||||
.execute(GetAssetQuery {
|
||||
asset_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
use application::catalog::{GetTimelineQuery, GetTimelineHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryAssetMetadataRepository};
|
||||
use application::catalog::{GetTimelineHandler, GetTimelineQuery};
|
||||
use application::testing::{InMemoryAssetMetadataRepository, InMemoryAssetRepository};
|
||||
use domain::catalog::entities::{Asset, AssetType, SourceReference};
|
||||
use domain::ports::AssetRepository;
|
||||
use domain::value_objects::{Checksum, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn seed_assets(repo: &InMemoryAssetRepository, owner: SystemId, count: usize) {
|
||||
for i in 0..count {
|
||||
@@ -28,11 +28,14 @@ async fn returns_paginated_assets() {
|
||||
|
||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||
|
||||
let page = handler.execute(GetTimelineQuery {
|
||||
owner_id: owner,
|
||||
limit: 3,
|
||||
offset: 0,
|
||||
}).await.unwrap();
|
||||
let page = handler
|
||||
.execute(GetTimelineQuery {
|
||||
owner_id: owner,
|
||||
limit: 3,
|
||||
offset: 0,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(page.len(), 3);
|
||||
}
|
||||
@@ -44,11 +47,14 @@ async fn returns_empty_for_no_assets() {
|
||||
|
||||
let handler = GetTimelineHandler::new(asset_repo, meta_repo);
|
||||
|
||||
let page = handler.execute(GetTimelineQuery {
|
||||
owner_id: SystemId::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
}).await.unwrap();
|
||||
let page = handler
|
||||
.execute(GetTimelineQuery {
|
||||
owner_id: SystemId::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(page.is_empty());
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
mod get_timeline;
|
||||
mod get_asset;
|
||||
mod get_timeline;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use application::identity::{RegisterUserCommand, RegisterUserHandler};
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use domain::errors::DomainError;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn registers_new_user() {
|
||||
@@ -22,16 +22,21 @@ async fn registers_new_user() {
|
||||
async fn rejects_duplicate_email() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||
handler.execute(RegisterUserCommand {
|
||||
username: "user1".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "user2".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "different1".into(),
|
||||
}).await;
|
||||
handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user1".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user2".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "different1".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||
}
|
||||
|
||||
@@ -39,16 +44,21 @@ async fn rejects_duplicate_email() {
|
||||
async fn rejects_duplicate_username() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo.clone(), Arc::new(StubPasswordHasher));
|
||||
handler.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "a@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "b@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await;
|
||||
handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "a@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "sameuser".into(),
|
||||
email: "b@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||
}
|
||||
|
||||
@@ -56,11 +66,13 @@ async fn rejects_duplicate_username() {
|
||||
async fn rejects_short_password() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "user".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "short".into(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "user".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "short".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -68,10 +80,12 @@ async fn rejects_short_password() {
|
||||
async fn rejects_empty_username() {
|
||||
let repo = Arc::new(InMemoryUserRepository::new());
|
||||
let handler = RegisterUserHandler::new(repo, Arc::new(StubPasswordHasher));
|
||||
let result = handler.execute(RegisterUserCommand {
|
||||
username: "".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RegisterUserCommand {
|
||||
username: "".into(),
|
||||
email: "test@example.com".into(),
|
||||
password: "password123".into(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
use std::sync::Arc;
|
||||
use application::identity::{
|
||||
GetProfileHandler, GetProfileQuery, RegisterUserCommand, RegisterUserHandler,
|
||||
};
|
||||
use application::testing::{InMemoryUserRepository, StubPasswordHasher};
|
||||
use application::identity::{RegisterUserCommand, RegisterUserHandler, GetProfileQuery, GetProfileHandler};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[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 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();
|
||||
let found = handler
|
||||
.execute(GetProfileQuery { user_id: user.id })
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(found.username, "alice");
|
||||
}
|
||||
|
||||
@@ -23,6 +31,10 @@ async fn returns_existing_user() {
|
||||
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;
|
||||
let result = handler
|
||||
.execute(GetProfileQuery {
|
||||
user_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use application::organization::{CreateAlbumCommand, CreateAlbumHandler};
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_album() {
|
||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||
let handler = CreateAlbumHandler::new(repo);
|
||||
let creator = SystemId::new();
|
||||
let album = handler.execute(CreateAlbumCommand {
|
||||
title: "Vacation 2024".into(),
|
||||
creator_id: creator,
|
||||
}).await.unwrap();
|
||||
let album = handler
|
||||
.execute(CreateAlbumCommand {
|
||||
title: "Vacation 2024".into(),
|
||||
creator_id: creator,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(album.title, "Vacation 2024");
|
||||
assert_eq!(album.creator_user_id, creator);
|
||||
assert_eq!(album.asset_count(), 0);
|
||||
@@ -22,9 +25,11 @@ async fn creates_album() {
|
||||
async fn rejects_empty_title() {
|
||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||
let handler = CreateAlbumHandler::new(repo);
|
||||
let result = handler.execute(CreateAlbumCommand {
|
||||
title: "".into(),
|
||||
creator_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(CreateAlbumCommand {
|
||||
title: "".into(),
|
||||
creator_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use application::organization::{
|
||||
AlbumAction, CreateAlbumCommand, CreateAlbumHandler,
|
||||
ManageAlbumEntriesCommand, ManageAlbumEntriesHandler,
|
||||
AlbumAction, CreateAlbumCommand, CreateAlbumHandler, ManageAlbumEntriesCommand,
|
||||
ManageAlbumEntriesHandler,
|
||||
};
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn setup_album(repo: &Arc<InMemoryAlbumRepository>, creator: SystemId) -> SystemId {
|
||||
let handler = CreateAlbumHandler::new(repo.clone());
|
||||
let album = handler.execute(CreateAlbumCommand {
|
||||
title: "Test Album".into(),
|
||||
creator_id: creator,
|
||||
}).await.unwrap();
|
||||
let album = handler
|
||||
.execute(CreateAlbumCommand {
|
||||
title: "Test Album".into(),
|
||||
creator_id: creator,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
album.album_id
|
||||
}
|
||||
|
||||
@@ -24,11 +27,14 @@ async fn adds_asset_to_album() {
|
||||
let asset_id = SystemId::new();
|
||||
|
||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||
let album = handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
let album = handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(album.asset_count(), 1);
|
||||
assert_eq!(album.entries[0].asset_id, asset_id);
|
||||
@@ -42,17 +48,23 @@ async fn removes_asset_from_album() {
|
||||
let asset_id = SystemId::new();
|
||||
|
||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||
handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let album = handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Remove { asset_id },
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
let album = handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Remove { asset_id },
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(album.asset_count(), 0);
|
||||
}
|
||||
@@ -61,11 +73,15 @@ async fn removes_asset_from_album() {
|
||||
async fn rejects_nonexistent_album() {
|
||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||
let handler = ManageAlbumEntriesHandler::new(repo);
|
||||
let result = handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id: SystemId::new(),
|
||||
action: AlbumAction::Add { asset_id: SystemId::new() },
|
||||
user_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id: SystemId::new(),
|
||||
action: AlbumAction::Add {
|
||||
asset_id: SystemId::new(),
|
||||
},
|
||||
user_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -77,16 +93,21 @@ async fn rejects_duplicate_add() {
|
||||
let asset_id = SystemId::new();
|
||||
|
||||
let handler = ManageAlbumEntriesHandler::new(repo.clone());
|
||||
handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = handler.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ManageAlbumEntriesCommand {
|
||||
album_id,
|
||||
action: AlbumAction::Add { asset_id },
|
||||
user_id: user,
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict(_))));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryTagRepository};
|
||||
use application::organization::{TagAssetCommand, TagAssetHandler};
|
||||
use application::testing::{InMemoryAssetRepository, InMemoryTagRepository};
|
||||
use domain::entities::{Asset, AssetType, SourceReference};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{AssetRepository, TagRepository};
|
||||
use domain::value_objects::{Checksum, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn seed_asset(repo: &Arc<InMemoryAssetRepository>) -> SystemId {
|
||||
let owner = SystemId::new();
|
||||
@@ -32,11 +32,14 @@ async fn tags_asset_creates_new_tag() {
|
||||
let user = SystemId::new();
|
||||
|
||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||
let (tag, asset_tag) = handler.execute(TagAssetCommand {
|
||||
asset_id,
|
||||
tag_name: "sunset".into(),
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
let (tag, asset_tag) = handler
|
||||
.execute(TagAssetCommand {
|
||||
asset_id,
|
||||
tag_name: "sunset".into(),
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tag.name, "sunset");
|
||||
assert_eq!(asset_tag.asset_id, asset_id);
|
||||
@@ -57,11 +60,14 @@ async fn reuses_existing_tag() {
|
||||
tag_repo.save_tag(&existing).await.unwrap();
|
||||
|
||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||
let (tag, _) = handler.execute(TagAssetCommand {
|
||||
asset_id,
|
||||
tag_name: "sunset".into(),
|
||||
user_id: user,
|
||||
}).await.unwrap();
|
||||
let (tag, _) = handler
|
||||
.execute(TagAssetCommand {
|
||||
asset_id,
|
||||
tag_name: "sunset".into(),
|
||||
user_id: user,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tag.tag_id, existing_id);
|
||||
}
|
||||
@@ -72,10 +78,12 @@ async fn rejects_nonexistent_asset() {
|
||||
let tag_repo = Arc::new(InMemoryTagRepository::new());
|
||||
|
||||
let handler = TagAssetHandler::new(asset_repo, tag_repo);
|
||||
let result = handler.execute(TagAssetCommand {
|
||||
asset_id: SystemId::new(),
|
||||
tag_name: "sunset".into(),
|
||||
user_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(TagAssetCommand {
|
||||
asset_id: SystemId::new(),
|
||||
tag_name: "sunset".into(),
|
||||
user_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use application::organization::{
|
||||
CreateAlbumCommand, CreateAlbumHandler,
|
||||
GetAlbumQuery, GetAlbumHandler,
|
||||
CreateAlbumCommand, CreateAlbumHandler, GetAlbumHandler, GetAlbumQuery,
|
||||
};
|
||||
use application::testing::InMemoryAlbumRepository;
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_album() {
|
||||
@@ -13,15 +12,21 @@ async fn returns_album() {
|
||||
let creator = SystemId::new();
|
||||
|
||||
let create_handler = CreateAlbumHandler::new(repo.clone());
|
||||
let album = create_handler.execute(CreateAlbumCommand {
|
||||
title: "My Album".into(),
|
||||
creator_id: creator,
|
||||
}).await.unwrap();
|
||||
let album = create_handler
|
||||
.execute(CreateAlbumCommand {
|
||||
title: "My Album".into(),
|
||||
creator_id: creator,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let query_handler = GetAlbumHandler::new(repo);
|
||||
let found = query_handler.execute(GetAlbumQuery {
|
||||
album_id: album.album_id,
|
||||
}).await.unwrap();
|
||||
let found = query_handler
|
||||
.execute(GetAlbumQuery {
|
||||
album_id: album.album_id,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(found.album_id, album.album_id);
|
||||
assert_eq!(found.title, "My Album");
|
||||
@@ -31,8 +36,10 @@ async fn returns_album() {
|
||||
async fn rejects_nonexistent() {
|
||||
let repo = Arc::new(InMemoryAlbumRepository::new());
|
||||
let handler = GetAlbumHandler::new(repo);
|
||||
let result = handler.execute(GetAlbumQuery {
|
||||
album_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(GetAlbumQuery {
|
||||
album_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{CompleteJobCommand, CompleteJobHandler};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn completes_job() {
|
||||
@@ -18,10 +18,13 @@ async fn completes_job() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Completed);
|
||||
assert!(result.result_data.is_some());
|
||||
@@ -37,17 +40,19 @@ async fn completes_job_and_updates_batch() {
|
||||
let batch_id = batch.batch_id;
|
||||
batch_repo.save(&batch).await.unwrap();
|
||||
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
||||
.with_batch(batch_id);
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||
job.start().unwrap();
|
||||
let job_id = job.job_id;
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||
assert_eq!(updated_batch.completed_count, 1);
|
||||
@@ -65,10 +70,13 @@ async fn publishes_event() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = CompleteJobHandler::new(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(CompleteJobCommand {
|
||||
job_id,
|
||||
result: StructuredData::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
use application::processing::{
|
||||
ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig,
|
||||
};
|
||||
use application::testing::{InMemoryPipelineRepository, InMemoryPluginRepository};
|
||||
use application::processing::{ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig};
|
||||
use domain::entities::{Plugin, PluginType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::PluginRepository;
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_pipeline() {
|
||||
@@ -19,13 +21,22 @@ async fn creates_pipeline() {
|
||||
plugin_repo.save(&p2).await.unwrap();
|
||||
|
||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||
let pipeline = handler.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig { plugin_id: p1_id, config: StructuredData::new() },
|
||||
PipelineStepConfig { plugin_id: p2_id, config: StructuredData::new() },
|
||||
],
|
||||
}).await.unwrap();
|
||||
let pipeline = handler
|
||||
.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig {
|
||||
plugin_id: p1_id,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
PipelineStepConfig {
|
||||
plugin_id: p2_id,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pipeline.trigger_event, "asset.ingested");
|
||||
assert_eq!(pipeline.steps.len(), 2);
|
||||
@@ -37,12 +48,15 @@ async fn rejects_nonexistent_plugin() {
|
||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||
|
||||
let handler = ConfigurePipelineHandler::new(pipeline_repo.clone(), plugin_repo.clone());
|
||||
let result = handler.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![
|
||||
PipelineStepConfig { plugin_id: SystemId::new(), config: StructuredData::new() },
|
||||
],
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ConfigurePipelineCommand {
|
||||
trigger_event: "asset.ingested".into(),
|
||||
steps: vec![PipelineStepConfig {
|
||||
plugin_id: SystemId::new(),
|
||||
config: StructuredData::new(),
|
||||
}],
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{EnqueueJobCommand, EnqueueJobHandler};
|
||||
use application::testing::{InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn enqueues_job() {
|
||||
@@ -11,13 +11,16 @@ async fn enqueues_job() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ExtractMetadata,
|
||||
priority: 5,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ExtractMetadata,
|
||||
priority: 5,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(job.status, JobStatus::Queued);
|
||||
assert_eq!(job.priority, 5);
|
||||
@@ -33,13 +36,16 @@ async fn enqueues_with_target_and_batch() {
|
||||
|
||||
let target = SystemId::new();
|
||||
let batch = SystemId::new();
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::GenerateDerivative,
|
||||
priority: 10,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: Some(target),
|
||||
batch_id: Some(batch),
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::GenerateDerivative,
|
||||
priority: 10,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: Some(target),
|
||||
batch_id: Some(batch),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(job.target_asset_id, Some(target));
|
||||
assert_eq!(job.batch_id, Some(batch));
|
||||
@@ -51,13 +57,16 @@ async fn publishes_event() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
let handler = EnqueueJobHandler::new(job_repo.clone(), event_pub.clone());
|
||||
|
||||
let job = handler.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ScanDirectory,
|
||||
priority: 1,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
}).await.unwrap();
|
||||
let job = handler
|
||||
.execute(EnqueueJobCommand {
|
||||
job_type: JobType::ScanDirectory,
|
||||
priority: 1,
|
||||
payload: StructuredData::new(),
|
||||
target_asset_id: None,
|
||||
batch_id: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use application::processing::{FailJobCommand, FailJobHandler};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository, StubEventPublisher};
|
||||
use domain::entities::{Job, JobBatch, JobStatus, JobType};
|
||||
use domain::events::DomainEvent;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn make_handler(
|
||||
job_repo: Arc<InMemoryJobRepository>,
|
||||
@@ -26,10 +26,13 @@ async fn retries_on_failure() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "transient error".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "transient error".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Queued);
|
||||
assert_eq!(result.retry_count, 1);
|
||||
@@ -54,10 +57,13 @@ async fn fails_permanently_after_max_retries() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
let result = handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "fatal".into(),
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "fatal".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result.status, JobStatus::Failed);
|
||||
assert_eq!(result.retry_count, 3);
|
||||
@@ -76,8 +82,7 @@ async fn updates_batch_on_permanent_failure() {
|
||||
let batch_id = batch.batch_id;
|
||||
batch_repo.save(&batch).await.unwrap();
|
||||
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new())
|
||||
.with_batch(batch_id);
|
||||
let mut job = Job::new(JobType::ExtractMetadata, 5, StructuredData::new()).with_batch(batch_id);
|
||||
// Exhaust retries
|
||||
job.fail("err1");
|
||||
job.fail("err2");
|
||||
@@ -85,10 +90,13 @@ async fn updates_batch_on_permanent_failure() {
|
||||
job_repo.save(&job).await.unwrap();
|
||||
|
||||
let handler = make_handler(job_repo.clone(), batch_repo.clone(), event_pub.clone());
|
||||
handler.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "permanent failure".into(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(FailJobCommand {
|
||||
job_id,
|
||||
error: "permanent failure".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let updated_batch = batch_repo.find_by_id(&batch_id).await.unwrap().unwrap();
|
||||
assert_eq!(updated_batch.failed_count, 1);
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryPluginRepository;
|
||||
use application::processing::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
||||
use application::testing::InMemoryPluginRepository;
|
||||
use domain::entities::{Plugin, PluginType};
|
||||
use domain::ports::PluginRepository;
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_plugin() {
|
||||
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
|
||||
let plugin = handler.execute(ManagePluginCommand {
|
||||
plugin_id: None,
|
||||
action: PluginAction::Create {
|
||||
name: "EXIF Extractor".into(),
|
||||
plugin_type: PluginType::MediaProcessor,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
}).await.unwrap();
|
||||
let plugin = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: None,
|
||||
action: PluginAction::Create {
|
||||
name: "EXIF Extractor".into(),
|
||||
plugin_type: PluginType::MediaProcessor,
|
||||
config: StructuredData::new(),
|
||||
},
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(plugin.name, "EXIF Extractor");
|
||||
assert_eq!(plugin.plugin_type, PluginType::MediaProcessor);
|
||||
@@ -36,10 +39,13 @@ async fn enables_plugin() {
|
||||
plugin_repo.save(&plugin).await.unwrap();
|
||||
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
let result = handler.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Enable,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Enable,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.is_enabled);
|
||||
}
|
||||
@@ -52,10 +58,13 @@ async fn disables_plugin() {
|
||||
plugin_repo.save(&plugin).await.unwrap();
|
||||
|
||||
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
||||
let result = handler.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Disable,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(ManagePluginCommand {
|
||||
plugin_id: Some(plugin_id),
|
||||
action: PluginAction::Disable,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(!result.is_enabled);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod enqueue_job;
|
||||
mod start_job;
|
||||
mod complete_job;
|
||||
mod configure_pipeline;
|
||||
mod enqueue_job;
|
||||
mod fail_job;
|
||||
mod manage_plugin;
|
||||
mod configure_pipeline;
|
||||
mod start_job;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryJobRepository;
|
||||
use application::processing::{StartJobCommand, StartJobHandler};
|
||||
use application::testing::InMemoryJobRepository;
|
||||
use domain::entities::{Job, JobStatus, JobType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::JobRepository;
|
||||
use domain::value_objects::StructuredData;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn starts_queued_job() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::processing::{ReportBatchProgressHandler, ReportBatchProgressQuery};
|
||||
use application::testing::{InMemoryJobBatchRepository, InMemoryJobRepository};
|
||||
use application::processing::{ReportBatchProgressQuery, ReportBatchProgressHandler};
|
||||
use domain::entities::{Job, JobBatch, JobType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{JobBatchRepository, JobRepository};
|
||||
use domain::value_objects::{StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_progress() {
|
||||
@@ -21,7 +21,10 @@ async fn returns_progress() {
|
||||
job_repo.save(&j2).await.unwrap();
|
||||
|
||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||
let progress = handler.execute(ReportBatchProgressQuery { batch_id }).await.unwrap();
|
||||
let progress = handler
|
||||
.execute(ReportBatchProgressQuery { batch_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(progress.batch.batch_id, batch_id);
|
||||
assert_eq!(progress.jobs.len(), 2);
|
||||
@@ -33,9 +36,11 @@ async fn rejects_nonexistent_batch() {
|
||||
let job_repo = Arc::new(InMemoryJobRepository::new());
|
||||
|
||||
let handler = ReportBatchProgressHandler::new(batch_repo.clone(), job_repo.clone());
|
||||
let result = handler.execute(ReportBatchProgressQuery {
|
||||
batch_id: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ReportBatchProgressQuery {
|
||||
batch_id: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryShareRepository;
|
||||
use application::sharing::{GenerateShareLinkCommand, GenerateShareLinkHandler};
|
||||
use application::testing::InMemoryShareRepository;
|
||||
use domain::entities::{LinkAccessLevel, ScopeType, ShareableType};
|
||||
use domain::value_objects::{DateTimeStamp, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn generates_link() {
|
||||
let share_repo = Arc::new(InMemoryShareRepository::new());
|
||||
let handler = GenerateShareLinkHandler::new(share_repo);
|
||||
|
||||
let (scope, link) = handler.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: None,
|
||||
max_uses: None,
|
||||
}).await.unwrap();
|
||||
let (scope, link) = handler
|
||||
.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: None,
|
||||
max_uses: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(scope.scope_type, ScopeType::Link);
|
||||
assert!(!link.token.is_empty());
|
||||
@@ -31,14 +34,17 @@ async fn generates_link_with_expiry_and_max_uses() {
|
||||
let handler = GenerateShareLinkHandler::new(share_repo);
|
||||
|
||||
let expiry = DateTimeStamp::now();
|
||||
let (_, link) = handler.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Collection,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::LimitedSearch,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: Some(expiry),
|
||||
max_uses: Some(10),
|
||||
}).await.unwrap();
|
||||
let (_, link) = handler
|
||||
.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Collection,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::LimitedSearch,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: Some(expiry),
|
||||
max_uses: Some(10),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(link.expires_at.is_some());
|
||||
assert_eq!(link.max_uses, Some(10));
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mod share_resource;
|
||||
mod generate_share_link;
|
||||
mod revoke_share;
|
||||
mod share_resource;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||
use application::sharing::{
|
||||
GenerateShareLinkCommand, GenerateShareLinkHandler,
|
||||
RevokeShareCommand, RevokeShareHandler,
|
||||
GenerateShareLinkCommand, GenerateShareLinkHandler, RevokeShareCommand, RevokeShareHandler,
|
||||
};
|
||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||
use domain::entities::{LinkAccessLevel, ShareableType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn revokes_share() {
|
||||
@@ -15,20 +14,26 @@ async fn revokes_share() {
|
||||
|
||||
// Create a scope first via generate_share_link
|
||||
let gen_handler = GenerateShareLinkHandler::new(share_repo.clone());
|
||||
let (scope, _) = gen_handler.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: None,
|
||||
max_uses: None,
|
||||
}).await.unwrap();
|
||||
let (scope, _) = gen_handler
|
||||
.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at: None,
|
||||
max_uses: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let handler = RevokeShareHandler::new(share_repo, event_pub.clone());
|
||||
handler.execute(RevokeShareCommand {
|
||||
scope_id: scope.scope_id,
|
||||
revoked_by: SystemId::new(),
|
||||
}).await.unwrap();
|
||||
handler
|
||||
.execute(RevokeShareCommand {
|
||||
scope_id: scope.scope_id,
|
||||
revoked_by: SystemId::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
@@ -40,9 +45,11 @@ async fn rejects_nonexistent_scope() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
let handler = RevokeShareHandler::new(share_repo, event_pub);
|
||||
|
||||
let result = handler.execute(RevokeShareCommand {
|
||||
scope_id: SystemId::new(),
|
||||
revoked_by: SystemId::new(),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RevokeShareCommand {
|
||||
scope_id: SystemId::new(),
|
||||
revoked_by: SystemId::new(),
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound(_))));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||
use application::sharing::{ShareResourceCommand, ShareResourceHandler};
|
||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||
use domain::entities::{ScopeType, ShareableType, TargetType};
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn shares_with_user() {
|
||||
@@ -10,14 +10,17 @@ async fn shares_with_user() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
|
||||
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
||||
let (scope, target) = handler.execute(ShareResourceCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
target_type: TargetType::User,
|
||||
target_id: SystemId::new(),
|
||||
role_id: SystemId::new(),
|
||||
created_by: SystemId::new(),
|
||||
}).await.unwrap();
|
||||
let (scope, target) = handler
|
||||
.execute(ShareResourceCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
target_type: TargetType::User,
|
||||
target_id: SystemId::new(),
|
||||
role_id: SystemId::new(),
|
||||
created_by: SystemId::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(scope.scope_type, ScopeType::User);
|
||||
assert_eq!(target.target_type, TargetType::User);
|
||||
@@ -33,14 +36,17 @@ async fn shares_with_group() {
|
||||
let event_pub = Arc::new(StubEventPublisher::new());
|
||||
|
||||
let handler = ShareResourceHandler::new(share_repo, event_pub.clone());
|
||||
let (scope, target) = handler.execute(ShareResourceCommand {
|
||||
shareable_type: ShareableType::Asset,
|
||||
shareable_id: SystemId::new(),
|
||||
target_type: TargetType::Group,
|
||||
target_id: SystemId::new(),
|
||||
role_id: SystemId::new(),
|
||||
created_by: SystemId::new(),
|
||||
}).await.unwrap();
|
||||
let (scope, target) = handler
|
||||
.execute(ShareResourceCommand {
|
||||
shareable_type: ShareableType::Asset,
|
||||
shareable_id: SystemId::new(),
|
||||
target_type: TargetType::Group,
|
||||
target_id: SystemId::new(),
|
||||
role_id: SystemId::new(),
|
||||
created_by: SystemId::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(scope.scope_type, ScopeType::Group);
|
||||
assert_eq!(target.target_type, TargetType::Group);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryShareRepository;
|
||||
use application::sharing::{
|
||||
AccessSharedResourceQuery, AccessSharedResourceHandler,
|
||||
GenerateShareLinkCommand, GenerateShareLinkHandler,
|
||||
AccessSharedResourceHandler, AccessSharedResourceQuery, GenerateShareLinkCommand,
|
||||
GenerateShareLinkHandler,
|
||||
};
|
||||
use application::testing::InMemoryShareRepository;
|
||||
use chrono::{DateTime, Utc};
|
||||
use domain::entities::{LinkAccessLevel, ShareableType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::value_objects::{DateTimeStamp, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn create_link(
|
||||
repo: &Arc<InMemoryShareRepository>,
|
||||
@@ -15,14 +15,17 @@ async fn create_link(
|
||||
max_uses: Option<u32>,
|
||||
) -> String {
|
||||
let handler = GenerateShareLinkHandler::new(repo.clone());
|
||||
let (_, link) = handler.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at,
|
||||
max_uses,
|
||||
}).await.unwrap();
|
||||
let (_, link) = handler
|
||||
.execute(GenerateShareLinkCommand {
|
||||
shareable_type: ShareableType::Album,
|
||||
shareable_id: SystemId::new(),
|
||||
access_level: LinkAccessLevel::ViewOnly,
|
||||
created_by: SystemId::new(),
|
||||
expires_at,
|
||||
max_uses,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
link.token
|
||||
}
|
||||
|
||||
@@ -32,9 +35,10 @@ async fn valid_link_returns_scope() {
|
||||
let token = create_link(&repo, None, None).await;
|
||||
|
||||
let handler = AccessSharedResourceHandler::new(repo);
|
||||
let (scope, access_level) = handler.execute(AccessSharedResourceQuery {
|
||||
token,
|
||||
}).await.unwrap();
|
||||
let (scope, access_level) = handler
|
||||
.execute(AccessSharedResourceQuery { token })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(access_level, LinkAccessLevel::ViewOnly);
|
||||
assert_eq!(scope.shareable_type, ShareableType::Album);
|
||||
@@ -59,7 +63,12 @@ async fn exhausted_link_rejected() {
|
||||
|
||||
// Use it once
|
||||
let handler = AccessSharedResourceHandler::new(repo.clone());
|
||||
handler.execute(AccessSharedResourceQuery { token: token.clone() }).await.unwrap();
|
||||
handler
|
||||
.execute(AccessSharedResourceQuery {
|
||||
token: token.clone(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Second use should fail
|
||||
let result = handler.execute(AccessSharedResourceQuery { token }).await;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{DetectExternalChangesCommand, DetectExternalChangesHandler};
|
||||
use application::sidecar::hash_helper::hash_structured_data;
|
||||
use application::sidecar::{DetectExternalChangesCommand, DetectExternalChangesHandler};
|
||||
use application::testing::{InMemorySidecarRepository, InMemorySidecarWriter};
|
||||
use domain::entities::{SidecarRecord, SyncStatus};
|
||||
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn detects_changed_sidecar() {
|
||||
@@ -31,7 +31,11 @@ async fn detects_changed_sidecar() {
|
||||
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
||||
|
||||
assert_eq!(changed, 1);
|
||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
||||
let updated = sidecar_repo
|
||||
.find_by_asset(&asset_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(updated.sync_status, SyncStatus::PendingRead);
|
||||
}
|
||||
|
||||
@@ -58,6 +62,10 @@ async fn ignores_unchanged_sidecar() {
|
||||
let changed = handler.execute(DetectExternalChangesCommand).await.unwrap();
|
||||
|
||||
assert_eq!(changed, 0);
|
||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
||||
let updated = sidecar_repo
|
||||
.find_by_asset(&asset_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{ExportSidecarCommand, ExportSidecarHandler};
|
||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
||||
use application::testing::{
|
||||
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||
};
|
||||
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
||||
use domain::entities::SyncStatus;
|
||||
use domain::ports::SidecarRepository;
|
||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn exports_sidecar_marks_in_sync() {
|
||||
@@ -20,7 +22,10 @@ async fn exports_sidecar_marks_in_sync() {
|
||||
meta_repo.save(&metadata).await.unwrap();
|
||||
|
||||
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer.clone());
|
||||
let record = handler.execute(ExportSidecarCommand { asset_id }).await.unwrap();
|
||||
let record = handler
|
||||
.execute(ExportSidecarCommand { asset_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||
assert!(record.last_known_file_hash.is_some());
|
||||
@@ -39,7 +44,10 @@ async fn creates_new_record_if_none_exists() {
|
||||
let asset_id = SystemId::new();
|
||||
|
||||
let handler = ExportSidecarHandler::new(meta_repo, sidecar_repo.clone(), writer);
|
||||
let record = handler.execute(ExportSidecarCommand { asset_id }).await.unwrap();
|
||||
let record = handler
|
||||
.execute(ExportSidecarCommand { asset_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(record.asset_id, asset_id);
|
||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{FullExportCommand, FullExportHandler};
|
||||
use application::testing::{
|
||||
InMemoryAssetRepository, InMemoryAssetMetadataRepository,
|
||||
InMemorySidecarRepository, InMemorySidecarWriter,
|
||||
InMemoryAssetMetadataRepository, InMemoryAssetRepository, InMemorySidecarRepository,
|
||||
InMemorySidecarWriter,
|
||||
};
|
||||
use domain::catalog::entities::{Asset, AssetMetadata, AssetType, MetadataSource, SourceReference};
|
||||
use domain::ports::AssetRepository;
|
||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn make_asset(owner: SystemId) -> Asset {
|
||||
let source = SourceReference {
|
||||
@@ -33,10 +33,20 @@ async fn exports_all_user_assets() {
|
||||
let mut data = StructuredData::new();
|
||||
data.insert("title", MetadataValue::String("Sunset".into()));
|
||||
use domain::ports::AssetMetadataRepository;
|
||||
meta_repo.save(&AssetMetadata::new(a1.asset_id, MetadataSource::UserEdited, data)).await.unwrap();
|
||||
meta_repo
|
||||
.save(&AssetMetadata::new(
|
||||
a1.asset_id,
|
||||
MetadataSource::UserEdited,
|
||||
data,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let handler = FullExportHandler::new(asset_repo, meta_repo, sidecar_repo, writer.clone());
|
||||
let count = handler.execute(FullExportCommand { owner_id: owner }).await.unwrap();
|
||||
let count = handler
|
||||
.execute(FullExportCommand { owner_id: owner })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(count, 2);
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{FullImportCommand, FullImportHandler};
|
||||
use application::testing::{
|
||||
InMemoryAssetRepository, InMemoryAssetMetadataRepository,
|
||||
InMemorySidecarRepository, InMemorySidecarWriter,
|
||||
InMemoryAssetMetadataRepository, InMemoryAssetRepository, InMemorySidecarRepository,
|
||||
InMemorySidecarWriter,
|
||||
};
|
||||
use domain::catalog::entities::{Asset, AssetType, MetadataSource, SourceReference};
|
||||
use domain::entities::SidecarRecord;
|
||||
use domain::ports::{AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort};
|
||||
use domain::ports::{
|
||||
AssetMetadataRepository, AssetRepository, SidecarRepository, SidecarWriterPort,
|
||||
};
|
||||
use domain::value_objects::{Checksum, MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn make_asset(owner: SystemId) -> Asset {
|
||||
let source = SourceReference {
|
||||
@@ -38,10 +40,16 @@ async fn imports_from_existing_sidecars() {
|
||||
writer.write_sidecar(&data, &path).await.unwrap();
|
||||
|
||||
let handler = FullImportHandler::new(asset_repo, meta_repo.clone(), sidecar_repo, writer);
|
||||
let count = handler.execute(FullImportCommand { owner_id: owner }).await.unwrap();
|
||||
let count = handler
|
||||
.execute(FullImportCommand { owner_id: owner })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(count, 1);
|
||||
let imported = meta_repo.find_by_asset_and_source(&asset.asset_id, MetadataSource::ExifExtracted).await.unwrap();
|
||||
let imported = meta_repo
|
||||
.find_by_asset_and_source(&asset.asset_id, MetadataSource::ExifExtracted)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(imported.is_some());
|
||||
assert_eq!(imported.unwrap().data.get_string("lens"), Some("50mm"));
|
||||
}
|
||||
@@ -59,7 +67,10 @@ async fn skips_missing_sidecars() {
|
||||
// No sidecar record, no sidecar file
|
||||
|
||||
let handler = FullImportHandler::new(asset_repo, meta_repo, sidecar_repo, writer);
|
||||
let count = handler.execute(FullImportCommand { owner_id: owner }).await.unwrap();
|
||||
let count = handler
|
||||
.execute(FullImportCommand { owner_id: owner })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(count, 0);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{ImportSidecarCommand, ImportSidecarHandler};
|
||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
||||
use application::testing::{
|
||||
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||
};
|
||||
use domain::catalog::entities::MetadataSource;
|
||||
use domain::entities::{SidecarRecord, SyncStatus};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{SidecarRepository, SidecarWriterPort};
|
||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn imports_pending_read_sidecar() {
|
||||
@@ -27,12 +29,19 @@ async fn imports_pending_read_sidecar() {
|
||||
writer.write_sidecar(&data, &path).await.unwrap();
|
||||
|
||||
let handler = ImportSidecarHandler::new(sidecar_repo.clone(), writer, meta_repo);
|
||||
let metadata = handler.execute(ImportSidecarCommand { asset_id }).await.unwrap();
|
||||
let metadata = handler
|
||||
.execute(ImportSidecarCommand { asset_id })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(metadata.metadata_source, MetadataSource::ExifExtracted);
|
||||
assert_eq!(metadata.data.get_string("camera"), Some("Canon"));
|
||||
|
||||
let updated = sidecar_repo.find_by_asset(&asset_id).await.unwrap().unwrap();
|
||||
let updated = sidecar_repo
|
||||
.find_by_asset(&asset_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(updated.sync_status, SyncStatus::InSync);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod export_sidecar;
|
||||
mod detect_external_changes;
|
||||
mod import_sidecar;
|
||||
mod resolve_conflict;
|
||||
mod export_sidecar;
|
||||
mod full_export;
|
||||
mod full_import;
|
||||
mod import_sidecar;
|
||||
mod resolve_conflict;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
use application::sidecar::{ResolveConflictCommand, ResolveConflictHandler};
|
||||
use application::testing::{InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter};
|
||||
use application::testing::{
|
||||
InMemoryAssetMetadataRepository, InMemorySidecarRepository, InMemorySidecarWriter,
|
||||
};
|
||||
use domain::catalog::entities::{AssetMetadata, MetadataSource};
|
||||
use domain::entities::{ConflictPolicy, SidecarRecord, SyncStatus};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::{AssetMetadataRepository, SidecarRepository, SidecarWriterPort};
|
||||
use domain::value_objects::{MetadataValue, StructuredData, SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn conflict_record(asset_id: SystemId, path: &str) -> SidecarRecord {
|
||||
let mut r = SidecarRecord::new(asset_id, path);
|
||||
@@ -22,17 +24,30 @@ async fn db_wins_re_exports() {
|
||||
let asset_id = SystemId::new();
|
||||
let path = format!("sidecars/{}.xmp", asset_id);
|
||||
|
||||
sidecar_repo.save(&conflict_record(asset_id, &path)).await.unwrap();
|
||||
sidecar_repo
|
||||
.save(&conflict_record(asset_id, &path))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut data = StructuredData::new();
|
||||
data.insert("title", MetadataValue::String("DB Value".into()));
|
||||
meta_repo.save(&AssetMetadata::new(asset_id, MetadataSource::UserEdited, data)).await.unwrap();
|
||||
meta_repo
|
||||
.save(&AssetMetadata::new(
|
||||
asset_id,
|
||||
MetadataSource::UserEdited,
|
||||
data,
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer.clone(), meta_repo);
|
||||
let record = handler.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::DbWins,
|
||||
}).await.unwrap();
|
||||
let record = handler
|
||||
.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::DbWins,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||
let written = writer.get(&path).await.unwrap();
|
||||
@@ -48,22 +63,34 @@ async fn file_wins_re_imports() {
|
||||
let asset_id = SystemId::new();
|
||||
let path = format!("sidecars/{}.xmp", asset_id);
|
||||
|
||||
sidecar_repo.save(&conflict_record(asset_id, &path)).await.unwrap();
|
||||
sidecar_repo
|
||||
.save(&conflict_record(asset_id, &path))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut file_data = StructuredData::new();
|
||||
file_data.insert("title", MetadataValue::String("File Value".into()));
|
||||
writer.write_sidecar(&file_data, &path).await.unwrap();
|
||||
|
||||
let handler = ResolveConflictHandler::new(sidecar_repo.clone(), writer, meta_repo.clone());
|
||||
let record = handler.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::FileWins,
|
||||
}).await.unwrap();
|
||||
let record = handler
|
||||
.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::FileWins,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(record.sync_status, SyncStatus::InSync);
|
||||
let imported = meta_repo.find_by_asset_and_source(&asset_id, MetadataSource::ExifExtracted).await.unwrap();
|
||||
let imported = meta_repo
|
||||
.find_by_asset_and_source(&asset_id, MetadataSource::ExifExtracted)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(imported.is_some());
|
||||
assert_eq!(imported.unwrap().data.get_string("title"), Some("File Value"));
|
||||
assert_eq!(
|
||||
imported.unwrap().data.get_string("title"),
|
||||
Some("File Value")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -73,13 +100,18 @@ async fn user_decision_returns_error() {
|
||||
let meta_repo = Arc::new(InMemoryAssetMetadataRepository::new());
|
||||
|
||||
let asset_id = SystemId::new();
|
||||
sidecar_repo.save(&conflict_record(asset_id, "sidecars/x.xmp")).await.unwrap();
|
||||
sidecar_repo
|
||||
.save(&conflict_record(asset_id, "sidecars/x.xmp"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let handler = ResolveConflictHandler::new(sidecar_repo, writer, meta_repo);
|
||||
let result = handler.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::RequireUserDecision,
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(ResolveConflictCommand {
|
||||
asset_id,
|
||||
policy: ConflictPolicy::RequireUserDecision,
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::Validation(msg)) if msg.contains("Manual")));
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
use std::sync::Arc;
|
||||
use bytes::Bytes;
|
||||
use application::testing::{
|
||||
InMemoryAssetRepository, InMemoryIngestSessionRepository,
|
||||
InMemoryLibraryPathRepository, InMemoryQuotaRepository,
|
||||
InMemoryStorageVolumeRepository, InMemoryUsageLedgerRepository,
|
||||
InMemoryFileStorage, StubEventPublisher,
|
||||
};
|
||||
use application::storage::{
|
||||
IngestAssetCommand, IngestAssetHandler,
|
||||
IngestAssetCommand, IngestAssetHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler,
|
||||
RegisterVolumeCommand, RegisterVolumeHandler,
|
||||
RegisterLibraryPathCommand, RegisterLibraryPathHandler,
|
||||
};
|
||||
use application::testing::{
|
||||
InMemoryAssetRepository, InMemoryFileStorage, InMemoryIngestSessionRepository,
|
||||
InMemoryLibraryPathRepository, InMemoryQuotaRepository, InMemoryStorageVolumeRepository,
|
||||
InMemoryUsageLedgerRepository, StubEventPublisher,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use domain::entities::{IngestStatus, QuotaDefinition, TimePeriod, UsageType};
|
||||
use domain::errors::DomainError;
|
||||
use domain::ports::QuotaRepository;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
struct Harness {
|
||||
ingest_repo: Arc<InMemoryIngestSessionRepository>,
|
||||
@@ -55,19 +53,26 @@ impl Harness {
|
||||
|
||||
async fn setup_volume_and_path(&self, owner: SystemId) -> SystemId {
|
||||
let vol_handler = RegisterVolumeHandler::new(self.vol_repo.clone());
|
||||
let vol = vol_handler.execute(RegisterVolumeCommand {
|
||||
volume_name: "main".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
}).await.unwrap();
|
||||
let vol = vol_handler
|
||||
.execute(RegisterVolumeCommand {
|
||||
volume_name: "main".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let path_handler = RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
|
||||
let path = path_handler.execute(RegisterLibraryPathCommand {
|
||||
volume_id: vol.volume_id,
|
||||
relative_path: "photos/inbox".into(),
|
||||
owner_id: owner,
|
||||
is_ingest_destination: true,
|
||||
}).await.unwrap();
|
||||
let path_handler =
|
||||
RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
|
||||
let path = path_handler
|
||||
.execute(RegisterLibraryPathCommand {
|
||||
volume_id: vol.volume_id,
|
||||
relative_path: "photos/inbox".into(),
|
||||
owner_id: owner,
|
||||
is_ingest_destination: true,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
path.path_id
|
||||
}
|
||||
}
|
||||
@@ -83,15 +88,18 @@ async fn ingests_successfully() {
|
||||
let path_id = h.setup_volume_and_path(user).await;
|
||||
|
||||
let handler = h.ingest_handler();
|
||||
let (asset, session) = handler.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
}).await.unwrap();
|
||||
let (asset, session) = handler
|
||||
.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(asset.mime_type, "image/jpeg");
|
||||
assert_eq!(asset.file_size, 1024);
|
||||
@@ -111,15 +119,17 @@ async fn rejects_quota_exceeded() {
|
||||
h.quota_repo.save("a).await.unwrap();
|
||||
|
||||
let handler = h.ingest_handler();
|
||||
let result = handler.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "big.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "big.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::QuotaExceeded(_))));
|
||||
}
|
||||
@@ -131,15 +141,17 @@ async fn rejects_invalid_checksum() {
|
||||
let path_id = h.setup_volume_and_path(user).await;
|
||||
|
||||
let handler = h.ingest_handler();
|
||||
let result = handler.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: "tooshort".into(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: "tooshort".into(),
|
||||
target_path_id: path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
@@ -151,11 +163,14 @@ async fn rejects_non_ingest_path() {
|
||||
|
||||
// Create volume + non-ingest path directly
|
||||
let vol_handler = RegisterVolumeHandler::new(h.vol_repo.clone());
|
||||
let vol = vol_handler.execute(RegisterVolumeCommand {
|
||||
volume_name: "main".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
}).await.unwrap();
|
||||
let vol = vol_handler
|
||||
.execute(RegisterVolumeCommand {
|
||||
volume_name: "main".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let path = domain::entities::LibraryPath::new_user_owned(
|
||||
vol.volume_id,
|
||||
@@ -167,15 +182,17 @@ async fn rejects_non_ingest_path() {
|
||||
h.path_repo.save(&path).await.unwrap();
|
||||
|
||||
let handler = h.ingest_handler();
|
||||
let result = handler.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path.path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(IngestAssetCommand {
|
||||
uploader_id: user,
|
||||
client_device_id: "iphone-1".into(),
|
||||
filename: "photo.jpg".into(),
|
||||
checksum: valid_checksum(),
|
||||
target_path_id: path.path_id,
|
||||
file_size: 1024,
|
||||
data: Bytes::from(vec![0u8; 1024]),
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mod register_volume;
|
||||
mod register_library_path;
|
||||
mod ingest_asset;
|
||||
mod register_library_path;
|
||||
mod register_volume;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryStorageVolumeRepository, InMemoryLibraryPathRepository};
|
||||
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler};
|
||||
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() {
|
||||
@@ -10,20 +13,26 @@ async fn creates_path() {
|
||||
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 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();
|
||||
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");
|
||||
@@ -37,11 +46,13 @@ async fn rejects_nonexistent_volume() {
|
||||
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;
|
||||
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(_))));
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::InMemoryStorageVolumeRepository;
|
||||
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler};
|
||||
use application::testing::InMemoryStorageVolumeRepository;
|
||||
use domain::errors::DomainError;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn creates_volume() {
|
||||
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
||||
let handler = RegisterVolumeHandler::new(repo);
|
||||
let vol = handler.execute(RegisterVolumeCommand {
|
||||
volume_name: "primary".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
}).await.unwrap();
|
||||
let vol = handler
|
||||
.execute(RegisterVolumeCommand {
|
||||
volume_name: "primary".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(vol.volume_name, "primary");
|
||||
assert_eq!(vol.uri_prefix, "file:///data");
|
||||
assert!(vol.is_writable);
|
||||
@@ -21,10 +24,12 @@ async fn creates_volume() {
|
||||
async fn rejects_empty_name() {
|
||||
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
|
||||
let handler = RegisterVolumeHandler::new(repo);
|
||||
let result = handler.execute(RegisterVolumeCommand {
|
||||
volume_name: "".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
}).await;
|
||||
let result = handler
|
||||
.execute(RegisterVolumeCommand {
|
||||
volume_name: "".into(),
|
||||
uri_prefix: "file:///data".into(),
|
||||
is_writable: true,
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Validation(_))));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
use application::storage::{CheckQuotaHandler, CheckQuotaQuery};
|
||||
use application::testing::{InMemoryQuotaRepository, InMemoryUsageLedgerRepository};
|
||||
use application::storage::{CheckQuotaQuery, CheckQuotaHandler};
|
||||
use domain::entities::{QuotaDefinition, TimePeriod, UsageLedgerEntry, UsageType};
|
||||
use domain::ports::UsageLedgerRepository;
|
||||
use domain::value_objects::SystemId;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[tokio::test]
|
||||
async fn returns_allowed() {
|
||||
@@ -17,11 +17,14 @@ async fn returns_allowed() {
|
||||
quota_repo.save("a).await.unwrap();
|
||||
|
||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||
let result = handler.execute(CheckQuotaQuery {
|
||||
user_id: user,
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 5_000,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(CheckQuotaQuery {
|
||||
user_id: user,
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 5_000,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.allowed);
|
||||
assert_eq!(result.limit, 10_000);
|
||||
@@ -44,11 +47,14 @@ async fn returns_denied() {
|
||||
ledger_repo.record(&entry).await.unwrap();
|
||||
|
||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||
let result = handler.execute(CheckQuotaQuery {
|
||||
user_id: user,
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 200,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(CheckQuotaQuery {
|
||||
user_id: user,
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 200,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(!result.allowed);
|
||||
assert_eq!(result.current_usage, 900);
|
||||
@@ -60,11 +66,14 @@ async fn returns_unlimited_when_no_quota() {
|
||||
let ledger_repo = Arc::new(InMemoryUsageLedgerRepository::new());
|
||||
|
||||
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
|
||||
let result = handler.execute(CheckQuotaQuery {
|
||||
user_id: SystemId::new(),
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 999_999,
|
||||
}).await.unwrap();
|
||||
let result = handler
|
||||
.execute(CheckQuotaQuery {
|
||||
user_id: SystemId::new(),
|
||||
usage_type: UsageType::StorageBytes,
|
||||
requested_amount: 999_999,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(result.allowed);
|
||||
assert!(result.is_unlimited);
|
||||
|
||||
Reference in New Issue
Block a user