last error remaining
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use crate::common::setup_isolated_db;
|
||||
use server::table_script::handlers::post_table_script::post_table_script; // Fixed import
|
||||
use common::proto::komp_ac::table_script::PostTableScriptRequest;
|
||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
||||
use rstest::*;
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
@@ -12,15 +13,10 @@ async fn create_test_table(
|
||||
pool: &PgPool,
|
||||
schema_id: i64,
|
||||
table_name: &str,
|
||||
columns: Vec<(&str, &str)>,
|
||||
columns: Vec<ColumnDefinition>,
|
||||
) -> i64 {
|
||||
let column_definitions: Vec<String> = columns
|
||||
.iter()
|
||||
.map(|(name, type_def)| format!("\"{}\" {}", name, type_def))
|
||||
.collect();
|
||||
|
||||
let columns_json = json!(column_definitions);
|
||||
let indexes_json = json!([]);
|
||||
let columns_json = serde_json::to_value(columns).unwrap();
|
||||
let indexes_json = serde_json::json!([]);
|
||||
|
||||
sqlx::query_scalar!(
|
||||
r#"INSERT INTO table_definitions (schema_id, table_name, columns, indexes)
|
||||
@@ -115,22 +111,17 @@ async fn test_comprehensive_error_scenarios(
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create comprehensive error test table
|
||||
let columns = vec![
|
||||
// Valid types
|
||||
("valid_numeric", "NUMERIC(10, 2)"),
|
||||
("valid_integer", "INTEGER"),
|
||||
|
||||
// Invalid for math operations
|
||||
("text_col", "TEXT"),
|
||||
("boolean_col", "BOOLEAN"),
|
||||
("bigint_col", "BIGINT"),
|
||||
("date_col", "DATE"),
|
||||
("timestamp_col", "TIMESTAMPTZ"),
|
||||
|
||||
// Invalid target types
|
||||
("bigint_target", "BIGINT"),
|
||||
("date_target", "DATE"),
|
||||
("timestamp_target", "TIMESTAMPTZ"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "valid_numeric".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "valid_integer".into(), field_type: "INTEGER".into() },
|
||||
ColumnDefinition { name: "text_col".into(), field_type: "TEXT".into() },
|
||||
ColumnDefinition { name: "boolean_col".into(), field_type: "BOOLEAN".into() },
|
||||
ColumnDefinition { name: "bigint_col".into(), field_type: "BIGINT".into() },
|
||||
ColumnDefinition { name: "date_col".into(), field_type: "DATE".into() },
|
||||
ColumnDefinition { name: "timestamp_col".into(), field_type: "TIMESTAMPTZ".into() },
|
||||
ColumnDefinition { name: "bigint_target".into(), field_type: "BIGINT".into() },
|
||||
ColumnDefinition { name: "date_target".into(), field_type: "DATE".into() },
|
||||
ColumnDefinition { name: "timestamp_target".into(), field_type: "TIMESTAMPTZ".into() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "error_table", columns).await;
|
||||
@@ -169,7 +160,9 @@ async fn test_malformed_script_scenarios(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("result", "NUMERIC(10, 2)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "result".into(), field_type: "NUMERIC(10, 2)".into() }
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "malformed_test", columns).await;
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -194,7 +187,9 @@ async fn test_advanced_validation_scenarios(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("result", "NUMERIC(10, 2)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "result".into(), field_type: "NUMERIC(10, 2)".into() }
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "advanced_test", columns).await;
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -236,16 +231,16 @@ async fn test_dependency_cycle_detection() {
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create table_b first
|
||||
let table_b_columns = vec![
|
||||
("value_b", "NUMERIC(10, 2)"),
|
||||
("result_b", "NUMERIC(10, 2)"),
|
||||
let table_b_columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "value_b".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "result_b".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
];
|
||||
let table_b_id = create_test_table(&pool, schema_id, "table_b", table_b_columns).await;
|
||||
|
||||
// Create table_a
|
||||
let table_a_columns = vec![
|
||||
("value_a", "NUMERIC(10, 2)"),
|
||||
("result_a", "NUMERIC(10, 2)"),
|
||||
let table_a_columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "value_a".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "result_a".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
];
|
||||
let table_a_id = create_test_table(&pool, schema_id, "table_a", table_a_columns).await;
|
||||
|
||||
@@ -305,7 +300,9 @@ async fn test_edge_case_identifiers(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("result", "NUMERIC(10, 2)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "result".into(), field_type: "NUMERIC(10, 2)".into() }
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "identifier_test", columns).await;
|
||||
|
||||
// Test with edge case identifier in script
|
||||
@@ -342,7 +339,9 @@ async fn test_sql_injection_prevention() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("result", "NUMERIC(10, 2)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "result".into(), field_type: "NUMERIC(10, 2)".into() }
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "injection_test", columns).await;
|
||||
|
||||
// Attempt SQL injection through script content
|
||||
@@ -388,9 +387,9 @@ async fn test_performance_with_deeply_nested_expressions() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("x", "NUMERIC(15, 8)"),
|
||||
("performance_result", "NUMERIC(25, 12)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "x".into(), field_type: "NUMERIC(15, 8)".into() },
|
||||
ColumnDefinition { name: "performance_result".into(), field_type: "NUMERIC(25, 12)".into() },
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "performance_test", columns).await;
|
||||
|
||||
@@ -437,11 +436,11 @@ async fn test_concurrent_script_creation() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("value", "NUMERIC(10, 2)"),
|
||||
("result1", "NUMERIC(10, 2)"),
|
||||
("result2", "NUMERIC(10, 2)"),
|
||||
("result3", "NUMERIC(10, 2)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "value".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "result1".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "result2".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
ColumnDefinition { name: "result3".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "concurrent_test", columns).await;
|
||||
|
||||
@@ -500,9 +499,10 @@ async fn test_error_message_localization_and_clarity() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("text_col", "TEXT"),
|
||||
("result", "NUMERIC(10, 2)"),
|
||||
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "text_col".into(), field_type: "TEXT".into() },
|
||||
ColumnDefinition { name: "result".into(), field_type: "NUMERIC(10, 2)".into() },
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "error_clarity_test", columns).await;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::common::setup_isolated_db;
|
||||
use server::table_script::handlers::post_table_script::post_table_script; // Fixed import
|
||||
use common::proto::komp_ac::table_script::PostTableScriptRequest;
|
||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
||||
use rstest::*;
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
@@ -12,15 +13,10 @@ async fn create_test_table(
|
||||
pool: &PgPool,
|
||||
schema_id: i64,
|
||||
table_name: &str,
|
||||
columns: Vec<(&str, &str)>,
|
||||
columns: Vec<ColumnDefinition>,
|
||||
) -> i64 {
|
||||
let column_definitions: Vec<String> = columns
|
||||
.iter()
|
||||
.map(|(name, type_def)| format!("\"{}\" {}", name, type_def))
|
||||
.collect();
|
||||
|
||||
let columns_json = json!(column_definitions);
|
||||
let indexes_json = json!([]);
|
||||
let columns_json = serde_json::to_value(columns).unwrap();
|
||||
let indexes_json = serde_json::json!([]);
|
||||
|
||||
sqlx::query_scalar!(
|
||||
r#"INSERT INTO table_definitions (schema_id, table_name, columns, indexes)
|
||||
@@ -97,7 +93,9 @@ async fn test_steel_decimal_literal_operations(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("result", "NUMERIC(30, 15)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(30, 15)".to_string() }
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "literal_test", columns).await;
|
||||
|
||||
let script = format!(r#"({} "{}" "{}")"#, operation, value1, value2);
|
||||
@@ -133,9 +131,9 @@ async fn test_steel_decimal_column_operations(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("test_value", column_type),
|
||||
("result", "NUMERIC(30, 15)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "test_value".to_string(), field_type: column_type.to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(30, 15)".to_string() },
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "column_test", columns).await;
|
||||
|
||||
@@ -179,12 +177,12 @@ async fn test_complex_financial_calculation(
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create a realistic financial calculation table
|
||||
let columns = vec![
|
||||
("principal", "NUMERIC(16, 2)"), // Principal amount
|
||||
("annual_rate", "NUMERIC(6, 5)"), // Interest rate
|
||||
("years", "INTEGER"), // Time period
|
||||
("compounding_periods", "INTEGER"), // Compounding frequency
|
||||
("compound_interest", "NUMERIC(20, 8)"), // Result
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "principal".to_string(), field_type: "NUMERIC(16, 2)".to_string() }, // Principal amount
|
||||
ColumnDefinition { name: "annual_rate".to_string(), field_type: "NUMERIC(6, 5)".to_string() }, // Interest rate
|
||||
ColumnDefinition { name: "years".to_string(), field_type: "INTEGER".to_string() }, // Time period
|
||||
ColumnDefinition { name: "compounding_periods".to_string(), field_type: "INTEGER".to_string() }, // Compounding frequency
|
||||
ColumnDefinition { name: "compound_interest".to_string(), field_type: "NUMERIC(20, 8)".to_string() }, // Result
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "financial_calc", columns).await;
|
||||
@@ -217,11 +215,11 @@ async fn test_scientific_precision_calculations() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("measurement_a", "NUMERIC(25, 15)"),
|
||||
("measurement_b", "NUMERIC(25, 15)"),
|
||||
("coefficient", "NUMERIC(10, 8)"),
|
||||
("scientific_result", "NUMERIC(30, 18)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "measurement_a".to_string(), field_type: "NUMERIC(25, 15)".to_string() },
|
||||
ColumnDefinition { name: "measurement_b".to_string(), field_type: "NUMERIC(25, 15)".to_string() },
|
||||
ColumnDefinition { name: "coefficient".to_string(), field_type: "NUMERIC(10, 8)".to_string() },
|
||||
ColumnDefinition { name: "scientific_result".to_string(), field_type: "NUMERIC(30, 18)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "scientific_data", columns).await;
|
||||
@@ -259,9 +257,9 @@ async fn test_precision_boundary_conditions(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("boundary_value", numeric_type),
|
||||
("result", "NUMERIC(30, 15)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "boundary_value".to_string(), field_type: numeric_type.to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(30, 15)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "boundary_test", columns).await;
|
||||
@@ -284,11 +282,11 @@ async fn test_mixed_integer_and_numeric_operations() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("integer_quantity", "INTEGER"),
|
||||
("numeric_price", "NUMERIC(10, 4)"),
|
||||
("numeric_tax_rate", "NUMERIC(5, 4)"),
|
||||
("total_with_tax", "NUMERIC(15, 4)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "integer_quantity".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "numeric_price".to_string(), field_type: "NUMERIC(10, 4)".to_string() },
|
||||
ColumnDefinition { name: "numeric_tax_rate".to_string(), field_type: "NUMERIC(5, 4)".to_string() },
|
||||
ColumnDefinition { name: "total_with_tax".to_string(), field_type: "NUMERIC(15, 4)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "mixed_types_calc", columns).await;
|
||||
@@ -325,9 +323,9 @@ async fn test_mathematical_edge_cases(
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("test_value", "NUMERIC(15, 6)"),
|
||||
("result", "NUMERIC(20, 8)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "test_value".to_string(), field_type: "NUMERIC(15, 6)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(20, 8)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "edge_case_test", columns).await;
|
||||
@@ -381,10 +379,10 @@ async fn test_comparison_operations_with_valid_types() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("value_a", "NUMERIC(10, 2)"),
|
||||
("value_b", "INTEGER"),
|
||||
("comparison_result", "BOOLEAN"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "value_a".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "value_b".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "comparison_result".to_string(), field_type: "BOOLEAN".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "comparison_test", columns).await;
|
||||
@@ -419,11 +417,11 @@ async fn test_nested_mathematical_expressions() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("x", "NUMERIC(15, 8)"),
|
||||
("y", "NUMERIC(15, 8)"),
|
||||
("z", "INTEGER"),
|
||||
("nested_result", "NUMERIC(25, 12)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "x".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "y".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "z".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "nested_result".to_string(), field_type: "NUMERIC(25, 12)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "nested_calc", columns).await;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::common::setup_isolated_db;
|
||||
use server::table_script::handlers::post_table_script::post_table_script;
|
||||
use common::proto::komp_ac::table_script::{PostTableScriptRequest, TableScriptResponse};
|
||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -26,14 +27,9 @@ impl TableScriptTestHelper {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_table_with_types(&self, table_name: &str, column_definitions: Vec<(&str, &str)>) -> i64 {
|
||||
let columns: Vec<String> = column_definitions
|
||||
.iter()
|
||||
.map(|(name, type_def)| format!("\"{}\" {}", name, type_def))
|
||||
.collect();
|
||||
|
||||
let columns_json = json!(columns);
|
||||
let indexes_json = json!([]);
|
||||
pub async fn create_table_with_types(&self, table_name: &str, column_definitions: Vec<ColumnDefinition>) -> i64 {
|
||||
let columns_json = serde_json::to_value(column_definitions).unwrap();
|
||||
let indexes_json = serde_json::json!([]);
|
||||
|
||||
sqlx::query_scalar!(
|
||||
r#"INSERT INTO table_definitions (schema_id, table_name, columns, indexes)
|
||||
@@ -73,24 +69,24 @@ mod integration_tests {
|
||||
"comprehensive_table",
|
||||
vec![
|
||||
// Supported types for math operations
|
||||
("integer_col", "INTEGER"),
|
||||
("numeric_basic", "NUMERIC(10, 2)"),
|
||||
("numeric_high_precision", "NUMERIC(28, 15)"),
|
||||
("numeric_currency", "NUMERIC(14, 4)"),
|
||||
ColumnDefinition { name: "integer_col".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "numeric_basic".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "numeric_high_precision".to_string(), field_type: "NUMERIC(28, 15)".to_string() },
|
||||
ColumnDefinition { name: "numeric_currency".to_string(), field_type: "NUMERIC(14, 4)".to_string() },
|
||||
|
||||
// Supported but not for math operations
|
||||
("text_col", "TEXT"),
|
||||
("boolean_col", "BOOLEAN"),
|
||||
ColumnDefinition { name: "text_col".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "boolean_col".to_string(), field_type: "BOOLEAN".to_string() },
|
||||
|
||||
// Prohibited types entirely
|
||||
("bigint_col", "BIGINT"),
|
||||
("date_col", "DATE"),
|
||||
("timestamp_col", "TIMESTAMPTZ"),
|
||||
ColumnDefinition { name: "bigint_col".to_string(), field_type: "BIGINT".to_string() },
|
||||
ColumnDefinition { name: "date_col".to_string(), field_type: "DATE".to_string() },
|
||||
ColumnDefinition { name: "timestamp_col".to_string(), field_type: "TIMESTAMPTZ".to_string() },
|
||||
|
||||
// Result columns of various types
|
||||
("result_integer", "INTEGER"),
|
||||
("result_numeric", "NUMERIC(15, 5)"),
|
||||
("result_text", "TEXT"),
|
||||
ColumnDefinition { name: "result_integer".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "result_numeric".to_string(), field_type: "NUMERIC(15, 5)".to_string() },
|
||||
ColumnDefinition { name: "result_text".to_string(), field_type: "TEXT".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -150,13 +146,13 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"precision_table",
|
||||
vec![
|
||||
("low_precision", "NUMERIC(5, 2)"), // e.g., 999.99
|
||||
("medium_precision", "NUMERIC(10, 4)"), // e.g., 999999.9999
|
||||
("high_precision", "NUMERIC(28, 15)"), // Maximum PostgreSQL precision
|
||||
("currency", "NUMERIC(14, 4)"), // Standard currency precision
|
||||
("percentage", "NUMERIC(5, 4)"), // e.g., 0.9999 (99.99%)
|
||||
("integer_val", "INTEGER"),
|
||||
("result", "NUMERIC(30, 15)"),
|
||||
ColumnDefinition { name: "low_precision".to_string(), field_type: "NUMERIC(5, 2)".to_string() }, // e.g., 999.99
|
||||
ColumnDefinition { name: "medium_precision".to_string(), field_type: "NUMERIC(10, 4)".to_string() }, // e.g., 999999.9999
|
||||
ColumnDefinition { name: "high_precision".to_string(), field_type: "NUMERIC(28, 15)".to_string() }, // Maximum PostgreSQL precision
|
||||
ColumnDefinition { name: "currency".to_string(), field_type: "NUMERIC(14, 4)".to_string() }, // Standard currency precision
|
||||
ColumnDefinition { name: "percentage".to_string(), field_type: "NUMERIC(5, 4)".to_string() }, // e.g., 0.9999 (99.99%)
|
||||
ColumnDefinition { name: "integer_val".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(30, 15)".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -202,12 +198,12 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"financial_instruments",
|
||||
vec![
|
||||
("principal", "NUMERIC(16, 2)"), // Principal amount
|
||||
("annual_rate", "NUMERIC(6, 5)"), // Interest rate (e.g., 0.05250)
|
||||
("years", "INTEGER"), // Time period
|
||||
("compounding_periods", "INTEGER"), // Compounding frequency
|
||||
("fees", "NUMERIC(10, 2)"), // Transaction fees
|
||||
("compound_interest", "NUMERIC(20, 8)"), // Result column
|
||||
ColumnDefinition { name: "principal".to_string(), field_type: "NUMERIC(16, 2)".to_string() }, // Principal amount
|
||||
ColumnDefinition { name: "annual_rate".to_string(), field_type: "NUMERIC(6, 5)".to_string() }, // Interest rate (e.g., 0.05250)
|
||||
ColumnDefinition { name: "years".to_string(), field_type: "INTEGER".to_string() }, // Time period
|
||||
ColumnDefinition { name: "compounding_periods".to_string(), field_type: "INTEGER".to_string() }, // Compounding frequency
|
||||
ColumnDefinition { name: "fees".to_string(), field_type: "NUMERIC(10, 2)".to_string() }, // Transaction fees
|
||||
ColumnDefinition { name: "compound_interest".to_string(), field_type: "NUMERIC(20, 8)".to_string() }, // Result column
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -237,9 +233,9 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"scientific_data",
|
||||
vec![
|
||||
("large_number", "NUMERIC(30, 10)"),
|
||||
("small_number", "NUMERIC(30, 20)"),
|
||||
("result", "NUMERIC(35, 25)"),
|
||||
ColumnDefinition { name: "large_number".to_string(), field_type: "NUMERIC(30, 10)".to_string() },
|
||||
ColumnDefinition { name: "small_number".to_string(), field_type: "NUMERIC(30, 20)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(35, 25)".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -265,8 +261,8 @@ mod integration_tests {
|
||||
let table_a_id = helper.create_table_with_types(
|
||||
"table_a",
|
||||
vec![
|
||||
("value_a", "NUMERIC(10, 2)"),
|
||||
("result_a", "NUMERIC(10, 2)"),
|
||||
ColumnDefinition { name: "value_a".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result_a".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
]
|
||||
).await;
|
||||
println!("Created table_a with ID: {}", table_a_id);
|
||||
@@ -274,8 +270,8 @@ mod integration_tests {
|
||||
let table_b_id = helper.create_table_with_types(
|
||||
"table_b",
|
||||
vec![
|
||||
("value_b", "NUMERIC(10, 2)"),
|
||||
("result_b", "NUMERIC(10, 2)"),
|
||||
ColumnDefinition { name: "value_b".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result_b".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
]
|
||||
).await;
|
||||
println!("Created table_b with ID: {}", table_b_id);
|
||||
@@ -354,10 +350,10 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"error_test_table",
|
||||
vec![
|
||||
("text_field", "TEXT"),
|
||||
("numeric_field", "NUMERIC(10, 2)"),
|
||||
("boolean_field", "BOOLEAN"),
|
||||
("bigint_field", "BIGINT"),
|
||||
ColumnDefinition { name: "text_field".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "numeric_field".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "boolean_field".to_string(), field_type: "BOOLEAN".to_string() },
|
||||
ColumnDefinition { name: "bigint_field".to_string(), field_type: "BIGINT".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -417,11 +413,11 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"performance_table",
|
||||
vec![
|
||||
("x", "NUMERIC(15, 8)"),
|
||||
("y", "NUMERIC(15, 8)"),
|
||||
("z", "NUMERIC(15, 8)"),
|
||||
("w", "NUMERIC(15, 8)"),
|
||||
("complex_result", "NUMERIC(25, 12)"),
|
||||
ColumnDefinition { name: "x".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "y".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "z".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "w".to_string(), field_type: "NUMERIC(15, 8)".to_string() },
|
||||
ColumnDefinition { name: "complex_result".to_string(), field_type: "NUMERIC(25, 12)".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -456,11 +452,11 @@ mod integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"boundary_table",
|
||||
vec![
|
||||
("min_numeric", "NUMERIC(1, 0)"), // Minimum: single digit, no decimal
|
||||
("max_numeric", "NUMERIC(1000, 999)"), // Maximum PostgreSQL allows
|
||||
("zero_scale", "NUMERIC(10, 0)"), // Integer-like numeric
|
||||
("max_scale", "NUMERIC(28, 28)"), // Maximum scale
|
||||
("result", "NUMERIC(1000, 999)"),
|
||||
ColumnDefinition { name: "min_numeric".to_string(), field_type: "NUMERIC(1, 0)".to_string() }, // Minimum: single digit, no decimal
|
||||
ColumnDefinition { name: "max_numeric".to_string(), field_type: "NUMERIC(1000, 999)".to_string() }, // Maximum PostgreSQL allows
|
||||
ColumnDefinition { name: "zero_scale".to_string(), field_type: "NUMERIC(10, 0)".to_string() }, // Integer-like numeric
|
||||
ColumnDefinition { name: "max_scale".to_string(), field_type: "NUMERIC(28, 28)".to_string() }, // Maximum scale
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(1000, 999)".to_string() },
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -495,10 +491,10 @@ mod steel_decimal_integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"test_execution_table",
|
||||
vec![
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("quantity", "INTEGER"),
|
||||
("tax_rate", "NUMERIC(5, 4)"),
|
||||
("result", "NUMERIC(15, 4)"), // Add a result column
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "quantity".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "tax_rate".to_string(), field_type: "NUMERIC(5, 4)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(15, 4)".to_string() }, // Add a result column
|
||||
]
|
||||
).await;
|
||||
println!("Created test table with ID: {}", table_id);
|
||||
@@ -575,9 +571,9 @@ mod steel_decimal_integration_tests {
|
||||
let table_id = helper.create_table_with_types(
|
||||
"precision_test_table",
|
||||
vec![
|
||||
("precise_value", "NUMERIC(20, 12)"),
|
||||
("multiplier", "NUMERIC(20, 12)"),
|
||||
("result", "NUMERIC(25, 15)"), // Add result column
|
||||
ColumnDefinition { name: "precise_value".to_string(), field_type: "NUMERIC(20, 12)".to_string() },
|
||||
ColumnDefinition { name: "multiplier".to_string(), field_type: "NUMERIC(20, 12)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(25, 15)".to_string() }, // Add result column
|
||||
]
|
||||
).await;
|
||||
println!("Created precision test table with ID: {}", table_id);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::common::setup_isolated_db;
|
||||
use server::table_script::handlers::post_table_script::post_table_script;
|
||||
use common::proto::komp_ac::table_script::PostTableScriptRequest;
|
||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -11,15 +12,10 @@ async fn create_test_table(
|
||||
pool: &PgPool,
|
||||
schema_id: i64,
|
||||
table_name: &str,
|
||||
columns: Vec<(&str, &str)>,
|
||||
columns: Vec<ColumnDefinition>,
|
||||
) -> i64 {
|
||||
let column_definitions: Vec<String> = columns
|
||||
.iter()
|
||||
.map(|(name, type_def)| format!("\"{}\" {}", name, type_def))
|
||||
.collect();
|
||||
|
||||
let columns_json = json!(column_definitions);
|
||||
let indexes_json = json!([]);
|
||||
let columns_json = serde_json::to_value(columns).unwrap();
|
||||
let indexes_json = serde_json::json!([]);
|
||||
|
||||
sqlx::query_scalar!(
|
||||
r#"INSERT INTO table_definitions (schema_id, table_name, columns, indexes)
|
||||
@@ -67,7 +63,10 @@ async fn test_reject_bigint_target_column() {
|
||||
&pool,
|
||||
schema_id,
|
||||
"bigint_table",
|
||||
vec![("name", "TEXT"), ("big_number", "BIGINT")]
|
||||
vec![
|
||||
ColumnDefinition { name: "name".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "big_number".to_string(), field_type: "BIGINT".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -99,7 +98,10 @@ async fn test_reject_date_target_column() {
|
||||
&pool,
|
||||
schema_id,
|
||||
"date_table",
|
||||
vec![("name", "TEXT"), ("event_date", "DATE")]
|
||||
vec![
|
||||
ColumnDefinition { name: "name".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "event_date".to_string(), field_type: "DATE".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -131,7 +133,10 @@ async fn test_reject_timestamptz_target_column() {
|
||||
&pool,
|
||||
schema_id,
|
||||
"timestamp_table",
|
||||
vec![("name", "TEXT"), ("created_time", "TIMESTAMPTZ")]
|
||||
vec![
|
||||
ColumnDefinition { name: "name".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "created_time".to_string(), field_type: "TIMESTAMPTZ".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -164,9 +169,9 @@ async fn test_reject_text_in_mathematical_operations() {
|
||||
schema_id,
|
||||
"text_math_table",
|
||||
vec![
|
||||
("description", "TEXT"),
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("result", "NUMERIC(10, 2)")
|
||||
ColumnDefinition { name: "description".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(10, 2)".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -202,9 +207,9 @@ async fn test_reject_boolean_in_mathematical_operations() {
|
||||
schema_id,
|
||||
"boolean_math_table",
|
||||
vec![
|
||||
("is_active", "BOOLEAN"),
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("result", "NUMERIC(10, 2)")
|
||||
ColumnDefinition { name: "is_active".to_string(), field_type: "BOOLEAN".to_string() },
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(10, 2)".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -240,8 +245,8 @@ async fn test_reject_bigint_in_mathematical_operations() {
|
||||
schema_id,
|
||||
"bigint_math_table",
|
||||
vec![
|
||||
("big_value", "BIGINT"),
|
||||
("result", "NUMERIC(10, 2)")
|
||||
ColumnDefinition { name: "big_value".to_string(), field_type: "BIGINT".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(10, 2)".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -277,10 +282,10 @@ async fn test_allow_valid_script_with_allowed_types() {
|
||||
schema_id,
|
||||
"allowed_types_table",
|
||||
vec![
|
||||
("name", "TEXT"),
|
||||
("count", "INTEGER"),
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("computed_value", "TEXT")
|
||||
ColumnDefinition { name: "name".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "count".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "computed_value".to_string(), field_type: "TEXT".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -312,9 +317,9 @@ async fn test_allow_integer_and_numeric_in_math_operations() {
|
||||
schema_id,
|
||||
"math_allowed_table",
|
||||
vec![
|
||||
("quantity", "INTEGER"),
|
||||
("price", "NUMERIC(10, 2)"),
|
||||
("total", "NUMERIC(12, 2)")
|
||||
ColumnDefinition { name: "quantity".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "price".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "total".to_string(), field_type: "NUMERIC(12, 2)".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
@@ -328,7 +333,7 @@ async fn test_allow_integer_and_numeric_in_math_operations() {
|
||||
)
|
||||
.fetch_one(&pool)
|
||||
.await;
|
||||
|
||||
|
||||
println!("Table verification: {:?}", table_check);
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
@@ -341,7 +346,7 @@ async fn test_allow_integer_and_numeric_in_math_operations() {
|
||||
|
||||
println!("About to call post_table_script");
|
||||
let result = post_table_script(&pool, request).await;
|
||||
|
||||
|
||||
// SHOW THE ACTUAL ERROR
|
||||
if let Err(e) = &result {
|
||||
println!("ERROR: {}", e);
|
||||
@@ -363,14 +368,19 @@ async fn test_script_without_table_links_should_fail() {
|
||||
&pool,
|
||||
schema_id,
|
||||
"table_a",
|
||||
vec![("value_a", "INTEGER"), ("result", "INTEGER")]
|
||||
vec![
|
||||
ColumnDefinition { name: "value_a".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "INTEGER".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
let _table_b_id = create_test_table(
|
||||
&pool,
|
||||
schema_id,
|
||||
"table_b",
|
||||
vec![("value_b", "INTEGER")]
|
||||
"table_b",
|
||||
vec![
|
||||
ColumnDefinition { name: "value_b".to_string(), field_type: "INTEGER".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
// DON'T create a link between the tables
|
||||
@@ -404,14 +414,19 @@ async fn test_script_with_table_links_should_succeed() {
|
||||
&pool,
|
||||
schema_id,
|
||||
"linked_table_a",
|
||||
vec![("value_a", "INTEGER"), ("result", "INTEGER")]
|
||||
vec![
|
||||
ColumnDefinition { name: "value_a".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "INTEGER".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
let table_b_id = create_test_table(
|
||||
&pool,
|
||||
schema_id,
|
||||
"linked_table_b",
|
||||
vec![("value_b", "INTEGER")]
|
||||
vec![
|
||||
ColumnDefinition { name: "value_b".to_string(), field_type: "INTEGER".to_string() }
|
||||
]
|
||||
).await;
|
||||
|
||||
// Create a link between the tables (table_a can access table_b)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::common::setup_isolated_db;
|
||||
use server::table_script::handlers::post_table_script::post_table_script;
|
||||
use common::proto::komp_ac::table_script::PostTableScriptRequest;
|
||||
use common::proto::komp_ac::table_definition::ColumnDefinition;
|
||||
use rstest::*;
|
||||
use serde_json::json;
|
||||
use sqlx::PgPool;
|
||||
@@ -76,15 +77,10 @@ async fn create_test_table(
|
||||
pool: &PgPool,
|
||||
schema_id: i64,
|
||||
table_name: &str,
|
||||
columns: Vec<(&str, &str)>,
|
||||
columns: Vec<ColumnDefinition>,
|
||||
) -> i64 {
|
||||
let column_definitions: Vec<String> = columns
|
||||
.iter()
|
||||
.map(|(name, type_def)| format!("\"{}\" {}", name, type_def))
|
||||
.collect();
|
||||
|
||||
let columns_json = json!(column_definitions);
|
||||
let indexes_json = json!([]);
|
||||
let columns_json = serde_json::to_value(columns).unwrap();
|
||||
let indexes_json = serde_json::json!([]);
|
||||
|
||||
sqlx::query_scalar!(
|
||||
r#"INSERT INTO table_definitions (schema_id, table_name, columns, indexes)
|
||||
@@ -123,8 +119,17 @@ async fn test_allowed_types_in_math_operations(
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create table with all allowed mathematical types plus a result column
|
||||
let mut columns = allowed_math_types.clone();
|
||||
columns.push(("result", "NUMERIC(30, 15)"));
|
||||
let mut columns: Vec<ColumnDefinition> = allowed_math_types
|
||||
.iter()
|
||||
.map(|(name, field_type)| ColumnDefinition {
|
||||
name: name.to_string(),
|
||||
field_type: field_type.to_string(),
|
||||
})
|
||||
.collect();
|
||||
columns.push(ColumnDefinition {
|
||||
name: "result".to_string(),
|
||||
field_type: "NUMERIC(30, 15)".to_string(),
|
||||
});
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "math_test_table", columns).await;
|
||||
|
||||
@@ -172,8 +177,17 @@ async fn test_prohibited_types_in_math_operations(
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create table with prohibited types plus a valid result column
|
||||
let mut columns = prohibited_math_types.clone();
|
||||
columns.push(("result", "NUMERIC(15, 6)"));
|
||||
let mut columns: Vec<ColumnDefinition> = prohibited_math_types
|
||||
.iter()
|
||||
.map(|(name, field_type)| ColumnDefinition {
|
||||
name: name.to_string(),
|
||||
field_type: field_type.to_string(),
|
||||
})
|
||||
.collect();
|
||||
columns.push(ColumnDefinition {
|
||||
name: "result".to_string(),
|
||||
field_type: "NUMERIC(15, 6)".to_string(),
|
||||
});
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "prohibited_math_table", columns).await;
|
||||
|
||||
@@ -225,8 +239,17 @@ async fn test_prohibited_target_column_types(
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create table with prohibited target types plus some valid source columns
|
||||
let mut columns = prohibited_target_types.clone();
|
||||
columns.push(("amount", "NUMERIC(10, 2)"));
|
||||
let mut columns: Vec<ColumnDefinition> = prohibited_target_types
|
||||
.iter()
|
||||
.map(|(name, field_type)| ColumnDefinition {
|
||||
name: name.to_string(),
|
||||
field_type: field_type.to_string(),
|
||||
})
|
||||
.collect();
|
||||
columns.push(ColumnDefinition {
|
||||
name: "amount".to_string(),
|
||||
field_type: "NUMERIC(10, 2)".to_string(),
|
||||
});
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "prohibited_target_table", columns).await;
|
||||
|
||||
@@ -245,7 +268,7 @@ async fn test_prohibited_target_column_types(
|
||||
|
||||
let error_message = result.unwrap_err().to_string();
|
||||
assert!(
|
||||
error_message.to_lowercase().contains("cannot create script") ||
|
||||
error_message.to_lowercase().contains("cannot create script") ||
|
||||
error_message.contains("prohibited type"),
|
||||
"Error should mention prohibited type: {}",
|
||||
error_message
|
||||
@@ -261,7 +284,12 @@ async fn test_system_column_restrictions(#[case] target_column: &str, #[case] de
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![("amount", "NUMERIC(10, 2)")];
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition {
|
||||
name: "amount".to_string(),
|
||||
field_type: "NUMERIC(10, 2)".to_string(),
|
||||
}
|
||||
];
|
||||
let table_id = create_test_table(&pool, schema_id, "system_test_table", columns).await;
|
||||
|
||||
let script = r#"(+ "10" "20")"#;
|
||||
@@ -290,22 +318,22 @@ async fn test_comprehensive_type_matrix() {
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
// Create comprehensive table with all type categories
|
||||
let all_columns = vec![
|
||||
let all_columns: Vec<ColumnDefinition> = vec![
|
||||
// Allowed math types
|
||||
("integer_col", "INTEGER"),
|
||||
("numeric_col", "NUMERIC(10, 2)"),
|
||||
("high_precision", "NUMERIC(28, 15)"),
|
||||
|
||||
ColumnDefinition { name: "integer_col".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "numeric_col".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "high_precision".to_string(), field_type: "NUMERIC(28, 15)".to_string() },
|
||||
|
||||
// Prohibited math types
|
||||
("text_col", "TEXT"),
|
||||
("boolean_col", "BOOLEAN"),
|
||||
("bigint_col", "BIGINT"),
|
||||
("date_col", "DATE"),
|
||||
("timestamp_col", "TIMESTAMPTZ"),
|
||||
|
||||
ColumnDefinition { name: "text_col".to_string(), field_type: "TEXT".to_string() },
|
||||
ColumnDefinition { name: "boolean_col".to_string(), field_type: "BOOLEAN".to_string() },
|
||||
ColumnDefinition { name: "bigint_col".to_string(), field_type: "BIGINT".to_string() },
|
||||
ColumnDefinition { name: "date_col".to_string(), field_type: "DATE".to_string() },
|
||||
ColumnDefinition { name: "timestamp_col".to_string(), field_type: "TIMESTAMPTZ".to_string() },
|
||||
|
||||
// Result columns
|
||||
("result_numeric", "NUMERIC(20, 8)"),
|
||||
("result_text", "TEXT"),
|
||||
ColumnDefinition { name: "result_numeric".to_string(), field_type: "NUMERIC(20, 8)".to_string() },
|
||||
ColumnDefinition { name: "result_text".to_string(), field_type: "TEXT".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "comprehensive_table", all_columns).await;
|
||||
@@ -316,7 +344,7 @@ async fn test_comprehensive_type_matrix() {
|
||||
("integer_col", "+", "result_numeric", true),
|
||||
("numeric_col", "*", "result_numeric", true),
|
||||
("high_precision", "/", "result_numeric", true),
|
||||
|
||||
|
||||
// Invalid source types in math
|
||||
("text_col", "+", "result_numeric", false),
|
||||
("boolean_col", "*", "result_numeric", false),
|
||||
@@ -361,20 +389,20 @@ async fn test_complex_mathematical_expressions() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("principal", "NUMERIC(16, 2)"),
|
||||
("rate", "NUMERIC(6, 5)"),
|
||||
("years", "INTEGER"),
|
||||
("compound_result", "NUMERIC(20, 8)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "principal".to_string(), field_type: "NUMERIC(16, 2)".to_string() },
|
||||
ColumnDefinition { name: "rate".to_string(), field_type: "NUMERIC(6, 5)".to_string() },
|
||||
ColumnDefinition { name: "years".to_string(), field_type: "INTEGER".to_string() },
|
||||
ColumnDefinition { name: "compound_result".to_string(), field_type: "NUMERIC(20, 8)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "financial_table", columns).await;
|
||||
|
||||
// Complex compound interest calculation - all using allowed types
|
||||
let complex_script = r#"
|
||||
(*
|
||||
(*
|
||||
(steel_get_column "financial_table" "principal")
|
||||
(pow
|
||||
(pow
|
||||
(+ "1" (steel_get_column "financial_table" "rate"))
|
||||
(steel_get_column "financial_table" "years")))
|
||||
"#;
|
||||
@@ -395,9 +423,9 @@ async fn test_nonexistent_column_reference() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("result", "NUMERIC(10, 2)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "simple_table", columns).await;
|
||||
@@ -427,9 +455,9 @@ async fn test_nonexistent_table_reference() {
|
||||
let pool = setup_isolated_db().await;
|
||||
let schema_id = get_default_schema_id(&pool).await;
|
||||
|
||||
let columns = vec![
|
||||
("amount", "NUMERIC(10, 2)"),
|
||||
("result", "NUMERIC(10, 2)"),
|
||||
let columns: Vec<ColumnDefinition> = vec![
|
||||
ColumnDefinition { name: "amount".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
ColumnDefinition { name: "result".to_string(), field_type: "NUMERIC(10, 2)".to_string() },
|
||||
];
|
||||
|
||||
let table_id = create_test_table(&pool, schema_id, "existing_table", columns).await;
|
||||
|
||||
Reference in New Issue
Block a user