all tests passed without any problem

This commit is contained in:
Priec
2025-09-21 20:50:14 +02:00
parent 49277cfdd4
commit 7e21258d2e

View File

@@ -441,15 +441,13 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
let script_request = PostTableScriptRequest { let script_request = PostTableScriptRequest {
table_definition_id: table_def_id, table_definition_id: table_def_id,
target_column: "total".to_string(), target_column: "total".to_string(),
script: "(* $price $quantity)".to_string(), script: r#"( * (get-var "price") (get-var "quantity") )"#.to_string(),
description: "Total = Price × Quantity".to_string(), description: "Total = Price × Quantity".to_string(),
}; };
post_table_script(&pool, script_request).await.unwrap(); post_table_script(&pool, script_request).await.unwrap();
let record_id = create_initial_record(&pool, "test_put_partial", "invoice", &indexer_tx).await; let record_id = create_initial_record(&pool, "test_put_partial", "invoice", &indexer_tx).await;
// Partial update: only update quantity. The script detects this would change total
// from 10.00 to 50.00 and requires the user to include 'total' in the update.
let mut update_data = HashMap::new(); let mut update_data = HashMap::new();
update_data.insert("quantity".to_string(), ProtoValue { update_data.insert("quantity".to_string(), ProtoValue {
kind: Some(Kind::NumberValue(5.0)), kind: Some(Kind::NumberValue(5.0)),
@@ -462,16 +460,16 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
data: update_data, data: update_data,
}; };
// This should fail because script would change total value // This should fail because script would change total value (Case B: implicit change detection)
let result = put_table_data(&pool, put_request, &indexer_tx).await; let result = put_table_data(&pool, put_request, &indexer_tx).await;
assert!(result.is_err()); assert!(result.is_err());
let error = result.unwrap_err(); let error = result.unwrap_err();
assert_eq!(error.code(), tonic::Code::FailedPrecondition); assert_eq!(error.code(), tonic::Code::FailedPrecondition);
assert!(error.message().contains("Script for column 'total' was triggered")); let msg = error.message();
assert!(error.message().contains("from '10.00' to '50.00'")); assert!(msg.contains("Script for column 'total' was triggered"));
assert!(msg.contains("from '10.00' to '50.00'"));
assert!(msg.contains("include 'total' in your update request")); // Full change detection msg
// Now, test a partial update that SHOULD fail validation.
// We update quantity and provide an incorrect total.
let mut failing_update_data = HashMap::new(); let mut failing_update_data = HashMap::new();
failing_update_data.insert("quantity".to_string(), ProtoValue { failing_update_data.insert("quantity".to_string(), ProtoValue {
kind: Some(Kind::NumberValue(3.0)), kind: Some(Kind::NumberValue(3.0)),
@@ -491,8 +489,9 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
assert!(result.is_err()); assert!(result.is_err());
let error = result.unwrap_err(); let error = result.unwrap_err();
assert_eq!(error.code(), tonic::Code::InvalidArgument); assert_eq!(error.code(), tonic::Code::InvalidArgument);
assert!(error.message().contains("Script calculated '30.00'")); let msg = error.message();
assert!(error.message().contains("but user provided '99.99'")); assert!(msg.contains("Script calculated '30.00'"));
assert!(msg.contains("but user provided '99.99'"));
} }
#[sqlx::test] #[sqlx::test]