app: add organization + sharing commands/queries
This commit is contained in:
47
crates/application/tests/sharing/commands/share_resource.rs
Normal file
47
crates/application/tests/sharing/commands/share_resource.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use std::sync::Arc;
|
||||
use application::testing::{InMemoryShareRepository, StubEventPublisher};
|
||||
use application::sharing::{ShareResourceCommand, ShareResourceHandler};
|
||||
use domain::entities::{ScopeType, ShareableType, TargetType};
|
||||
use domain::value_objects::SystemId;
|
||||
|
||||
#[tokio::test]
|
||||
async fn shares_with_user() {
|
||||
let share_repo = Arc::new(InMemoryShareRepository::new());
|
||||
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();
|
||||
|
||||
assert_eq!(scope.scope_type, ScopeType::User);
|
||||
assert_eq!(target.target_type, TargetType::User);
|
||||
assert_eq!(target.scope_id, scope.scope_id);
|
||||
|
||||
let events = event_pub.published().await;
|
||||
assert_eq!(events.len(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shares_with_group() {
|
||||
let share_repo = Arc::new(InMemoryShareRepository::new());
|
||||
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();
|
||||
|
||||
assert_eq!(scope.scope_type, ScopeType::Group);
|
||||
assert_eq!(target.target_type, TargetType::Group);
|
||||
}
|
||||
Reference in New Issue
Block a user