Refactor code for improved readability and consistency
- Simplified error handling in `PostgresApContentQuery` and `SqliteApContentQuery` by aligning the formatting of `try_get` calls. - Removed unnecessary line breaks and improved formatting in various repository implementations for better readability. - Consolidated imports in `lib.rs` and `factory.rs` to maintain a cleaner structure. - Enhanced consistency in async function signatures across multiple files. - Updated test helpers and use cases to streamline code and improve clarity. - Refactored `InMemory` repositories to enhance readability by aligning method implementations.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "federation")]
|
||||
use domain::testing::PanicRemoteWatchlistRepository;
|
||||
use domain::{
|
||||
ports::{
|
||||
AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, ImageStorage,
|
||||
@@ -18,13 +20,8 @@ use domain::{
|
||||
PanicSearchPort, PanicStatsRepository,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "federation")]
|
||||
use domain::testing::PanicRemoteWatchlistRepository;
|
||||
|
||||
use crate::{
|
||||
config::AppConfig,
|
||||
context::AppContext,
|
||||
};
|
||||
use crate::{config::AppConfig, context::AppContext};
|
||||
|
||||
pub struct TestContextBuilder {
|
||||
pub movie_repo: Arc<dyn MovieRepository>,
|
||||
|
||||
@@ -68,8 +68,8 @@ mod tests {
|
||||
use domain::{
|
||||
models::Movie,
|
||||
ports::MovieRepository,
|
||||
value_objects::{MovieTitle, ReleaseYear},
|
||||
testing::{InMemoryMovieRepository, InMemoryWatchlistRepository},
|
||||
value_objects::{MovieTitle, ReleaseYear},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
||||
@@ -62,17 +62,15 @@ mod tests {
|
||||
use domain::{
|
||||
models::{Movie, Review},
|
||||
ports::{MovieRepository, ReviewRepository},
|
||||
value_objects::{MovieId, MovieTitle, Rating, ReleaseYear, UserId},
|
||||
testing::{
|
||||
FakeDiaryRepository, InMemoryMovieRepository, InMemoryReviewRepository,
|
||||
NoopEventPublisher,
|
||||
},
|
||||
value_objects::{MovieId, MovieTitle, Rating, ReleaseYear, UserId},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
commands::DeleteReviewCommand,
|
||||
test_helpers::TestContextBuilder,
|
||||
use_cases::delete_review,
|
||||
commands::DeleteReviewCommand, test_helpers::TestContextBuilder, use_cases::delete_review,
|
||||
};
|
||||
|
||||
fn make_movie() -> Movie {
|
||||
@@ -86,8 +84,14 @@ mod tests {
|
||||
}
|
||||
|
||||
fn make_review(movie_id: MovieId, user_id: UserId) -> Review {
|
||||
Review::new(movie_id, user_id, Rating::new(4).unwrap(), None, Utc::now().naive_utc())
|
||||
.unwrap()
|
||||
Review::new(
|
||||
movie_id,
|
||||
user_id,
|
||||
Rating::new(4).unwrap(),
|
||||
None,
|
||||
Utc::now().naive_utc(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -54,11 +54,7 @@ mod tests {
|
||||
use domain::testing::InMemoryUserRepository;
|
||||
use domain::value_objects::Email;
|
||||
|
||||
use crate::{
|
||||
commands::RegisterCommand,
|
||||
test_helpers::TestContextBuilder,
|
||||
use_cases::register,
|
||||
};
|
||||
use crate::{commands::RegisterCommand, test_helpers::TestContextBuilder, use_cases::register};
|
||||
|
||||
fn cmd(email: &str) -> RegisterCommand {
|
||||
RegisterCommand {
|
||||
@@ -76,7 +72,9 @@ mod tests {
|
||||
.with_users(Arc::clone(&users) as _)
|
||||
.build();
|
||||
|
||||
register::execute(&ctx, cmd("alice@example.com")).await.unwrap();
|
||||
register::execute(&ctx, cmd("alice@example.com"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let email = Email::new("alice@example.com".into()).unwrap();
|
||||
let user = users.find_by_email(&email).await.unwrap().unwrap();
|
||||
@@ -91,7 +89,9 @@ mod tests {
|
||||
.with_users(Arc::clone(&users) as _)
|
||||
.build();
|
||||
|
||||
register::execute(&ctx, cmd("bob@example.com")).await.unwrap();
|
||||
register::execute(&ctx, cmd("bob@example.com"))
|
||||
.await
|
||||
.unwrap();
|
||||
let result = register::execute(&ctx, cmd("bob@example.com")).await;
|
||||
assert!(result.is_err(), "duplicate email should fail");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user