all tests passed without any problem
This commit is contained in:
@@ -441,15 +441,13 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
|
||||
let script_request = PostTableScriptRequest {
|
||||
table_definition_id: table_def_id,
|
||||
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(),
|
||||
};
|
||||
post_table_script(&pool, script_request).await.unwrap();
|
||||
|
||||
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();
|
||||
update_data.insert("quantity".to_string(), ProtoValue {
|
||||
kind: Some(Kind::NumberValue(5.0)),
|
||||
@@ -462,16 +460,16 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
|
||||
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;
|
||||
assert!(result.is_err());
|
||||
let error = result.unwrap_err();
|
||||
assert_eq!(error.code(), tonic::Code::FailedPrecondition);
|
||||
assert!(error.message().contains("Script for column 'total' was triggered"));
|
||||
assert!(error.message().contains("from '10.00' to '50.00'"));
|
||||
let msg = error.message();
|
||||
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();
|
||||
failing_update_data.insert("quantity".to_string(), ProtoValue {
|
||||
kind: Some(Kind::NumberValue(3.0)),
|
||||
@@ -491,8 +489,9 @@ async fn test_put_partial_update_with_validation(pool: PgPool) {
|
||||
assert!(result.is_err());
|
||||
let error = result.unwrap_err();
|
||||
assert_eq!(error.code(), tonic::Code::InvalidArgument);
|
||||
assert!(error.message().contains("Script calculated '30.00'"));
|
||||
assert!(error.message().contains("but user provided '99.99'"));
|
||||
let msg = error.message();
|
||||
assert!(msg.contains("Script calculated '30.00'"));
|
||||
assert!(msg.contains("but user provided '99.99'"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
|
||||
Reference in New Issue
Block a user