Skip to content

Commit a191e93

Browse files
Added new projection
1 parent 7d126e6 commit a191e93

8 files changed

Lines changed: 154 additions & 6 deletions

EventStoreProjections/EventStoreProjections.Tests.njsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Content Include="tests\EstateAggregatorTests.js" />
4444
<Content Include="tests\EstateManagementSubscriptionStreamBuilderTests.js" />
4545
<Content Include="tests\FileProcessorSubscriptionStreamBuilderTests.js" />
46+
<Content Include="tests\MerchantBalanceAggregatorTests.js" />
4647
<Content Include="tests\MerchantAggregatorTests.js" />
4748
<Content Include="tests\TestData.js" />
4849
<Content Include="tests\TransactionProcessorSubscriptionStreamBuilderTests.js" />
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
require('../../NugetPackage/projections/continuous/MerchantBalanceAggregator.js');
2+
var projection = require('@transactionprocessing/esprojection-testing-framework');
3+
var testData = require('./TestData.js');
4+
var describe = require('tape-describe');
5+
var test = describe('Merchant Balance Aggregator Tests');
6+
7+
test('Projection Can Handle Merchant Events',
8+
t =>
9+
{
10+
projection.initialize();
11+
12+
var estateId = '3bf2dab2-86d6-44e3-bcf8-51bec65cf8bc';
13+
var merchantId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
14+
var merchantName = 'Test Merchant 1';
15+
16+
// Set up the merchant events
17+
var merchantCreatedEvent = testData.getMerchantCreatedEvent(estateId, merchantId, merchantName);
18+
19+
var depositDateTime = '2020-05-30T06:21:31.356Z';
20+
var depositAmount = 1000.00;
21+
var manualDepositMadeEvent =
22+
testData.getManualDepositMadeEvent(estateId, merchantId, depositDateTime, depositAmount);
23+
24+
var automaticDepositMadeEvent =
25+
testData.getAutomaticDepositMadeEvent(estateId, merchantId, depositDateTime, depositAmount);
26+
27+
projection.processEvent(
28+
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
29+
merchantCreatedEvent.eventType,
30+
merchantCreatedEvent.data);
31+
32+
projection.processEvent(
33+
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
34+
manualDepositMadeEvent.eventType,
35+
manualDepositMadeEvent.data);
36+
37+
projection.processEvent(
38+
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
39+
automaticDepositMadeEvent.eventType,
40+
automaticDepositMadeEvent.data);
41+
42+
var events = projection.emittedEvents;
43+
t.equal(events.length, 3);
44+
t.end();
45+
});
46+
47+
test('Projection Can Handle Transaction Events',
48+
t =>
49+
{
50+
projection.initialize();
51+
52+
var estateId = '3bf2dab2-86d6-44e3-bcf8-51bec65cf8bc';
53+
var merchantId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
54+
var transactionId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
55+
var transactionAmount = 100.00;
56+
var transactionType = 'Sale';
57+
58+
var transactionHasStartedEvent = testData.getTransactionHasStartedEvent(estateId,
59+
merchantId,
60+
transactionId,
61+
transactionAmount,
62+
transactionType);
63+
64+
var transactionHasBeenCompletedEvent =
65+
testData.getTransactionHasBeenCompletedEvent(estateId, merchantId, transactionId, true);
66+
67+
var calculatedValue = 5.00;
68+
var eventCreatedDateTime = "2020-05-16T07:47:51.6617562+00:00";
69+
var merchantFeeAddedToTransactionEvent = testData.getMerchantFeeAddedToTransactionEvent(estateId,
70+
merchantId,
71+
transactionId,
72+
calculatedValue,
73+
eventCreatedDateTime);
74+
75+
projection.processEvent(
76+
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
77+
transactionHasStartedEvent.eventType,
78+
transactionHasStartedEvent.data);
79+
80+
projection.processEvent(
81+
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
82+
transactionHasBeenCompletedEvent.eventType,
83+
transactionHasBeenCompletedEvent.data);
84+
85+
projection.processEvent(
86+
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
87+
merchantFeeAddedToTransactionEvent.eventType,
88+
merchantFeeAddedToTransactionEvent.data);
89+
90+
var events = projection.emittedEvents;
91+
t.equal(events.length, 3);
92+
t.end();
93+
});

NugetPackage/NugetPackage.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@
3030
</Content>
3131
</ItemGroup>
3232

33+
<ItemGroup>
34+
<None Remove="projections\continuous\MerchantBalanceAggregator.js" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<Content Update="projections\continuous\MerchantBalanceAggregator.js">
39+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
40+
</Content>
41+
</ItemGroup>
42+
3343
</Project>

