test: move sqlite tests to tests/

No inline exceptions; migrate via sqlite::migrate, renamed diary/social tests.
This commit is contained in:
2026-10-25 22:40:53 +01:00
parent 8526b77f18
commit f6383d6c04
15 changed files with 39 additions and 41 deletions

View File

@@ -169,6 +169,3 @@ impl SqliteDiaryRepository {
.map_err(crate::shared::map_sqlx_error) .map_err(crate::shared::map_sqlx_error)
} }
} }
#[cfg(test)]
mod tests;

View File

@@ -64,6 +64,3 @@ impl ImageRefQuery for SqliteImageRefAdapter {
Ok(rows.into_iter().map(|(k,)| k).collect()) Ok(rows.into_iter().map(|(k,)| k).collect())
} }
} }
#[cfg(test)]
mod tests;

View File

@@ -23,6 +23,3 @@ pub fn create_person_adapter(pool: SqlitePool) -> (Arc<dyn PersonCommand>, Arc<d
adapter as Arc<dyn PersonQuery>, adapter as Arc<dyn PersonQuery>,
) )
} }
#[cfg(test)]
mod tests;

View File

@@ -298,6 +298,3 @@ impl MovieProfileRepository for SqliteMovieProfileRepository {
.collect()) .collect())
} }
} }
#[cfg(test)]
mod tests;

View File

@@ -22,6 +22,3 @@ pub fn create_search_adapter(pool: SqlitePool) -> (Arc<dyn SearchCommand>, Arc<d
adapter as Arc<dyn SearchPort>, adapter as Arc<dyn SearchPort>,
) )
} }
#[cfg(test)]
mod tests;

View File

@@ -22,6 +22,3 @@ pub fn create_federated_profile_query(
) -> std::sync::Arc<dyn domain::ports::FederatedProfileQuery> { ) -> std::sync::Arc<dyn domain::ports::FederatedProfileQuery> {
std::sync::Arc::new(SqliteSocialRepository::new(pool, instance)) std::sync::Arc::new(SqliteSocialRepository::new(pool, instance))
} }
#[cfg(test)]
mod tests;

View File

@@ -197,6 +197,3 @@ impl UserRepository for SqliteUserRepository {
.collect() .collect()
} }
} }
#[cfg(test)]
mod tests;

View File

@@ -0,0 +1,14 @@
#[path = "repositories/diary_repository_test.rs"]
mod diary_repository_test;
#[path = "repositories/image_ref_adapter_test.rs"]
mod image_ref_adapter_test;
#[path = "repositories/movie_profile_repository_test.rs"]
mod movie_profile_repository_test;
#[path = "repositories/person_adapter_test.rs"]
mod person_adapter_test;
#[path = "repositories/search_adapter_test.rs"]
mod search_adapter_test;
#[path = "repositories/social_repository_test.rs"]
mod social_repository_test;
#[path = "repositories/user_repository_test.rs"]
mod user_repository_test;

View File

