This commit is contained in:
rossmill76 committed 2026-03-05 18:57:12 +00:00
1 parent 38067df8c3
commit 492d86db9e
30 files changed
+2473 -40

No files matched your search

@@ -107,6 +107,59 @@ public class DashboardServiceTests
Assert.Empty(result.Datasets);
}
[Fact]
public void BuildChartData_PaidFutureTransaction_ExcludedFromProjection()
{
var today = DateTime.Today;
var start = today.AddDays(-1);
var end = today.AddDays(5);
// CurrentBalance is manually maintained by the user — MarkAsPaidAsync never touches it
var account = new Account { Id = 1, Name = "Current", Color = "#000", CurrencyCode = "GBP", CurrentBalance = 1000 };
var transactions = new List<Transaction>
{
// Unpaid future expense — should reduce the projected balance
new() { Description = "Unpaid Bill", Amount = 100, Date = today.AddDays(3), Type = TransactionType.Expense, AccountId = 1, Account = account, IsPaid = false },
// Paid future expense — excluded from projection; CurrentBalance already reflects it (user-managed)
new() { Description = "Paid Bill", Amount = 200, Date = today.AddDays(4), Type = TransactionType.Expense, AccountId = 1, Account = account, IsPaid = true }
};
var result = DashboardService.BuildChartData([account], transactions, start, end);
var data = result.Datasets[0].Data;
// Today's index = 1 (start is today-1)
int todayIndex = 1;
// Balance is flat at CurrentBalance up to the unpaid bill
Assert.Equal(1000m, data[todayIndex]);
// Day +3 (index 4): unpaid bill applied → 900
Assert.Equal(900m, data[todayIndex + 3]);
// Day +4 (index 5): paid bill is excluded from projection → stays at 900
Assert.Equal(900m, data[todayIndex + 4]);
}
[Fact]
public void BuildChartData_PaidFutureTransaction_ExcludedFromDayTransactionLabels()
{
var today = DateTime.Today;
var start = today;
var end = today.AddDays(2);
var account = new Account { Id = 1, Name = "Current", Color = "#000", CurrencyCode = "GBP", CurrentBalance = 500 };
var transactions = new List<Transaction>
{
new() { Description = "Unpaid", Amount = 50, Date = today.AddDays(1), Type = TransactionType.Expense, AccountId = 1, Account = account, IsPaid = false },
new() { Description = "Paid", Amount = 100, Date = today.AddDays(2), Type = TransactionType.Expense, AccountId = 1, Account = account, IsPaid = true }
};
var result = DashboardService.BuildChartData([account], transactions, start, end);
// Day +1: unpaid transaction appears in labels
Assert.Single(result.DayTransactionLabels[1]);
Assert.Contains("Unpaid", result.DayTransactionLabels[1][0]);
// Day +2: paid transaction is excluded from labels
Assert.Empty(result.DayTransactionLabels[2]);
}
#endregion
#region GetDashboardDataAsync (integration tests)