last error remaining

This commit is contained in:
Priec
2025-09-18 18:53:55 +02:00
parent 1f6dc3cd75
commit 49277cfdd4
6 changed files with 278 additions and 241 deletions

View File

@@ -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);