@@ -1,13 +1,13 @@
use super::*;
use domain::{ use domain::{
models::collections::PageParams, models::collections::PageParams,
models::{FeedSortBy, FollowingFilter}, models::{FeedSortBy, FollowingFilter},
ports::DiaryQuery, ports::DiaryQuery,
}; };
use sqlite::SqliteDiaryRepository;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn setup(pool: &SqlitePool) { async fn setup(pool: &SqlitePool) {
sqlx::migrate!("./migrations").run(pool).await.unwrap(); sqlite::migrate(pool).await.unwrap();
sqlx::query( sqlx::query(
"INSERT INTO users (id, email, username, password_hash, created_at) VALUES "INSERT INTO users (id, email, username, password_hash, created_at) VALUES
@@ -41,7 +41,7 @@ async fn setup(pool: &SqlitePool) {
} }
#[tokio::test] #[tokio::test]
async fn test_sort_by_rating_descending() { async fn activity_feed_sorts_by_rating_descending() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -61,7 +61,7 @@ async fn test_sort_by_rating_descending() {
} }
#[tokio::test] #[tokio::test]
async fn test_search_by_title() { async fn activity_feed_filters_by_title_search() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -77,7 +77,7 @@ async fn test_search_by_title() {
} }
#[tokio::test] #[tokio::test]
async fn test_following_filter() { async fn activity_feed_restricts_to_followed_local_and_remote_authors() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -105,7 +105,7 @@ async fn test_following_filter() {
} }
#[tokio::test] #[tokio::test]
async fn test_get_movie_stats_local() { async fn movie_stats_for_local_review() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -123,7 +123,7 @@ async fn test_get_movie_stats_local() {
} }
#[tokio::test] #[tokio::test]
async fn test_get_movie_social_feed_returns_reviews_for_movie() { async fn movie_social_feed_returns_reviews_for_movie() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -143,7 +143,7 @@ async fn test_get_movie_social_feed_returns_reviews_for_movie() {
} }
#[tokio::test] #[tokio::test]
async fn test_get_movie_social_feed_federated_review() { async fn movie_social_feed_marks_federated_review_as_remote() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -164,7 +164,7 @@ async fn test_get_movie_social_feed_federated_review() {
} }
#[tokio::test] #[tokio::test]
async fn test_get_movie_social_feed_pagination() { async fn movie_social_feed_offset_past_end_returns_no_items() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);
@@ -180,7 +180,7 @@ async fn test_get_movie_social_feed_pagination() {
} }
#[tokio::test] #[tokio::test]
async fn test_get_movie_stats_federated() { async fn movie_stats_counts_federated_review() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup(&pool).await; setup(&pool).await;
let repo = SqliteDiaryRepository::new(pool); let repo = SqliteDiaryRepository::new(pool);

View File

@@ -1,4 +1,6 @@
use super::*; use domain::ports::{ImageRefCommand, ImageRefQuery};
use sqlite::SqliteImageRefAdapter;
use sqlx::SqlitePool;
async fn setup(pool: &SqlitePool) { async fn setup(pool: &SqlitePool) {
sqlx::query( sqlx::query(

View File

@@ -1,5 +1,5 @@
use super::SqliteMovieProfileRepository;
use domain::{ports::MovieProfileRepository, value_objects::MovieId}; use domain::{ports::MovieProfileRepository, value_objects::MovieId};
use sqlite::SqliteMovieProfileRepository;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn pool_with_schema() -> SqlitePool { async fn pool_with_schema() -> SqlitePool {

View File

@@ -1,9 +1,9 @@
use super::SqlitePersonAdapter;
use domain::testing::test_person_with_tmdb; use domain::testing::test_person_with_tmdb;
use domain::{ use domain::{
models::{ExternalPersonId, PersonId}, models::{ExternalPersonId, PersonId},
ports::{PersonCommand, PersonQuery}, ports::{PersonCommand, PersonQuery},
}; };
use sqlite::SqlitePersonAdapter;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn pool_with_schema() -> SqlitePool { async fn pool_with_schema() -> SqlitePool {

View File

@@ -1,10 +1,10 @@
use super::create_search_adapter;
use domain::{ use domain::{
models::{ models::{
EntityType, IndexableDocument, Movie, SearchFilters, SearchQuery, collections::PageParams, EntityType, IndexableDocument, Movie, SearchFilters, SearchQuery, collections::PageParams,
}, },
value_objects::{MovieId, MovieTitle, ReleaseYear}, value_objects::{MovieId, MovieTitle, ReleaseYear},
}; };
use sqlite::create_search_adapter;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn pool_with_schema() -> SqlitePool { async fn pool_with_schema() -> SqlitePool {

View File

@@ -1,6 +1,6 @@
use super::*;
use domain::ports::{FederationAdminQuery, FollowQuery}; use domain::ports::{FederationAdminQuery, FollowQuery};
use domain::value_objects::{FollowStatus, InstanceIdentity, SocialIdentity}; use domain::value_objects::{FollowStatus, InstanceIdentity, SocialIdentity};
use sqlite::SqliteSocialRepository;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn test_pool() -> SqlitePool { async fn test_pool() -> SqlitePool {
@@ -220,7 +220,7 @@ async fn setup_admin_query_db(pool: &SqlitePool) {
} }
#[tokio::test] #[tokio::test]
async fn test_list_all_followed_remote_actors_deduplicates() { async fn list_all_followed_remote_actors_deduplicates_across_users() {
let pool = SqlitePool::connect(":memory:").await.unwrap(); let pool = SqlitePool::connect(":memory:").await.unwrap();
setup_admin_query_db(&pool).await; setup_admin_query_db(&pool).await;
let repo = let repo =

View File

@@ -1,5 +1,8 @@
use super::*; use domain::models::UserProfile;
use domain::ports::UserRepository;
use domain::testing::test_user; use domain::testing::test_user;
use domain::value_objects::UserId;
use sqlite::SqliteUserRepository;
use sqlx::SqlitePool; use sqlx::SqlitePool;
async fn setup() -> (SqlitePool, SqliteUserRepository) { async fn setup() -> (SqlitePool, SqliteUserRepository) {
@@ -59,7 +62,7 @@ async fn update_profile_persists_bio_and_avatar() {
repo.update_profile( repo.update_profile(
user.id(), user.id(),
&domain::models::UserProfile { &UserProfile {
bio: Some("My biography".to_string()), bio: Some("My biography".to_string()),
avatar_path: Some("avatars/user1".to_string()), avatar_path: Some("avatars/user1".to_string()),
..Default::default() ..Default::default()
@@ -80,7 +83,7 @@ async fn update_profile_clears_fields_with_none() {
repo.save(&user).await.unwrap(); repo.save(&user).await.unwrap();
repo.update_profile( repo.update_profile(
user.id(), user.id(),
&domain::models::UserProfile { &UserProfile {
bio: Some("bio".to_string()), bio: Some("bio".to_string()),
avatar_path: Some("path".to_string()), avatar_path: Some("path".to_string()),
..Default::default() ..Default::default()
@@ -88,7 +91,7 @@ async fn update_profile_clears_fields_with_none() {
) )
.await .await
.unwrap(); .unwrap();
repo.update_profile(user.id(), &domain::models::UserProfile::default()) repo.update_profile(user.id(), &UserProfile::default())
.await .await
.unwrap(); .unwrap();