<commit_before>var client = require('../../../')
	, ges = require('ges-test-helper')
	, uuid = require('node-uuid')
	, createTestEvent = require('../../createTestEvent')
	, range = require('../../range')
	, streamWriter = require('../../streamWriter')
	, eventStreamCounter = require('../../eventStreamCounter')
	, should = require('../../shouldExtensions')


describe('when_committing_empty_transaction', function() {
	var es
		, connection

	before(function(done) {
		ges({ tcpPort: 5024 }, function(err, memory) {
			if(err) return done(err)

			es = memory
			connection = client({ port: 5024 }, done)
		})
	})

  it('following_append_with_correct_expected_version_are_commited_correctly')
  it('following_append_with_expected_version_any_are_commited_correctly')
  it('committing_first_event_with_expected_version_no_stream_is_idempotent')
  it('trying_to_append_new_events_with_expected_version_no_stream_fails')

  after(function(done) {
  	connection.close(function() {
	  	es.on('exit', function(code, signal) {
		  	done()
	  	})
	  	es.on('error', done)
	  	es.kill()
  	})
  })
})<commit_msg>Committing empty transaction tests now migrated<commit_after>var client = require('../../../')
	, ges = require('ges-test-helper')
	, uuid = require('node-uuid')
	, createTestEvent = require('../../createTestEvent')
	, range = require('../../range')
	, streamWriter = require('../../streamWriter')
	, eventStreamCounter = require('../../eventStreamCounter')
	, should = require('../../shouldExtensions')
	, port = 8200


describe('when_committing_empty_transaction', function() {
	var es
		, connection
		, firstEvent = createTestEvent()
		, stream = 'test-stream'

	beforeEach(function(done) {
		ges({ tcpPort: port }, function(err, memory) {
			if(err) return done(err)

			es = memory
			client({ port: port }, function(err, con) {
				if(err) return done(err)
				connection = con
				var appendOptions = {
							expectedVersion: client.expectedVersion.noStream
						, events: [ firstEvent, createTestEvent(), createTestEvent() ]
						}

				connection.appendToStream(stream, appendOptions, function(err, appendResult) {
					if(err) return done(err)

					appendResult.NextExpectedVersion.should.equal(2)
					var transactionOptions = {
								expectedVersion: 2
							}

					connection.startTransaction(stream, transactionOptions, function(err, transaction) {
						transaction.commit(function(err, commitResult) {
							if(err) return done(err)

							commitResult.NextExpectedVersion.should.equal(2)
							done()
						})
					})
				})
			})
		})
	})

  it('following_append_with_correct_expected_version_are_commited_correctly', function(done) {
  	var appendOptions = {
  				expectedVersion: 2
  			, events: [ createTestEvent(), createTestEvent() ]
		  	}
  	connection.appendToStream(stream, appendOptions, function(err, appendResult) {
  		if(err) return done(err)

  		appendResult.NextExpectedVersion.should.equal(4)
  		var readOptions = {
		  			start: 0
		  		, count: 100
		  		}

  		connection.readStreamEventsForward(stream, readOptions, function(err, readResult) {
  			if(err) return done(err)

  			readResult.Status.should.equal('Success')
  			readResult.Events.length.should.equal(5)
  			for(var i = 0; i < 5; i += 1) {
  				readResult.Events[i].OriginalEventNumber.should.equal(i)
  			}
  			done()
  		})
  	})
  })

  it('following_append_with_expected_version_any_are_commited_correctly', function(done) {
  	var appendOptions = {
  				expectedVersion: client.expectedVersion.any
  			, events: [ createTestEvent(), createTestEvent() ]
		  	}
  	connection.appendToStream(stream, appendOptions, function(err, appendResult) {
  		if(err) return done(err)

  		appendResult.NextExpectedVersion.should.equal(4)
  		var readOptions = {
		  			start: 0
		  		, count: 100
		  		}

  		connection.readStreamEventsForward(stream, readOptions, function(err, readResult) {
  			if(err) return done(err)

  			readResult.Status.should.equal('Success')
  			readResult.Events.length.should.equal(5)
  			for(var i = 0; i < 5; i += 1) {
  				readResult.Events[i].OriginalEventNumber.should.equal(i)
  			}
  			done()
  		})
  	})
  })

  it('committing_first_event_with_expected_version_no_stream_is_idempotent', function(done) {
  	var appendOptions = {
  				expectedVersion: client.expectedVersion.noStream
  			, events: firstEvent
		  	}
  	connection.appendToStream(stream, appendOptions, function(err, appendResult) {
  		if(err) return done(err)

  		appendResult.NextExpectedVersion.should.equal(0)
  		var readOptions = {
		  			start: 0
		  		, count: 100
		  		}

  		connection.readStreamEventsForward(stream, readOptions, function(err, readResult) {
  			if(err) return done(err)

  			readResult.Status.should.equal('Success')
  			readResult.Events.length.should.equal(3)
  			for(var i = 0; i < 3; i += 1) {
  				readResult.Events[i].OriginalEventNumber.should.equal(i)
  			}
  			done()
  		})
  	})
  })

  it('trying_to_append_new_events_with_expected_version_no_stream_fails', function(done) {
  	var appendOptions = {
  				expectedVersion: client.expectedVersion.noStream
  			, events: createTestEvent()
		  	}
  	connection.appendToStream(stream, appendOptions, function(err, appendResult) {
  		should.not.be.null(err)
  		err.message.should.equal('Wrong expected version.')
			done()
  	})
  })

  afterEach(function(done) {
  	connection.close(function() {
	  	es.on('exit', function(code, signal) {
	  		port += 1
		  	done()
	  	})
	  	es.on('error', done)
	  	es.kill()
  	})
  })
})
{'fraction_non_alphanumeric': 0.13694439445744105, 'fraction_numerical': 0.007917941335252834, 'mean_word_length': 3.5077047850770477, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5520286', 'n_tokens_mistral': 2098, 'n_tokens_neox': 1836, 'n_words': 286}