fixing post table script

This commit is contained in:
filipriec
2025-07-20 11:46:00 +02:00
parent 7d1b130b68
commit bcb433d7b2
6 changed files with 155 additions and 114 deletions

View File

@@ -1,7 +1,7 @@
// tests/table_script/mathematical_operations_tests.rs
use crate::common::setup_isolated_db;
use multieko2_server::table_script::handlers::post_table_script::post_table_script;
use server::table_script::handlers::post_table_script::post_table_script; // Fixed import
use common::proto::multieko2::table_script::PostTableScriptRequest;
use rstest::*;
use serde_json::json;
@@ -53,14 +53,14 @@ pub fn steel_decimal_operations() -> Vec<(&'static str, &'static str, &'static s
("-", "subtraction", "binary"),
("*", "multiplication", "binary"),
("/", "division", "binary"),
// Advanced math
("sqrt", "square_root", "unary"),
("abs", "absolute_value", "unary"),
("min", "minimum", "binary"),
("max", "maximum", "binary"),
("pow", "power", "binary"),
// Comparison operations
(">", "greater_than", "binary"),
("<", "less_than", "binary"),
@@ -106,7 +106,7 @@ async fn test_steel_decimal_literal_operations(
table_definition_id: table_id,
target_column: "result".to_string(),
script,
description: Some(format!("Steel decimal {} with literals", operation)),
description: format!("Steel decimal {} with literals", operation), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -158,7 +158,7 @@ async fn test_steel_decimal_column_operations(
table_definition_id: table_id,
target_column: "result".to_string(),
script,
description: Some(format!("Steel decimal {} with {} column", operation, column_type)),
description: format!("Steel decimal {} with {} column", operation, column_type), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -191,10 +191,10 @@ async fn test_complex_financial_calculation(
// Complex compound interest formula: P * (1 + r/n)^(n*t)
let compound_script = r#"
(*
(*
(steel_get_column "financial_calc" "principal")
(pow
(+ "1"
(pow
(+ "1"
(/ (steel_get_column "financial_calc" "annual_rate")
(steel_get_column "financial_calc" "compounding_periods")))
(* (steel_get_column "financial_calc" "years")
@@ -205,7 +205,7 @@ async fn test_complex_financial_calculation(
table_definition_id: table_id,
target_column: "compound_interest".to_string(),
script: compound_script.to_string(),
description: Some("Complex compound interest calculation".to_string()),
description: "Complex compound interest calculation".to_string(), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -239,7 +239,7 @@ async fn test_scientific_precision_calculations() {
table_definition_id: table_id,
target_column: "scientific_result".to_string(),
script: scientific_script.to_string(),
description: Some("High precision scientific calculation".to_string()),
description: "High precision scientific calculation".to_string(), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -272,7 +272,7 @@ async fn test_precision_boundary_conditions(
table_definition_id: table_id,
target_column: "result".to_string(),
script: script.to_string(),
description: Some(description.to_string()),
description: description.to_string(), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -295,7 +295,7 @@ async fn test_mixed_integer_and_numeric_operations() {
// Calculate total with tax: (quantity * price) * (1 + tax_rate)
let mixed_script = r#"
(*
(*
(* (steel_get_column "mixed_types_calc" "integer_quantity")
(steel_get_column "mixed_types_calc" "numeric_price"))
(+ "1" (steel_get_column "mixed_types_calc" "numeric_tax_rate")))
@@ -305,7 +305,7 @@ async fn test_mixed_integer_and_numeric_operations() {
table_definition_id: table_id,
target_column: "total_with_tax".to_string(),
script: mixed_script.to_string(),
description: Some("Mixed INTEGER and NUMERIC calculation".to_string()),
description: "Mixed INTEGER and NUMERIC calculation".to_string(), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -351,13 +351,13 @@ async fn test_mathematical_edge_cases(
table_definition_id: table_id,
target_column: "result".to_string(),
script,
description: Some(description.to_string()),
description: description.to_string(), // Fixed: removed Some()
};
// Note: These operations should either succeed (if steel_decimal handles them gracefully)
// or fail with appropriate error messages (if they're genuinely problematic)
let result = post_table_script(&pool, request).await;
// For now, we just ensure the validation doesn't crash
// The specific behavior (success vs failure) depends on steel_decimal implementation
match result {
@@ -393,7 +393,7 @@ async fn test_comparison_operations_with_valid_types() {
for operation in comparison_operations {
let script = format!(
r#"({} (steel_get_column "comparison_test" "value_a")
r#"({} (steel_get_column "comparison_test" "value_a")
(steel_get_column "comparison_test" "value_b"))"#,
operation
);
@@ -402,7 +402,7 @@ async fn test_comparison_operations_with_valid_types() {
table_definition_id: table_id,
target_column: "comparison_result".to_string(),
script,
description: Some(format!("Comparison operation: {}", operation)),
description: format!("Comparison operation: {}", operation), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;
@@ -431,12 +431,12 @@ async fn test_nested_mathematical_expressions() {
// Deeply nested expression: sqrt((x^2 + y^2) / z) + abs(x - y)
let nested_script = r#"
(+
(sqrt
(/
(sqrt
(/
(+ (pow (steel_get_column "nested_calc" "x") "2")
(pow (steel_get_column "nested_calc" "y") "2"))
(steel_get_column "nested_calc" "z")))
(abs
(abs
(- (steel_get_column "nested_calc" "x")
(steel_get_column "nested_calc" "y"))))
"#;
@@ -445,7 +445,7 @@ async fn test_nested_mathematical_expressions() {
table_definition_id: table_id,
target_column: "nested_result".to_string(),
script: nested_script.to_string(),
description: Some("Deeply nested mathematical expression".to_string()),
description: "Deeply nested mathematical expression".to_string(), // Fixed: removed Some()
};
let result = post_table_script(&pool, request).await;