var gRex = require('../../index.js'),
    Transaction = require("../../src/transaction/transaction");

var g, updatedEdge;

before(function(done){
    gRex.connect()
        .then(function(result) {
            g = result;
            done();
        })
        .fail(function(error) {
            console.error(error);
        });
});


describe('Transaction', function() {
    describe('when adding a Vertex', function() {
        var addedVertex;
        var alice, bob;

        it('should add a vertex in the graph database', function(done) {
            var tx = g.begin();

            alice = tx.addVertex({name: "Alice"});

            tx.commit()
            .then(function(result) {
                done();
            });
        });

        it('should add a vertex and an edge in a transaction', function(done) {
            var tx = g.begin();

            bob = tx.addVertex({name: 'Bob'});
            tx.addEdge(5543345, alice, bob, 'likes', {since: 'now'});

            tx.commit()
            .then(function(result) {
                done();
            });

        });
    });

    describe('when updating a vertex', function() {
        before(function(done) {
            g.V('name', 'Alice')
            .then(function(result) {
                alice = result.results[0];
                done();
            });
        });

        it('should update a property', function(done) {
            var tx = g.begin();

            tx.updateVertex(alice._id, {name: 'Jess'});

            tx.commit()
            .then(function(result) {
                result.should.have.property('txProcessed', 1);
                result.should.have.property('success', true);
                done();
            })
            .fail(function(error) {
                console.error(error);
                done();
            });
        });
    });


    // Currently bugged?
    // @see https://groups.google.com/forum/#!topic/gremlin-users/i0Uci2yZoaQ
    describe.skip('when updating an edge', function() {
        before(function(done) {
            g.V('name', 'Jess').outE('likes')
            .then(function(result) {
                updatedEdge = result.results[0];
                done();
            })
            .fail(function(error) {
                console.error(error);
                done();
            });
        });

        it('should update a property', function(done) {
            tx = g.begin();
            tx.updateEdge(updatedEdge._id, {since: 'forever', foo: 'bar'});

            tx.commit()
            .then(function(result) {
                // console.log(result);
                done();
            })
            .fail(function(error) {
                console.error(error);
                done();
            });
        });
    });


    describe('when deleting two vertices', function() {
        before(function(done) {
            g.V('name', 'Jess')
            .then(function(result) {
                alice = result.results[0];
                done();
            });
        });

        before(function(done) {
            g.V('name', 'Bob')
            .then(function(result) {
                bob = result.results[0];
                done();
            });
        });


        it('should delete vertices in a transaction', function(done) {
            var tx = g.begin();

            tx.removeVertex(alice);
            tx.removeVertex(bob);

            tx.commit()
            .then(function(result) {
                done();
            });
        });
    });
});

@@ -331,16 +331,51 @@
 ;%0A%7D);%0A%0A%0A
+var alice, bob;%0Avar james, waldo;%0A%0A
 describe
@@ -433,16 +433,29 @@
 ing 
-a Vertex
+elements to the graph
 ', f
@@ -470,58 +470,8 @@
 ) %7B%0A
-        var addedVertex;%0A        var alice, bob;%0A%0A
     
@@ -505,26 +505,21 @@
  in 
-the graph database
+a transaction
 ', f
@@ -672,32 +672,94 @@
 ction(result) %7B%0A
+                result.should.have.property('success', true);%0A
                 
@@ -982,15 +982,10 @@
 dge(
-5543345
+20
 , al
@@ -1090,32 +1090,852 @@
                 
+result.should.have.property('txProcessed', 1);%0A                result.should.have.property('success', true);%0A                done();%0A            %7D);%0A%0A        %7D);%0A%0A        it('should add 2 vertices in a transaction', function(done) %7B%0A            var tx = g.begin();%0A%0A            james = tx.addVertex(%7Bname: 'James'%7D);%0A            waldo = tx.addVertex(%7Bname: 'Waldo'%7D);%0A%0A            tx.commit()%0A            .then(function(result) %7B%0A                result.should.have.property('success', true);%0A                done();%0A            %7D);%0A        %7D);%0A%0A        // Clean up: remove james and waldo from the database%0A        after(function(done) %7B%0A            var tx = g.begin()%0A            tx.removeVertex(james._id);%0A            tx.removeVertex(waldo._id);%0A%0A            tx.commit()%0A            .then(function()%7B%0A                
 done();%0A        
@@ -1933,33 +1933,32 @@
 %0A            %7D);
-%0A
 %0A        %7D);%0A   
@@ -2715,25 +2715,24 @@
 );%0A    %7D);%0A%0A
-%0A
     // Curre
@@ -2838,13 +2838,8 @@
 ribe
-.skip
 ('wh
@@ -3429,48 +3429,8 @@
 ) %7B%0A
-                // console.log(result);%0A
     

Add test: adding 2 vertices in a transaction (entrendipity/grex#19)