style: cargo fmt --all
This commit is contained in:
@@ -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(_))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user