working without any problems
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// tests/adresar/get_adresar_by_position_test.rs
|
// tests/adresar/get_adresar_by_position_test.rs
|
||||||
use rstest::{fixture, rstest};
|
use rstest::{fixture, rstest};
|
||||||
use server::adresar::handlers::get_adresar_by_position;
|
use server::adresar::handlers::{get_adresar_by_position, get_adresar_count};
|
||||||
use common::proto::multieko2::common::PositionRequest;
|
use common::proto::multieko2::common::{PositionRequest, Empty};
|
||||||
use crate::common::setup_test_db;
|
use crate::common::setup_test_db;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use tonic;
|
use tonic;
|
||||||
@@ -193,7 +193,7 @@ async fn test_position_changes_after_deletion(#[future] pool: PgPool) {
|
|||||||
let id3 = create_test_record(&pool, &format!("{}_3", prefix), false).await;
|
let id3 = create_test_record(&pool, &format!("{}_3", prefix), false).await;
|
||||||
|
|
||||||
// Find initial positions
|
// Find initial positions
|
||||||
let pos1 = find_position_of_record(&pool, id1).await.unwrap();
|
let _pos1 = find_position_of_record(&pool, id1).await.unwrap();
|
||||||
let pos2 = find_position_of_record(&pool, id2).await.unwrap();
|
let pos2 = find_position_of_record(&pool, id2).await.unwrap();
|
||||||
let pos3 = find_position_of_record(&pool, id3).await.unwrap();
|
let pos3 = find_position_of_record(&pool, id3).await.unwrap();
|
||||||
|
|
||||||
@@ -301,3 +301,68 @@ async fn test_position_after_adding_record(#[future] pool: PgPool) {
|
|||||||
// Clean up test data
|
// Clean up test data
|
||||||
cleanup_test_records(&pool, prefix).await;
|
cleanup_test_records(&pool, prefix).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test handler correctly excludes deleted records
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handler_excludes_deleted_records(#[future] pool: PgPool) {
|
||||||
|
let pool = pool.await;
|
||||||
|
|
||||||
|
// Take a lock to prevent concurrent test execution
|
||||||
|
let _guard = TEST_MUTEX.lock().await;
|
||||||
|
|
||||||
|
// Use a unique prefix for test data
|
||||||
|
let prefix = "CountTest";
|
||||||
|
|
||||||
|
// Clean up any existing test data
|
||||||
|
cleanup_test_records(&pool, prefix).await;
|
||||||
|
|
||||||
|
// Create active records
|
||||||
|
for i in 1..=3 {
|
||||||
|
create_test_record(&pool, &format!("{}_Active_{}", prefix, i), false).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create deleted records
|
||||||
|
for i in 1..=2 {
|
||||||
|
create_test_record(&pool, &format!("{}_Deleted_{}", prefix, i), true).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count our test records by deleted status
|
||||||
|
let active_test_count = sqlx::query_scalar!(
|
||||||
|
"SELECT COUNT(*) FROM adresar WHERE firma LIKE $1 AND deleted = FALSE",
|
||||||
|
format!("{}%", prefix)
|
||||||
|
)
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
let deleted_test_count = sqlx::query_scalar!(
|
||||||
|
"SELECT COUNT(*) FROM adresar WHERE firma LIKE $1 AND deleted = TRUE",
|
||||||
|
format!("{}%", prefix)
|
||||||
|
)
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
// Verify our test data was inserted correctly
|
||||||
|
assert_eq!(active_test_count, 3);
|
||||||
|
assert_eq!(deleted_test_count, 2);
|
||||||
|
|
||||||
|
// Get the total count of active records (including existing ones)
|
||||||
|
let total_active_count = sqlx::query_scalar!(
|
||||||
|
"SELECT COUNT(*) FROM adresar WHERE deleted = FALSE"
|
||||||
|
)
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
// Now call our handler and verify it returns the same count
|
||||||
|
let response = get_adresar_count(&pool, Empty {}).await.unwrap();
|
||||||
|
assert_eq!(response.count, total_active_count);
|
||||||
|
|
||||||
|
// Clean up test data
|
||||||
|
cleanup_test_records(&pool, prefix).await;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user