Added some more tests around RecordedEvent properties type

This commit is contained in:
Nicolas Dextraze 2019-11-01 12:57:54 -07:00
parent 67dab18d53
commit 6ad2d34114
4 changed files with 18 additions and 10 deletions

View File

@ -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);
}

View File

@ -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 _ = {

View File

@ -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) {

View File

@ -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 = [];