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