diff --git a/server/tests/adresar/get_adresar_count_test.rs b/server/tests/adresar/get_adresar_count_test.rs index 878c319..4fff9ec 100644 --- a/server/tests/adresar/get_adresar_count_test.rs +++ b/server/tests/adresar/get_adresar_count_test.rs @@ -1,4 +1,5 @@ // tests/adresar/get_adresar_count_test.rs + use rstest::{fixture, rstest}; use server::adresar::handlers::get_adresar_count; use common::proto::multieko2::common::{CountResponse, Empty}; @@ -57,7 +58,7 @@ async fn test_count_empty_database(#[future] pool: PgPool) { async fn test_count_mixed_records(#[future] mixed_records: PgPool) { let pool = mixed_records.await; let response = get_adresar_count(&pool, Empty {}).await.unwrap(); - assert_eq!(response.count, 3); + assert_eq!(response.count, 3); // Only non-deleted records are counted } #[rstest] @@ -74,7 +75,7 @@ async fn test_count_after_deletion(#[future] mixed_records: PgPool) { .unwrap(); let response = get_adresar_count(&pool, Empty {}).await.unwrap(); - assert_eq!(response.count, 2); + assert_eq!(response.count, 2); // One fewer non-deleted record } #[rstest] @@ -97,7 +98,7 @@ async fn test_count_all_deleted(#[future] pool: PgPool) { .unwrap(); let response = get_adresar_count(&pool, Empty {}).await.unwrap(); - assert_eq!(response.count, 0); + assert_eq!(response.count, 0); // No non-deleted records } #[rstest] @@ -105,7 +106,6 @@ async fn test_count_all_deleted(#[future] pool: PgPool) { async fn test_database_error(#[future] closed_pool: PgPool) { let closed_pool = closed_pool.await; let result = get_adresar_count(&closed_pool, Empty {}).await; - assert!(result.is_err()); assert_eq!(result.unwrap_err().code(), tonic::Code::Internal); } @@ -130,5 +130,5 @@ async fn test_count_after_insert(#[future] pool: PgPool) { // Verify updated count let response = get_adresar_count(&pool, Empty {}).await.unwrap(); - assert_eq!(response.count, 1); + assert_eq!(response.count, 1); // One new non-deleted record } diff --git a/server/tests/common/mod.rs b/server/tests/common/mod.rs index 81dfbfc..9b700f0 100644 --- a/server/tests/common/mod.rs +++ b/server/tests/common/mod.rs @@ -29,22 +29,8 @@ pub async fn setup_test_db() -> PgPool { pool } -// Add this to tests/common/mod.rs -pub async fn clear_all_tables(pool: &PgPool) { - // Clear tables in the correct order to respect foreign key constraints - clear_uctovnictvo_table(pool).await; - clear_adresar_table(pool).await; -} - -pub async fn clear_uctovnictvo_table(pool: &PgPool) { - sqlx::query!("DELETE FROM uctovnictvo") - .execute(pool) - .await - .expect("Failed to clear uctovnictvo table"); -} - pub async fn clear_adresar_table(pool: &PgPool) { - sqlx::query!("DELETE FROM adresar") + sqlx::query("TRUNCATE adresar RESTART IDENTITY CASCADE") .execute(pool) .await .expect("Failed to clear adresar table");