Skip to content

Commit a0ab3d2

Browse files
Merge pull request #496 from TransactionProcessing/copilot/investigate-nightly-build-failure
Stabilize nightly integration tests around midnight and correct last-hour merchant KPI logic
2 parents 8ec3281 + bd2973b commit a0ab3d2

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

EstateReportingAPI.BusinessLogic/ReportingManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,13 @@ public async Task<Result<MerchantKpi>> GetMerchantsTransactionKpis(MerchantQueri
572572

573573
var merchants = merchantsQueryResult.Data;
574574

575-
Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSaleDate == DateTime.Now.Date && m.LastSaleDateTime >= DateTime.Now.AddHours(-1) select m).Count();
575+
DateTime now = DateTime.Now;
576576

577-
Int32 merchantsWithNoSaleToday = (from m in merchants where m.LastSaleDate >= DateTime.Now.Date.AddDays(-7) && m.LastSaleDate <= DateTime.Now.Date.AddDays(-1) select m).Count();
577+
Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSaleDateTime >= now.AddHours(-1) && m.LastSaleDateTime <= now select m).Count();
578578

579-
Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSaleDate <= DateTime.Now.Date.AddDays(-7) select m).Count();
579+
Int32 merchantsWithNoSaleToday = (from m in merchants where m.LastSaleDate >= now.Date.AddDays(-7) && m.LastSaleDate <= now.Date.AddDays(-1) select m).Count();
580+
581+
Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSaleDate <= now.Date.AddDays(-7) select m).Count();
580582

581583
MerchantKpi response = new() { MerchantsWithSaleInLastHour = merchantsWithSaleInLastHour, MerchantsWithNoSaleToday = merchantsWithNoSaleToday, MerchantsWithNoSaleInLast7Days = merchantsWithNoSaleInLast7Days };
582584

@@ -1524,4 +1526,3 @@ private sealed class ProductPerformanceItemData {
15241526

15251527
#endregion
15261528
}
1527-

EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,32 @@ public async Task MerchantEndpoint_GetMerchantDevices_MerchantDevicesReturned()
148148
[Fact]
149149
public async Task MerchantEndpoint_GetMerchantKpis_MerchantKpisReturned()
150150
{
151-
await this.helper.AddEstate("Test Estate", "Ref1");
151+
DateTime now = DateTime.Now;
152152

153-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 1",100, DateTime.Now, DateTime.Now,
153+
await this.helper.AddEstate("Test Estate", "Ref1");
154+
155+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 1",100, now, now,
154156
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
155157
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
156-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 2", 200, DateTime.Now, DateTime.Now.AddMinutes(-10),
158+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 2", 200, now, now.AddMinutes(-10),
157159
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
158160
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
159-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 3",300, DateTime.Now, DateTime.Now.AddHours(-2),
161+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 3",300, now, now.AddHours(-2),
160162
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
161163
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
162-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 4",400, DateTime.Now, DateTime.Now.AddHours(-3),
164+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 4",400, now, now.AddHours(-3),
163165
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
164166
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
165-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 5",500, DateTime.Now, DateTime.Now.AddDays(-2),
167+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 5",500, now, now.AddDays(-2),
166168
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
167169
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
168-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 6",600, DateTime.Now, DateTime.Now.AddDays(-1),
170+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 6",600, now, now.AddDays(-1),
169171
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
170172
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
171-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 7",700, DateTime.Now, DateTime.Now.AddDays(-3),
173+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 7",700, now, now.AddDays(-3),
172174
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
173175
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
174-
await this.helper.AddMerchant("Test Estate", $"Test Merchant 8",800, DateTime.Now, DateTime.Now.AddDays(-10),
176+
await this.helper.AddMerchant("Test Estate", $"Test Merchant 8",800, now, now.AddDays(-10),
175177
("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
176178
("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
177179

@@ -192,4 +194,4 @@ protected override async Task ClearStandingData() {
192194
protected override async Task SetupStandingData() {
193195

194196
}
195-
}
197+
}

EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public async Task TransactionsEndpoint_TodaysSales_SalesReturned() {
104104
List<Transaction>? todaysTransactions = new List<Transaction>();
105105
List<Transaction> comparisonDateTransactions = new List<Transaction>();
106106

107-
DateTime todaysDateTime = DateTime.Now;
108-
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
107+
DateTime todaysDateTime = DateTime.Now.Date;
108+
DateTime comparisonDate = todaysDateTime.AddDays(-1);
109109

110110
Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
111111

@@ -115,7 +115,7 @@ public async Task TransactionsEndpoint_TodaysSales_SalesReturned() {
115115
foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) {
116116
var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
117117
for (int i = 0; i < transactionCount; i++) {
118-
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
118+
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
119119
todaysTransactions.Add(transaction);
120120
}
121121
}
@@ -162,8 +162,8 @@ public async Task TransactionsEndpoint_TodaysSales_OperatorFilter_SalesReturned(
162162
List<Transaction>? todaysTransactions = new List<Transaction>();
163163
List<Transaction> comparisonDateTransactions = new List<Transaction>();
164164

165-
DateTime todaysDateTime = DateTime.Now;
166-
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
165+
DateTime todaysDateTime = DateTime.Now.Date;
166+
DateTime comparisonDate = todaysDateTime.AddDays(-1);
167167

168168
Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
169169

@@ -173,7 +173,7 @@ public async Task TransactionsEndpoint_TodaysSales_OperatorFilter_SalesReturned(
173173
foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) {
174174
var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
175175
for (int i = 0; i < transactionCount; i++) {
176-
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
176+
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
177177
todaysTransactions.Add(transaction);
178178
}
179179
}
@@ -220,8 +220,8 @@ public async Task TransactionsEndpoint_TodaysSales_MerchantFilter_SalesReturned(
220220
List<Transaction>? todaysTransactions = new List<Transaction>();
221221
List<Transaction> comparisonDateTransactions = new List<Transaction>();
222222

223-
DateTime todaysDateTime = DateTime.Now;
224-
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
223+
DateTime todaysDateTime = DateTime.Now.Date;
224+
DateTime comparisonDate = todaysDateTime.AddDays(-1);
225225

226226
Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
227227

@@ -231,7 +231,7 @@ public async Task TransactionsEndpoint_TodaysSales_MerchantFilter_SalesReturned(
231231
foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) {
232232
var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
233233
for (int i = 0; i < transactionCount; i++) {
234-
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
234+
Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
235235
todaysTransactions.Add(transaction);
236236
}
237237
}
@@ -1213,4 +1213,4 @@ public async Task SettlementEndpoints_TodaysSettlement_SettlementReturned()
12131213
todaysSettlement.TodaysPendingSettlementCount.ShouldBe(overallTodaysPendingSettlementTransactionCount);
12141214
todaysSettlement.TodaysPendingSettlementValue.ShouldBe(todayOverallTotals.Sum(c => c.pendingSettlementFees));
12151215
}
1216-
}
1216+
}

0 commit comments

Comments
 (0)