not working, needs fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
// tests/adresar/get_adresar_count_test.rs
|
// tests/adresar/get_adresar_count_test.rs
|
||||||
|
|
||||||
use rstest::{fixture, rstest};
|
use rstest::{fixture, rstest};
|
||||||
use server::adresar::handlers::get_adresar_count;
|
use server::adresar::handlers::get_adresar_count;
|
||||||
use common::proto::multieko2::common::{CountResponse, Empty};
|
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) {
|
async fn test_count_mixed_records(#[future] mixed_records: PgPool) {
|
||||||
let pool = mixed_records.await;
|
let pool = mixed_records.await;
|
||||||
let response = get_adresar_count(&pool, Empty {}).await.unwrap();
|
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]
|
#[rstest]
|
||||||
@@ -74,7 +75,7 @@ async fn test_count_after_deletion(#[future] mixed_records: PgPool) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let response = get_adresar_count(&pool, Empty {}).await.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]
|
#[rstest]
|
||||||
@@ -97,7 +98,7 @@ async fn test_count_all_deleted(#[future] pool: PgPool) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let response = get_adresar_count(&pool, Empty {}).await.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]
|
#[rstest]
|
||||||
@@ -105,7 +106,6 @@ async fn test_count_all_deleted(#[future] pool: PgPool) {
|
|||||||
async fn test_database_error(#[future] closed_pool: PgPool) {
|
async fn test_database_error(#[future] closed_pool: PgPool) {
|
||||||
let closed_pool = closed_pool.await;
|
let closed_pool = closed_pool.await;
|
||||||
let result = get_adresar_count(&closed_pool, Empty {}).await;
|
let result = get_adresar_count(&closed_pool, Empty {}).await;
|
||||||
|
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(result.unwrap_err().code(), tonic::Code::Internal);
|
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
|
// Verify updated count
|
||||||
let response = get_adresar_count(&pool, Empty {}).await.unwrap();
|
let response = get_adresar_count(&pool, Empty {}).await.unwrap();
|
||||||
assert_eq!(response.count, 1);
|
assert_eq!(response.count, 1); // One new non-deleted record
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,22 +29,8 @@ pub async fn setup_test_db() -> PgPool {
|
|||||||
pool
|
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) {
|
pub async fn clear_adresar_table(pool: &PgPool) {
|
||||||
sqlx::query!("DELETE FROM adresar")
|
sqlx::query("TRUNCATE adresar RESTART IDENTITY CASCADE")
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to clear adresar table");
|
.expect("Failed to clear adresar table");
|
||||||
|
|||||||
Reference in New Issue
Block a user