diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index cbc5802..ff086b2 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -2124,7 +2124,9 @@ private static List BuildMerchantDailyPerformanceMetrics(List m.Name == "Test Merchant 1"); + var contract = this.contractList.Single(c => c.contractName == "Safaricom Contract"); + var topProduct = this.contractProducts.Single(cp => cp.Key == contract.contractId).Value.Single(p => p.productName == "50 KES Topup"); + var secondaryProduct = this.contractProducts.Single(cp => cp.Key == contract.contractId).Value.Single(p => p.productName == "100 KES Topup"); + DateTime transactionDate = DateTime.Now.Date; + + List transactions = [ + await this.helper.BuildTransactionX( + transactionDate.AddHours(9), + merchant.MerchantId, + Guid.NewGuid(), + contract.contractId, + topProduct.productId, + "0000", + topProduct.productValue, + 3001), + await this.helper.BuildTransactionX( + transactionDate.AddHours(10), + merchant.MerchantId, + Guid.NewGuid(), + contract.contractId, + topProduct.productId, + "0000", + topProduct.productValue, + 3002), + await this.helper.BuildTransactionX( + transactionDate.AddHours(11), + merchant.MerchantId, + contract.operatorId, + contract.contractId, + secondaryProduct.productId, + "0000", + secondaryProduct.productValue, + 3003) + ]; + + await this.helper.AddTransactionsX(transactions); + + MerchantDailyPerformanceSummaryRequest request = new() + { + MerchantReportingId = merchant.MerchantReportingId, + StartDate = transactionDate, + EndDate = transactionDate + }; + + var result = await this.CreateAndSendHttpRequestMessage( + $"{this.BaseRoute}/merchantdailyperformancesummary", + StringSerialiser.Serialise(request), + CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + + MerchantDailyPerformanceSummaryResponse response = result.Data; + response.ShouldNotBeNull(); + response.Metrics.ShouldNotBeNull(); + + response.Metrics.Single(m => m.Title == "Top Product Sales Count").ShouldSatisfyAllConditions(metric => { + metric.Value.ShouldBe(2); + metric.Description.ShouldBe("Unknown product"); + }); + } + [Fact] public async Task TransactionsEndpoint_MerchantDailyPerformanceSummary_NoSales_ReturnsStableMetricCategories() {