use super::*;
#[test]
fn test_is_indexed_column_name_human_readable() {
assert!(PostgresIntrospector::is_indexed_column_name("items__product"));
assert!(PostgresIntrospector::is_indexed_column_name("items__product__category"));
assert!(PostgresIntrospector::is_indexed_column_name("items__product__category__code"));
assert!(PostgresIntrospector::is_indexed_column_name("order_items__product_name"));
assert!(!PostgresIntrospector::is_indexed_column_name("items"));
assert!(!PostgresIntrospector::is_indexed_column_name("items_product")); assert!(!PostgresIntrospector::is_indexed_column_name("__items")); assert!(!PostgresIntrospector::is_indexed_column_name("items__")); }
#[test]
fn test_is_indexed_column_name_entity_id() {
assert!(PostgresIntrospector::is_indexed_column_name("f200100__code"));
assert!(PostgresIntrospector::is_indexed_column_name("f1__name"));
assert!(PostgresIntrospector::is_indexed_column_name("f123456789__field"));
assert!(!PostgresIntrospector::is_indexed_column_name("f__code"));
assert!(PostgresIntrospector::is_indexed_column_name("fx123__code")); }
#[cfg(feature = "test-postgres")]
mod integration_tests {
use deadpool_postgres::{Config, ManagerConfig, RecyclingMethod, Runtime};
use tokio_postgres::NoTls;
use super::*;
use crate::postgres::PostgresAdapter;
const TEST_DB_URL: &str =
"postgresql://fraiseql_test:fraiseql_test_password@localhost:5433/test_fraiseql";
async fn create_test_introspector() -> PostgresIntrospector {
let _adapter =
PostgresAdapter::new(TEST_DB_URL).await.expect("Failed to create test adapter");
let mut cfg = Config::new();
cfg.url = Some(TEST_DB_URL.to_string());
cfg.manager = Some(ManagerConfig {
recycling_method: RecyclingMethod::Fast,
});
cfg.pool = Some(deadpool_postgres::PoolConfig::new(10));
let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls).expect("Failed to create pool");
PostgresIntrospector::new(pool)
}
#[tokio::test]
async fn test_get_columns_tf_sales() {
let introspector = create_test_introspector().await;
let columns = introspector.get_columns("tf_sales").await.expect("Failed to get columns");
assert!(columns.len() >= 10, "Expected at least 10 columns, got {}", columns.len());
let column_names: Vec<String> = columns.iter().map(|(name, _, _)| name.clone()).collect();
assert!(column_names.contains(&"revenue".to_string()));
assert!(column_names.contains(&"quantity".to_string()));
assert!(column_names.contains(&"data".to_string()));
assert!(column_names.contains(&"customer_id".to_string()));
}
#[tokio::test]
async fn test_get_indexed_columns_tf_sales() {
let introspector = create_test_introspector().await;
let indexed = introspector
.get_indexed_columns("tf_sales")
.await
.expect("Failed to get indexed columns");
assert!(indexed.len() >= 4, "Expected at least 4 indexed columns, got {}", indexed.len());
assert!(indexed.contains(&"customer_id".to_string()));
assert!(indexed.contains(&"product_id".to_string()));
assert!(indexed.contains(&"occurred_at".to_string()));
}
#[tokio::test]
async fn test_database_type() {
let introspector = create_test_introspector().await;
assert_eq!(introspector.database_type(), DatabaseType::PostgreSQL);
}
}