diff --git a/src/results.js b/src/results.js index 70c806d..92442ac 100644 --- a/src/results.js +++ b/src/results.js @@ -49,6 +49,7 @@ const EventReadStatus = Object.freeze({ * @property {string} eventId * @property {Long} eventNumber * @property {string} eventType + * @property {Date} created * @property {number} createdEpoch * @property {?Buffer} data * @property {?Buffer} metadata @@ -61,8 +62,8 @@ function RecordedEvent(ev) { this.eventType = ev.eventType; this.created = new Date(ev.createdEpoch ? ev.createdEpoch.toNumber() : 0); this.createdEpoch = ev.createdEpoch ? ev.createdEpoch.toNumber() : 0; - this.data = ev.data ? ev.data : new Buffer(0); - this.metadata = ev.metadata ? ev.metadata : new Buffer(0); + this.data = ev.data ? ev.data : Buffer.alloc(0); + this.metadata = ev.metadata ? ev.metadata : Buffer.alloc(0); this.isJson = ev.dataContentType === 1; Object.freeze(this); } @@ -268,4 +269,4 @@ exports.PersistentSubscriptionCreateStatus = PersistentSubscriptionCreateStatus; exports.PersistentSubscriptionUpdateResult = PersistentSubscriptionUpdateResult; exports.PersistentSubscriptionUpdateStatus = PersistentSubscriptionUpdateStatus; exports.PersistentSubscriptionDeleteResult = PersistentSubscriptionDeleteResult; -exports.PersistentSubscriptionDeleteStatus = PersistentSubscriptionDeleteStatus; \ No newline at end of file +exports.PersistentSubscriptionDeleteStatus = PersistentSubscriptionDeleteStatus; diff --git a/test/common/base_test.js b/test/common/base_test.js index 9586b20..8de1ce0 100644 --- a/test/common/base_test.js +++ b/test/common/base_test.js @@ -1,5 +1,6 @@ var util = require('util'); var uuid = require('uuid'); +var Long = require('long'); var client = require('../../lib/dist'); var FileLogger = require('../../src/common/log/fileLogger'); var NoopLogger = require('../../src/common/log/noopLogger'); @@ -71,17 +72,23 @@ function eventEqualEventData(name, resolvedEvent, eventData) { this.ok(Buffer.compare(ev.metadata, eventData.metadata) === 0, name + ".originalEvent.metadata is not equal to original metadata."); } +function testRecordedEvent(name, event) { + this.ok(Long.isLong(event.eventNumber), name + ".eventNumber is not a Long"); + this.ok(event.created instanceof Date, name + ".created is not a Date"); + this.ok(typeof event.createdEpoch === 'number', name + ".createdEpoch is not a number"); +} + function testLiveEvent(name, event, evNumber) { this.ok(event.event, name + ".event not defined (or null)"); this.ok(event.originalEvent, name + ".originalEvent not defined (or null)"); this.ok(event.isResolved === false, name + ".isResolved should be true"); this.ok(event.originalPosition instanceof client.Position, name + ".originalPosition is not an instance of Position"); this.ok(event.originalStreamId, name + ".originalStreamId not defined (or null)"); + this.ok(Long.isLong(event.originalEventNumber), name + ".originalEventNumber is not a Long"); if (typeof evNumber === 'number') { this.ok(event.originalEventNumber.toNumber() === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber); - } else { - this.ok(typeof event.originalEventNumber === 'number', name + ".originalEventNumber is not a number"); } + testRecordedEvent.call(this, name + '.event', event.event); } function testReadEvent(name, event, evNumber) { @@ -90,11 +97,11 @@ function testReadEvent(name, event, evNumber) { this.ok(event.isResolved === false, name + ".isResolved should be true"); this.ok(event.originalPosition === null, name + ".originalPosition is not null"); this.ok(event.originalStreamId, name + ".originalStreamId not defined (or null)"); + this.ok(Long.isLong(event.originalEventNumber), name + ".originalEventNumber is not a Long"); if (typeof evNumber === 'number') { this.ok(event.originalEventNumber.toNumber() === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber); - } else { - this.ok(typeof event.originalEventNumber === 'number', name + ".originalEventNumber is not a number"); } + testRecordedEvent.call(this, name + '.event', event.event); } var _ = { diff --git a/test/readStreamEventsForward_test.js b/test/readStreamEventsForward_test.js index 9ca0b8c..c989256 100644 --- a/test/readStreamEventsForward_test.js +++ b/test/readStreamEventsForward_test.js @@ -18,7 +18,7 @@ module.exports = { .catch(cb); }, 'Read Stream Events Forward Happy Path': function(test) { - test.expect(7 + (streamSize * 11)); + test.expect(7 + (streamSize * 15)); var self = this; this.conn.readStreamEventsForward(this.testStreamName, Long.fromNumber(0), streamSize) .then(function(slice) { diff --git a/test/subscribeToStreamFrom_test.js b/test/subscribeToStreamFrom_test.js index b6ae456..a79c4ca 100644 --- a/test/subscribeToStreamFrom_test.js +++ b/test/subscribeToStreamFrom_test.js @@ -22,7 +22,7 @@ function delayOnlyFirst(count, action) { module.exports = { 'Test Subscribe to Stream From Beginning (null)': function(test) { - test.expect(32); + test.expect(48); var self = this; var liveProcessing = false; var catchUpEvents = []; @@ -78,7 +78,7 @@ module.exports = { .catch(test.done); }, 'Test Subscribe to Stream From 0': function(test) { - test.expect(26); + test.expect(38); var self = this; var liveProcessing = false; var catchUpEvents = [];