var should = require('should');

var grex = require('../');
var client = grex.createClient();
var bind = grex.bindParameter;
var g = grex.g;
var gremlin = grex.gremlin;


describe('Transactions', function() {
  it('should add a vertex to the graph', function(done) {
    var query = gremlin(g.addVertex({ name: "Alice" }));

    client.execute(query, function(err, result) {
      should.not.exist(err);
      result.should.have.property('success', true);
      done();
    });
  });

  it('should add a vertex with bound properties to the graph', function(done) {
    var query = gremlin(g.addVertex(bind({ name: "Eve" })));

    query.script.should.equal('g.addVertex(p0)\n');
    query.params.p0.name.should.equal('Eve');

    client.execute(query, function(err, result) {
      should.not.exist(err);
      result.should.have.property('success', true);
      done();
    });
  });

  it('should add two vertices and an edge in a transaction', function(done) {
    var query = gremlin();
    var bob = query.var(g.addVertex({ name: 'Bob' }));
    var waldo = query.var(g.addVertex({ name: 'Waldo' }));

    query(g.addEdge(bob, waldo, 'likes', { since: 'now' }));

    query.script.split('\n').length.should.equal(4);
    client.execute(query, function(err, result) {
      should.not.exist(err);
      result.should.have.property('success', true);
      done();
    });
  });

  it('should add two vertices and an edge with bound properties', function(done) {
    var query = gremlin();
    var john = query.var(g.addVertex(bind({ name: 'John' })));
    var carol = query.var(g.addVertex(bind({ name: 'Carol' })));
    query(g.addEdge(john, carol, 'knows', bind({ since: 'now' })));

    query.script.split('\n').length.should.equal(4);
    client.execute(query, function(err, result) {
      should.not.exist(err);
      result.should.have.property('success', true);
      done();
    });
  });
});

@@ -164,16 +164,375 @@
 mlin;%0A%0A%0A
+function cleanGraph(done) %7B%0A  var query = gremlin();%0A  query(g.V('name', 'Alice').remove());%0A  query(g.V('name', 'Bob').remove());%0A  query(g.V('name', 'Carol').remove());%0A  query(g.V('name', 'Eve').remove());%0A  query(g.V('name', 'John').remove());%0A  query(g.V('name', 'Waldo').remove());%0A%0A  client.execute(query, function(err, results) %7B%0A    done();%0A  %7D);%0A%7D%0A%0A
 describe
@@ -561,16 +561,42 @@
 ion() %7B%0A
+  afterEach(cleanGraph);%0A%0A
   it('sh

Clean graph after each transaction tests