NugetPackage/obj/NugetPackage.csproj.nuget.dgspec.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"sources": {
2929
"C:\\Program Files\\dotnet\\library-packs": {},
3030
"https://api.nuget.org/v3/index.json": {},
31-
"https://nuget.devexpress.com/tP9yfuwysSqblTj4iZAmef8L1WgJPsXlZjZLvEacI8BaCoK3A1/api": {},
3231
"https://www.myget.org/F/transactionprocessing/api/v3/index.json": {},
3332
"https://www.myget.org/F/vme-intellistore/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {},
3433
"https://www.myget.org/F/vme-shared/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {}
@@ -64,7 +63,7 @@
6463
"privateAssets": "all"
6564
}
6665
},
67-
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.401\\RuntimeIdentifierGraph.json"
66+
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100-rc.2.22477.23\\RuntimeIdentifierGraph.json"
6867
}
6968
}
7069
}

NugetPackage/obj/NugetPackage.csproj.nuget.g.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
88
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\stuar\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
99
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
10-
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.0</NuGetToolVersion>
10+
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.4.0</NuGetToolVersion>
1111
</PropertyGroup>
1212
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
1313
<SourceRoot Include="C:\Users\stuar\.nuget\packages\" />

NugetPackage/obj/project.assets.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"sources": {
3737
"C:\\Program Files\\dotnet\\library-packs": {},
3838
"https://api.nuget.org/v3/index.json": {},
39-
"https://nuget.devexpress.com/tP9yfuwysSqblTj4iZAmef8L1WgJPsXlZjZLvEacI8BaCoK3A1/api": {},
4039
"https://www.myget.org/F/transactionprocessing/api/v3/index.json": {},
4140
"https://www.myget.org/F/vme-intellistore/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {},
4241
"https://www.myget.org/F/vme-shared/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {}
@@ -72,7 +71,7 @@
7271
"privateAssets": "all"
7372
}
7473
},
75-
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.401\\RuntimeIdentifierGraph.json"
74+
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100-rc.2.22477.23\\RuntimeIdentifierGraph.json"
7675
}
7776
}
7877
}

NugetPackage/obj/project.nuget.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"dgSpecHash": "KbjJ6b/Y+kTy1GKsVWpr7Z3DDcY3Fx1ElosAQ1kHqJTgRiQCXFzRulAKCOqka9t8HA4vmisX5vbm1ENdIq+C8Q==",
3+
"dgSpecHash": "zKSi6wid/WSnBVdoC/xTn5nYXu7whOdnAbYDX2c907cmEVYMfmCreIiWizMZeX0Heo5FKLmFLarJl29Q9A9qJg==",
44
"success": true,
55
"projectFilePath": "C:\\Projects\\TransactionProcessing\\EventStoreProjections\\NugetPackage\\NugetPackage.csproj",
66
"expectedPackageFiles": [],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//starttestsetup
2+
var fromAll = fromAll || require("../../../EventStoreProjections/node_modules/@transactionprocessing/esprojection-testing-framework").scope.fromAll;
3+
var linkTo = linkTo || require("../../../EventStoreProjections/node_modules/@transactionprocessing/esprojection-testing-framework").scope.linkTo;
4+
//endtestsetup
5+
6+
isValidEvent = function (e) {
7+
8+
if (e) {
9+
if (e.data) {
10+
if (e.isJson) {
11+
if (e.eventType !== "$metadata") {
12+
return true;
13+
}
14+
}
15+
}
16+
}
17+
18+
return false;
19+
};
20+
21+
getMerchantId = function (e) {
22+
if (e.data.merchantId === undefined) {
23+
return null;
24+
}
25+
return e.data.merchantId;
26+
};
27+
28+
fromAll()
29+
.when({
30+
$any: function (s, e) {
31+
if (isValidEvent(e)) {
32+
var merchantId = getMerchantId(e);
33+
if (merchantId !== null) {
34+
if (e.eventType == "MerchantCreatedEvent" ||
35+
e.eventType === "ManualDepositMadeEvent" ||
36+
e.eventType === "AutomaticDepositMadeEvent" ||
37+
e.eventType === "TransactionHasStartedEvent" ||
38+
e.eventType === "TransactionHasBeenCompletedEvent" ||
39+
e.eventType === "MerchantFeeAddedToTransactionEvent") {
40+
var streamName = "MerchantBalanceArchive-" + merchantId.replace(/-/gi, "");
41+
linkTo(streamName, e);
42+
}
43+
}
44+
}
45+
}
46+
});

0 commit comments

Comments
 (0)