Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fromCategories helper #1326

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,62 @@ public void source_definition_is_correct()
}
}

[TestFixture]
public class with_multiple_from_categories : TestFixtureWithJsProjection
{
protected override void Given()
{
_projection = @"
fromCategories(['category1', 'category2', 'category3']).when({
$any: function(state, event) {
return state;
}});
";
_state = @"{""count"": 0}";
}

[Test, Category("v8")]
public void source_definition_is_correct()
{
Assert.AreEqual(false, _source.AllStreams);
Assert.IsNotNull(_source.Streams);
Assert.AreEqual(3, _source.Streams.Length);
Assert.AreEqual("$ce-category1", _source.Streams[0]);
Assert.AreEqual("$ce-category2", _source.Streams[1]);
Assert.AreEqual("$ce-category3", _source.Streams[2]);
Assert.That(_source.Categories == null || _source.Categories.Length == 0);
Assert.AreEqual(false, _source.ByStreams);
}
}

[TestFixture]
public class with_multiple_from_categories_plain : TestFixtureWithJsProjection
{
protected override void Given()
{
_projection = @"
fromCategories('category1', 'category2', 'category3').when({
$any:function(state, event) {
return state;
}});
";
_state = @"{""count"": 0}";
}

[Test, Category("v8")]
public void source_definition_is_correct()
{
Assert.AreEqual(false, _source.AllStreams);
Assert.IsNotNull(_source.Streams);
Assert.AreEqual(3, _source.Streams.Length);
Assert.AreEqual("$ce-category1", _source.Streams[0]);
Assert.AreEqual("$ce-category2", _source.Streams[1]);
Assert.AreEqual("$ce-category3", _source.Streams[2]);
Assert.That(_source.Categories == null || _source.Categories.Length == 0);
Assert.AreEqual(false, _source.ByStreams);
}
}

[TestFixture]
public class with_from_category : TestFixtureWithJsProjection
{
Expand Down
9 changes: 9 additions & 0 deletions src/EventStore.Projections.Core/Prelude/1Prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ function scope($on, $notify) {
};
}

function fromCategories(categories) {
var arr = Array.isArray(categories) ? categories : Array.prototype.slice.call(arguments);
arr = arr.map(function (x) {
return '$ce-' + x;
});
return fromStreams(arr);
}

function emit(streamId, eventName, eventBody, metadata) {
var message = { streamId: streamId, eventName: eventName , body: JSON.stringify(eventBody), metadata: metadata, isJson: true };
eventProcessor.emit(message);
Expand Down Expand Up @@ -257,6 +265,7 @@ function scope($on, $notify) {
fromCategory: fromCategory,
fromStream: fromStream,
fromStreams: fromStreams,
fromCategories: fromCategories,
fromStreamCatalog: fromStreamCatalog,
fromStreamsMatching: fromStreamsMatching,

Expand Down