style: cargo fmt --all

This commit is contained in:
2026-05-31 05:31:42 +02:00
parent 4b31a0f74b
commit c2ebca0da0
138 changed files with 2422 additions and 1164 deletions

View File

@@ -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));

View File

@@ -1,3 +1,3 @@
mod share_resource;
mod generate_share_link;
mod revoke_share;
mod share_resource;

View File

@@ -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(_))));
}

View File

@@ -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);

View File

@@ -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;