From 41cc5846bfc6aea1e295d3c907154f0bfe1bb88d Mon Sep 17 00:00:00 2001 From: Ben Simpson Date: Thu, 15 Sep 2022 14:56:25 -0400 Subject: [PATCH] Add test case for transactional rollback --- spec/neo4j/http/cypher_client_spec.rb | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/spec/neo4j/http/cypher_client_spec.rb b/spec/neo4j/http/cypher_client_spec.rb index 6da862b..d4188ae 100644 --- a/spec/neo4j/http/cypher_client_spec.rb +++ b/spec/neo4j/http/cypher_client_spec.rb @@ -102,11 +102,11 @@ }, { statement: statement3, - parameters: { name: "Baz" } + parameters: {name: "Baz"} }, { statement: statement4, - parameters: { name: "Qux" } + parameters: {name: "Qux"} } ]) @@ -115,6 +115,35 @@ expect(results[2][0]["node"]["name"]).to eq("Baz") expect(results[3][0]["node"]["name"]).to eq("Qux") end + + it "handles error and rolls back" do + good_statement = "MERGE (node:Test {uuid: 'Uuid1', name: 'Foo'}) return node" + bad_statement = "MERGE (node:Test {uuid: 'Uuid2', name: 'Bar'}) BAD SYNTAX" + good_statement2 = "MERGE (node:Test {uuid: 'Uuid3', name: 'Baz'}) return node" + + expect { + client.execute_batch_cypher([ + { + statement: good_statement, + parameters: {} + }, + { + statement: bad_statement, + parameters: {} + }, + { + statement: good_statement2, + parameters: {} + } + ]) + }.to raise_error Neo4j::Http::Errors::Neo::ClientError::Statement::SyntaxError + + results = client.execute_cypher("MATCH (node:Test { uuid: 'Uuid1' }) return node") + expect(results).to be_empty + + results = client.execute_cypher("MATCH (node:Test { uuid: 'Uuid3' }) return node") + expect(results).to be_empty + end end end end