Adding tests
This commit is contained in:
@ -163,7 +163,7 @@ module.exports = {
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},*/
|
||||
},
|
||||
'Test Subscribe to Stream': function(test) {
|
||||
var done = false;
|
||||
function eventAppeared() {
|
||||
@ -188,7 +188,7 @@ module.exports = {
|
||||
done = true;
|
||||
test.done(err);
|
||||
})
|
||||
},
|
||||
}
|
||||
'Test Subscribe to All': function(test) {
|
||||
var done = false;
|
||||
function eventAppeared() {
|
||||
@ -233,11 +233,12 @@ module.exports = {
|
||||
self.conn.appendToStream(testStreamName, client.expectedVersion.any, events);
|
||||
}
|
||||
function subscriptionDropped(connection, reason, error) {
|
||||
console.log(reason);
|
||||
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
|
||||
test.ok(catchUpEvents.length >= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
|
||||
test.done(error);
|
||||
}
|
||||
//this.conn.appendToStream()
|
||||
this.conn.appendToStream(testStreamName, client.expectedVersion.noStream, )
|
||||
var subscription = this.conn.subscribeToStreamFrom(testStreamName, null, false, eventAppeared, liveProcessingStarted, subscriptionDropped);
|
||||
},
|
||||
'Test Subscribe to All From': function(test) {
|
||||
@ -264,55 +265,8 @@ module.exports = {
|
||||
test.done(error);
|
||||
}
|
||||
var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, userCredentialsForAll);
|
||||
},
|
||||
'Test Set Stream Metadata Raw': function(test) {
|
||||
this.conn.setStreamMetadataRaw(testStreamName, client.expectedVersion.emptyStream, {$maxCount: 100})
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},
|
||||
'Test Get Stream Metadata Raw': function(test) {
|
||||
this.conn.getStreamMetadataRaw(testStreamName)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},
|
||||
'Test Create Persistent Subscription': function(test) {
|
||||
var settings = client.PersistentSubscriptionSettings.create();
|
||||
this.conn.createPersistentSubscription(testStreamName, 'consumer-1', settings, userCredentialsForAll)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},
|
||||
//TODO: Update Persistent Subscription
|
||||
'Test ConnectTo Persistent Subscription': function(test) {
|
||||
function eventAppeared(s, e) {
|
||||
s.stop();
|
||||
}
|
||||
function subscriptionDropped(connection, reason, error) {
|
||||
test.done(error);
|
||||
}
|
||||
var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped);
|
||||
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]);
|
||||
},
|
||||
'Test Delete Persistent Subscription': function(test) {
|
||||
this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', userCredentialsForAll)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
}/*,
|
||||
},*/
|
||||
/*,
|
||||
'Test Delete Stream': function(test) {
|
||||
this.conn.deleteStream(testStreamName, client.expectedVersion.any)
|
||||
.then(function(result) {
|
||||
|
@ -17,6 +17,7 @@ var tcpEndPoint = {host: 'localhost', port: 1113};
|
||||
function setUp(cb) {
|
||||
this.log = settings.log;
|
||||
this.testStreamName = 'test-' + uuid.v4();
|
||||
this.log.info('A', this.testStreamName);
|
||||
var connected = false;
|
||||
this.conn = client.EventStoreConnection.create(settings, tcpEndPoint);
|
||||
this.conn.connect()
|
||||
|
@ -22,7 +22,7 @@ module.exports = {
|
||||
test.done();
|
||||
}
|
||||
},
|
||||
'Connect To Endpoint That Don\'t Exist': function(test) {
|
||||
'Connect To Endpoint That Doesn\'t Exist': function(test) {
|
||||
var tcpEndpoint = {hostname: 'localhost', port: 1114};
|
||||
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint);
|
||||
conn.connect()
|
||||
|
26
test/metadata_test.js
Normal file
26
test/metadata_test.js
Normal file
@ -0,0 +1,26 @@
|
||||
var util = require('util');
|
||||
var uuid = require('uuid');
|
||||
var client = require('../src/client');
|
||||
|
||||
module.exports = {
|
||||
'Test Set Stream Metadata Raw': function(test) {
|
||||
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.emptyStream, {$maxCount: 100})
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},
|
||||
'Test Get Stream Metadata Raw': function(test) {
|
||||
this.conn.getStreamMetadataRaw(this.testStreamName)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
46
test/persistentSubscription_test.js
Normal file
46
test/persistentSubscription_test.js
Normal file
@ -0,0 +1,46 @@
|
||||
var util = require('util');
|
||||
var uuid = require('uuid');
|
||||
var client = require('../src/client');
|
||||
const adminCredentials = new client.UserCredentials("admin", "changeit");
|
||||
|
||||
function createRandomEvent() {
|
||||
return client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, {createdAt: Date.now()}, 'testEvent');
|
||||
}
|
||||
|
||||
var testStreamName = 'test' + uuid.v4();
|
||||
|
||||
module.exports = {
|
||||
'Test Create Persistent Subscription': function(test) {
|
||||
var settings = client.PersistentSubscriptionSettings.create();
|
||||
this.conn.createPersistentSubscription(testStreamName, 'consumer-1', settings, adminCredentials)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
},
|
||||
//TODO: Update Persistent Subscription
|
||||
'Test ConnectTo Persistent Subscription': function(test) {
|
||||
function eventAppeared(s, e) {
|
||||
s.stop();
|
||||
}
|
||||
function subscriptionDropped(connection, reason, error) {
|
||||
test.done(error);
|
||||
}
|
||||
var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped);
|
||||
this.log.info('ABC', subscription);
|
||||
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]);
|
||||
},
|
||||
'Test Delete Persistent Subscription': function(test) {
|
||||
this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials)
|
||||
.then(function(result) {
|
||||
test.done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
test.done(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
38
test/subscribeToAllFrom_test.js
Normal file
38
test/subscribeToAllFrom_test.js
Normal file
@ -0,0 +1,38 @@
|
||||
var util = require('util');
|
||||
var uuid = require('uuid');
|
||||
var client = require('../src/client');
|
||||
const allCredentials = new client.UserCredentials("admin", "changeit");
|
||||
|
||||
function createRandomEvent() {
|
||||
return client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, {createdAt: Date.now()}, 'testEvent');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'Test Subscribe to All From': function(test) {
|
||||
var self = this;
|
||||
var liveProcessing = false;
|
||||
var catchUpEvents = [];
|
||||
var liveEvents = [];
|
||||
function eventAppeared(s, e) {
|
||||
if (liveProcessing) {
|
||||
liveEvents.push(e);
|
||||
s.stop();
|
||||
} else {
|
||||
catchUpEvents.push(e);
|
||||
}
|
||||
}
|
||||
function liveProcessingStarted() {
|
||||
liveProcessing = true;
|
||||
var events = [createRandomEvent()];
|
||||
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events);
|
||||
}
|
||||
function subscriptionDropped(connection, reason, error) {
|
||||
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
|
||||
test.ok(catchUpEvents.length > 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
|
||||
test.done(error);
|
||||
}
|
||||
var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, allCredentials);
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
44
test/subscribeToAll_test.js
Normal file
44
test/subscribeToAll_test.js
Normal file
@ -0,0 +1,44 @@
|
||||
const uuid = require('uuid');
|
||||
const client = require('../src/client');
|
||||
const allCredentials = new client.UserCredentials("admin", "changeit");
|
||||
|
||||
module.exports = {
|
||||
'Test Subscribe To All Happy Path': function(test) {
|
||||
const resolveLinkTos = false;
|
||||
const numberOfPublishedEvents = 5;
|
||||
var publishedEvents = [];
|
||||
for(var i=0;i<numberOfPublishedEvents;i++)
|
||||
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
|
||||
|
||||
function testAllPublishedEventsAppeared() {
|
||||
test.areEqual("receivedEvents.length", receivedEvents.length, numberOfPublishedEvents);
|
||||
}
|
||||
function testEventsAppearedInCorrectOrder() {
|
||||
for (var j = 0; j < numberOfPublishedEvents; j++)
|
||||
test.ok(receivedEvents[j].originalEvent.eventId === publishedEvents[j].eventId,
|
||||
"receivedEvents[" + j + "] != publishedEvents[" + j + "]");
|
||||
}
|
||||
|
||||
var receivedEvents = [];
|
||||
function eventAppeared(subscription, event) {
|
||||
receivedEvents.push(event);
|
||||
if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
|
||||
}
|
||||
function subscriptionDropped(subscription, reason, error) {
|
||||
if (error) return test.done(error);
|
||||
testAllPublishedEventsAppeared();
|
||||
testEventsAppearedInCorrectOrder();
|
||||
test.done();
|
||||
}
|
||||
var self = this;
|
||||
this.conn.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, allCredentials)
|
||||
.then(function(subscription) {
|
||||
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, true);
|
||||
|
||||
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
|
||||
})
|
||||
.catch(test.done)
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
47
test/subscribeToStreamFrom_test.js
Normal file
47
test/subscribeToStreamFrom_test.js
Normal file
@ -0,0 +1,47 @@
|
||||
var util = require('util');
|
||||
var uuid = require('uuid');
|
||||
var client = require('../src/client');
|
||||
|
||||
function createRandomEvent() {
|
||||
return client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, {createdAt: Date.now()}, 'testEvent');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'Test Subscribe to Stream From Happy Path': function(test) {
|
||||
var self = this;
|
||||
var liveProcessing = false;
|
||||
var catchUpEvents = [];
|
||||
var liveEvents = [];
|
||||
function eventAppeared(s, e) {
|
||||
if (liveProcessing) {
|
||||
liveEvents.push(e);
|
||||
s.stop();
|
||||
} else {
|
||||
catchUpEvents.push(e);
|
||||
}
|
||||
}
|
||||
function liveProcessingStarted() {
|
||||
liveProcessing = true;
|
||||
var events = [createRandomEvent()];
|
||||
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events);
|
||||
}
|
||||
function subscriptionDropped(connection, reason, error) {
|
||||
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
|
||||
test.ok(catchUpEvents.length >= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
|
||||
test.done(error);
|
||||
}
|
||||
|
||||
var events = [createRandomEvent()];
|
||||
this.conn.appendToStream(self.testStreamName, client.expectedVersion.noStream, events)
|
||||
.then(function() {
|
||||
var subscription = self.conn.subscribeToStreamFrom(self.testStreamName, null, false, eventAppeared, liveProcessingStarted, subscriptionDropped);
|
||||
|
||||
test.areEqual("subscription.streamId", subscription.streamId, self.testStreamName);
|
||||
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false);
|
||||
test.areEqual("subscription.readBatchSize", subscription.readBatchSize, 500);
|
||||
test.areEqual("subscription.maxPushQueueSize", subscription.maxPushQueueSize, 10000);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
45
test/subscribeToStream_test.js
Normal file
45
test/subscribeToStream_test.js
Normal file
@ -0,0 +1,45 @@
|
||||
const uuid = require('uuid');
|
||||
const client = require('../src/client');
|
||||
|
||||
module.exports = {
|
||||
'Test Subscribe To Stream Happy Path': function(test) {
|
||||
const resolveLinkTos = false;
|
||||
const numberOfPublishedEvents = 5;
|
||||
var publishedEvents = [];
|
||||
for(var i=0;i<numberOfPublishedEvents;i++)
|
||||
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
|
||||
|
||||
function testAllPublishedEventsAppeared() {
|
||||
test.areEqual("receivedEvents.length", receivedEvents.length, numberOfPublishedEvents);
|
||||
}
|
||||
function testEventsAppearedInCorrectOrder() {
|
||||
for (var j = 0; j < numberOfPublishedEvents; j++)
|
||||
test.ok(receivedEvents[j].originalEvent.eventId === publishedEvents[j].eventId,
|
||||
"receivedEvents[" + j + "] != publishedEvents[" + j + "]");
|
||||
}
|
||||
|
||||
var receivedEvents = [];
|
||||
function eventAppeared(subscription, event) {
|
||||
receivedEvents.push(event);
|
||||
if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
|
||||
}
|
||||
function subscriptionDropped(subscription, reason, error) {
|
||||
if (error) return test.done(error);
|
||||
testAllPublishedEventsAppeared();
|
||||
testEventsAppearedInCorrectOrder();
|
||||
test.done();
|
||||
}
|
||||
var self = this;
|
||||
this.conn.subscribeToStream(this.testStreamName, resolveLinkTos, eventAppeared, subscriptionDropped)
|
||||
.then(function(subscription) {
|
||||
test.areEqual("subscription.streamId", subscription.streamId, self.testStreamName);
|
||||
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false);
|
||||
test.areEqual("subscription.lastEventNumber", subscription.lastEventNumber, client.expectedVersion.emptyStream);
|
||||
|
||||
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
|
||||
})
|
||||
.catch(test.done)
|
||||
}
|
||||
};
|
||||
|
||||
require('./common/base_test').init(module.exports);
|
Reference in New Issue
Block a user