Skip to content
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
1 change: 1 addition & 0 deletions EventStoreProjections/EventStoreProjections.Tests.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Content Include="tests\EstateAggregatorTests.js" />
<Content Include="tests\EstateManagementSubscriptionStreamBuilderTests.js" />
<Content Include="tests\FileProcessorSubscriptionStreamBuilderTests.js" />
<Content Include="tests\MerchantBalanceAggregatorTests.js" />
<Content Include="tests\MerchantAggregatorTests.js" />
<Content Include="tests\TestData.js" />
<Content Include="tests\TransactionProcessorSubscriptionStreamBuilderTests.js" />
Expand Down
93 changes: 93 additions & 0 deletions EventStoreProjections/tests/MerchantBalanceAggregatorTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
require('../../NugetPackage/projections/continuous/MerchantBalanceAggregator.js');
var projection = require('@transactionprocessing/esprojection-testing-framework');
var testData = require('./TestData.js');
var describe = require('tape-describe');
var test = describe('Merchant Balance Aggregator Tests');

test('Projection Can Handle Merchant Events',
t =>
{
projection.initialize();

var estateId = '3bf2dab2-86d6-44e3-bcf8-51bec65cf8bc';
var merchantId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
var merchantName = 'Test Merchant 1';

// Set up the merchant events
var merchantCreatedEvent = testData.getMerchantCreatedEvent(estateId, merchantId, merchantName);

var depositDateTime = '2020-05-30T06:21:31.356Z';
var depositAmount = 1000.00;
var manualDepositMadeEvent =
testData.getManualDepositMadeEvent(estateId, merchantId, depositDateTime, depositAmount);

var automaticDepositMadeEvent =
testData.getAutomaticDepositMadeEvent(estateId, merchantId, depositDateTime, depositAmount);

projection.processEvent(
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
merchantCreatedEvent.eventType,
merchantCreatedEvent.data);

projection.processEvent(
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
manualDepositMadeEvent.eventType,
manualDepositMadeEvent.data);

projection.processEvent(
'MerchantAggregate-' + merchantId.replace(/-/gi, ""),
automaticDepositMadeEvent.eventType,
automaticDepositMadeEvent.data);

var events = projection.emittedEvents;
t.equal(events.length, 3);
t.end();
});

test('Projection Can Handle Transaction Events',
t =>
{
projection.initialize();

var estateId = '3bf2dab2-86d6-44e3-bcf8-51bec65cf8bc';
var merchantId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
var transactionId = 'c4c33d75-f011-40e4-9d97-1f428ab563d8';
var transactionAmount = 100.00;
var transactionType = 'Sale';

var transactionHasStartedEvent = testData.getTransactionHasStartedEvent(estateId,
merchantId,
transactionId,
transactionAmount,
transactionType);

var transactionHasBeenCompletedEvent =
testData.getTransactionHasBeenCompletedEvent(estateId, merchantId, transactionId, true);

var calculatedValue = 5.00;
var eventCreatedDateTime = "2020-05-16T07:47:51.6617562+00:00";
var merchantFeeAddedToTransactionEvent = testData.getMerchantFeeAddedToTransactionEvent(estateId,
merchantId,
transactionId,
calculatedValue,
eventCreatedDateTime);

projection.processEvent(
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
transactionHasStartedEvent.eventType,
transactionHasStartedEvent.data);

projection.processEvent(
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
transactionHasBeenCompletedEvent.eventType,
transactionHasBeenCompletedEvent.data);

projection.processEvent(
'TransactionAggregate-' + transactionId.replace(/-/gi, ""),
merchantFeeAddedToTransactionEvent.eventType,
merchantFeeAddedToTransactionEvent.data);

var events = projection.emittedEvents;
t.equal(events.length, 3);
t.end();
});
10 changes: 10 additions & 0 deletions NugetPackage/NugetPackage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
</Content>
</ItemGroup>

<ItemGroup>
<None Remove="projections\continuous\MerchantBalanceAggregator.js" />
</ItemGroup>

<ItemGroup>
<Content Update="projections\continuous\MerchantBalanceAggregator.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions NugetPackage/obj/NugetPackage.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"sources": {
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {},
"https://nuget.devexpress.com/tP9yfuwysSqblTj4iZAmef8L1WgJPsXlZjZLvEacI8BaCoK3A1/api": {},
"https://www.myget.org/F/transactionprocessing/api/v3/index.json": {},
"https://www.myget.org/F/vme-intellistore/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {},
"https://www.myget.org/F/vme-shared/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {}
Expand Down Expand Up @@ -64,7 +63,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.401\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100-rc.2.22477.23\\RuntimeIdentifierGraph.json"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion NugetPackage/obj/NugetPackage.csproj.nuget.g.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\stuar\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.0</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.4.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\stuar\.nuget\packages\" />
Expand Down
3 changes: 1 addition & 2 deletions NugetPackage/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"sources": {
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {},
"https://nuget.devexpress.com/tP9yfuwysSqblTj4iZAmef8L1WgJPsXlZjZLvEacI8BaCoK3A1/api": {},
"https://www.myget.org/F/transactionprocessing/api/v3/index.json": {},
"https://www.myget.org/F/vme-intellistore/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {},
"https://www.myget.org/F/vme-shared/auth/024ff48c-540a-4059-8712-d54f7b0d6a31/api/v3/index.json": {}
Expand Down Expand Up @@ -72,7 +71,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.401\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100-rc.2.22477.23\\RuntimeIdentifierGraph.json"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion NugetPackage/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "KbjJ6b/Y+kTy1GKsVWpr7Z3DDcY3Fx1ElosAQ1kHqJTgRiQCXFzRulAKCOqka9t8HA4vmisX5vbm1ENdIq+C8Q==",
"dgSpecHash": "zKSi6wid/WSnBVdoC/xTn5nYXu7whOdnAbYDX2c907cmEVYMfmCreIiWizMZeX0Heo5FKLmFLarJl29Q9A9qJg==",
"success": true,
"projectFilePath": "C:\\Projects\\TransactionProcessing\\EventStoreProjections\\NugetPackage\\NugetPackage.csproj",
"expectedPackageFiles": [],
Expand Down
46 changes: 46 additions & 0 deletions NugetPackage/projections/continuous/MerchantBalanceAggregator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//starttestsetup
var fromAll = fromAll || require("../../../EventStoreProjections/node_modules/@transactionprocessing/esprojection-testing-framework").scope.fromAll;
var linkTo = linkTo || require("../../../EventStoreProjections/node_modules/@transactionprocessing/esprojection-testing-framework").scope.linkTo;
//endtestsetup

isValidEvent = function (e) {

if (e) {
if (e.data) {
if (e.isJson) {
if (e.eventType !== "$metadata") {
return true;
}
}
}
}

return false;
};

getMerchantId = function (e) {
if (e.data.merchantId === undefined) {
return null;
}
return e.data.merchantId;
};

fromAll()
.when({
$any: function (s, e) {
if (isValidEvent(e)) {
var merchantId = getMerchantId(e);
if (merchantId !== null) {
if (e.eventType == "MerchantCreatedEvent" ||
e.eventType === "ManualDepositMadeEvent" ||
e.eventType === "AutomaticDepositMadeEvent" ||
e.eventType === "TransactionHasStartedEvent" ||
e.eventType === "TransactionHasBeenCompletedEvent" ||
e.eventType === "MerchantFeeAddedToTransactionEvent") {
var streamName = "MerchantBalanceArchive-" + merchantId.replace(/-/gi, "");
linkTo(streamName, e);
}
}
}
}
});