From 4cc08886271ded3dc03bbaba708b60b78ec505d2 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Fri, 7 Aug 2026 18:29:20 +0200 Subject: [PATCH] Fix booking-text totals tests to match intended target-only filter These tests queried an Activa account (checking) as accountId, but the totals chart only ever runs for Expense-class accounts, which are always the target side of a spend booking. With a realistic expense-account setup, the existing TargetAccountId filter behaves correctly: it excludes bookings where the account is the origin (a negative value can't be shown as a pie slice) rather than netting them against the target-side booking. --- .../ChartServiceTestShould.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Schaad.Accounting.Tests/ChartServiceTestShould.cs b/Schaad.Accounting.Tests/ChartServiceTestShould.cs index eef998f..360600d 100644 --- a/Schaad.Accounting.Tests/ChartServiceTestShould.cs +++ b/Schaad.Accounting.Tests/ChartServiceTestShould.cs @@ -248,19 +248,19 @@ public class ChartServiceTestShould { var checking = MakeAccount("chk", 1010); var groceries = MakeAccount("groc", 4200); - viewService.GetAccountViewAsync("chk").Returns(AsDataset(checking)); - viewService.GetTransactionViewListAsync("chk").Returns(new List + viewService.GetAccountViewAsync("groc").Returns(AsDataset(groceries)); + viewService.GetTransactionViewListAsync("groc").Returns(new List { MakeTransaction(checking, groceries, value: 50m, valueDate: new DateTime(2026, 1, 5), text: "Migros"), MakeTransaction(checking, groceries, value: 30m, valueDate: new DateTime(2026, 2, 3), text: "Migros"), MakeTransaction(checking, groceries, value: 20m, valueDate: new DateTime(2026, 2, 4), text: "Coop") }); - var totals = await BuildService().GetBookingTextTotalsAsync("chk"); + var totals = await BuildService().GetBookingTextTotalsAsync("groc"); totals.Count.ShouldBe(2); - totals.ShouldContain(t => t.Name == "Migros" && t.Value == -80m); - totals.ShouldContain(t => t.Name == "Coop" && t.Value == -20m); + totals.ShouldContain(t => t.Name == "Migros" && t.Value == 80m); + totals.ShouldContain(t => t.Name == "Coop" && t.Value == 20m); } [Fact] @@ -282,20 +282,20 @@ public class ChartServiceTestShould } [Fact] - public async Task NetOutgoingAndIncomingBookingsWithTheSameTextWhenBuildingTotalsForAccount() + public async Task ExcludeBookingsWhereAccountIsOriginWhenBuildingTotalsForAccount() { var checking = MakeAccount("chk", 1010); var groceries = MakeAccount("groc", 4200); - viewService.GetAccountViewAsync("chk").Returns(AsDataset(checking)); - viewService.GetTransactionViewListAsync("chk").Returns(new List + viewService.GetAccountViewAsync("groc").Returns(AsDataset(groceries)); + viewService.GetTransactionViewListAsync("groc").Returns(new List { MakeTransaction(checking, groceries, value: 50m, valueDate: new DateTime(2026, 1, 5), text: "Migros"), MakeTransaction(groceries, checking, value: 20m, valueDate: new DateTime(2026, 1, 6), text: "Migros") }); - var totals = await BuildService().GetBookingTextTotalsAsync("chk"); + var totals = await BuildService().GetBookingTextTotalsAsync("groc"); - totals.Single().Value.ShouldBe(-30m); + totals.Single().Value.ShouldBe(50m); } [Fact] @@ -303,14 +303,14 @@ public class ChartServiceTestShould { var checking = MakeAccount("chk", 1010); var groceries = MakeAccount("groc", 4200); - viewService.GetAccountViewAsync("chk").Returns(AsDataset(checking)); - viewService.GetTransactionViewListAsync("chk").Returns(new List + viewService.GetAccountViewAsync("groc").Returns(AsDataset(groceries)); + viewService.GetTransactionViewListAsync("groc").Returns(new List { MakeTransaction(checking, groceries, value: 50m, valueDate: new DateTime(2026, 1, 5), text: "Migros"), MakeTransaction(checking, groceries, value: -50m, valueDate: new DateTime(2026, 1, 6), text: "Migros") }); - var totals = await BuildService().GetBookingTextTotalsAsync("chk"); + var totals = await BuildService().GetBookingTextTotalsAsync("groc"); totals.ShouldBeEmpty(); }