<commit_before>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();
            });<commit_msg>Add test: adding 2 vertices in a transaction (entrendipity/grex#19)<commit_after>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);
        });
});


var alice, bob;
var james, waldo;

describe('Transaction', function() {
    describe('when adding elements to the graph', function() {
        it('should add a vertex in a transaction', function(done) {
            var tx = g.begin();

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

            tx.commit()
            .then(function(result) {
                result.should.have.property('success', true);
                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(20, alice, bob, 'likes', {since: 'now'});

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

        });

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

            james = tx.addVertex({name: 'James'});
            waldo = tx.addVertex({name: 'Waldo'});

            tx.commit()
            .then(function(result) {
                result.should.have.property('success', true);
                done();
            });
        });

        // Clean up: remove james and waldo from the database
        after(function(done) {
            var tx = g.begin()
            tx.removeVertex(james._id);
            tx.removeVertex(waldo._id);

            tx.commit()
            .then(function(){
                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('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) {
                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();
            });
{'fraction_non_alphanumeric': 0.15221441880464384, 'fraction_numerical': 0.003726530027232335, 'mean_word_length': 1.4028925619834711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5887658', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1836, 'n_words': 365}