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
4 changes: 3 additions & 1 deletion EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,9 @@ private static List<MetricItem> BuildMerchantDailyPerformanceMetrics(List<Mercha
return new MetricItem {
Title = "Top Product Sales Count",
Value = topProduct.SalesCount,
Description = $"{topProduct.OperatorName} {topProduct.ProductName}" ?? "Unknown product",
Description = string.IsNullOrWhiteSpace(topProduct.OperatorName) || string.IsNullOrWhiteSpace(topProduct.ProductName)
? "Unknown product"
: $"{topProduct.OperatorName} {topProduct.ProductName}",
Category = 5,
Type = 8
};
Expand Down
65 changes: 65 additions & 0 deletions EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,71 @@ await this.helper.BuildTransactionX(
response.DrillDownTransactions.Count.ShouldBe(2);
}

[Fact]
public async Task TransactionsEndpoint_MerchantDailyPerformanceSummary_UsesFallbackWhenTopProductOperatorNameIsMissing()
{
TransactionProcessor.Database.Entities.Merchant merchant = this.merchantsList.Single(m => 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<Transaction> 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<MerchantDailyPerformanceSummaryResponse>(
$"{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()
{
Expand Down
Loading