#[path = "testutils/mod.rs"]
mod testutils;
use graphlite::Value;
use testutils::test_fixture::TestFixture;
#[test]
fn test_rollback_undoes_batch_set_operations() {
let fixture = TestFixture::new().expect("Failed to create fixture");
fixture
.setup_graph("rollback_batch_test")
.expect("Failed to setup graph");
fixture
.query("INSERT (:Person {name: 'Charlie', age: 28, city: 'LA', status: 'active'})")
.expect("Failed to create person");
fixture
.query("START TRANSACTION")
.expect("Failed to start transaction");
fixture.query(
"MATCH (p:Person {name: 'Charlie'}) SET p.age = 29, p.city = 'SF', p.status = 'inactive'"
).expect("SET should succeed in transaction");
let mid_result = fixture.query(
"MATCH (p:Person {name: 'Charlie'}) RETURN p.age as age, p.city as city, p.status as status"
).expect("Query should succeed");
let mid_row = &mid_result.rows[0].values;
assert_eq!(
mid_row.get("age"),
Some(&Value::Number(29.0)),
"Age should be 29"
);
assert_eq!(
mid_row.get("city"),
Some(&Value::String("SF".to_string())),
"City should be SF"
);
assert_eq!(
mid_row.get("status"),
Some(&Value::String("inactive".to_string())),
"Status should be inactive"
);
fixture.query("ROLLBACK").expect("ROLLBACK should succeed");
let final_result = fixture.query(
"MATCH (p:Person {name: 'Charlie'}) RETURN p.age as age, p.city as city, p.status as status"
).expect("Query should succeed");
let final_row = &final_result.rows[0].values;
assert_eq!(
final_row.get("age"),
Some(&Value::Number(28.0)),
"Age should be rolled back to 28"
);
assert_eq!(
final_row.get("city"),
Some(&Value::String("LA".to_string())),
"City should be rolled back to LA"
);
assert_eq!(
final_row.get("status"),
Some(&Value::String("active".to_string())),
"Status should be rolled back to active"
);
}