Adding transaction tests

This commit is contained in:
Nicolas Dextraze
2016-03-18 14:04:07 -07:00
parent a64dbc9b8e
commit b2504749ce
12 changed files with 626 additions and 351 deletions

View File

@ -1,11 +1,21 @@
var util = require('util');
var Long = require('long');
function AccessDeniedError(action, stream) {
function AccessDeniedError(action, streamOrTransactionId) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = util.format("%s access denied for stream '%s'.", action, stream);
this.action = action;
this.stream = stream;
if (typeof streamOrTransactionId === 'string') {
this.message = util.format("%s access denied for stream '%s'.", action, streamOrTransactionId);
this.stream = streamOrTransactionId;
return;
}
if (Long.isLong(streamOrTransactionId)) {
this.message = util.format("%s access denied for transaction %s.", action, streamOrTransactionId);
this.transactionId = streamOrTransactionId;
return;
}
throw new TypeError("second argument must be a stream name or transaction Id.");
}
util.inherits(AccessDeniedError, Error);

View File

@ -1,10 +1,20 @@
var util = require('util');
var Long = require('long');
function StreamDeletedError(stream) {
function StreamDeletedError(streamOrTransactionId) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = util.format("Event stream '%s' is deleted.", stream);
this.stream = stream;
if (typeof streamOrTransactionId === 'string') {
this.message = util.format("Event stream '%s' is deleted.", streamOrTransactionId);
this.stream = streamOrTransactionId;
return;
}
if (Long.isLong(streamOrTransactionId)) {
this.message = util.format("Stream is deleted for transaction %s.", streamOrTransactionId);
this.transactionId = streamOrTransactionId;
return;
}
throw new TypeError("second argument must be a stream name or transaction Id.");
}
util.inherits(StreamDeletedError, Error);

View File

@ -1,12 +1,22 @@
var util = require('util');
var Long = require('long');
function WrongExpectedVersionError(action, stream, expectedVersion) {
function WrongExpectedVersionError(action, streamOrTransactionId, expectedVersion) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = util.format("%s failed due to WrongExpectedVersion. Stream: %s Expected version: %d.", action, stream, expectedVersion);
this.action = action;
this.stream = stream;
this.expectedVersion = expectedVersion;
if (typeof streamOrTransactionId === 'string') {
this.message = util.format("%s failed due to WrongExpectedVersion. Stream: %s Expected version: %d.", action, streamOrTransactionId, expectedVersion);
this.stream = streamOrTransactionId;
this.expectedVersion = expectedVersion;
return;
}
if (Long.isLong(streamOrTransactionId)) {
this.message = util.format("%s transaction failed due to WrongExpectedVersion. Transaction Id: %s.", action, streamOrTransactionId);
this.transactionId = streamOrTransactionId;
return;
}
throw new TypeError("second argument must be a stream name or a transaction Id.");
}
util.inherits(WrongExpectedVersionError, Error);