diff --git a/API/ROLAC.API.Tests/Services/GivingServiceTests.cs b/API/ROLAC.API.Tests/Services/GivingServiceTests.cs index f400994..67d0281 100644 --- a/API/ROLAC.API.Tests/Services/GivingServiceTests.cs +++ b/API/ROLAC.API.Tests/Services/GivingServiceTests.cs @@ -100,4 +100,41 @@ public class GivingServiceTests var svc = new GivingService(db); await Assert.ThrowsAsync(() => svc.DeleteAsync(999)); } + + [Fact] + public async Task CreateAsync_Anonymous_NullsProvidedMemberId() + { + using var db = BuildDb(); + var catId = await SeedCategoryAsync(db); + var svc = new GivingService(db); + + var id = await svc.CreateAsync(new CreateGivingRequest + { + GivingCategoryId = catId, Amount = 25m, PaymentMethod = "Cash", + GivingDate = new DateOnly(2026, 5, 31), + IsAnonymous = true, MemberId = 12345, // provided, but must be stripped + }); + + var saved = await db.Givings.FindAsync(id); + Assert.True(saved!.IsAnonymous); + Assert.Null(saved.MemberId); + } + + [Fact] + public async Task DeleteAsync_Throws_WhenGivingBelongsToSubmittedSession() + { + using var db = BuildDb(); + var catId = await SeedCategoryAsync(db); + var session = new OfferingSession { SessionDate = new DateOnly(2026, 5, 31), Status = "Submitted" }; + db.OfferingSessions.Add(session); + await db.SaveChangesAsync(); + var giving = new Giving { GivingCategoryId = catId, Amount = 50m, PaymentMethod = "Cash", + GivingDate = new DateOnly(2026, 5, 31), OfferingSessionId = session.Id }; + db.Givings.Add(giving); + await db.SaveChangesAsync(); + + var svc = new GivingService(db); + + await Assert.ThrowsAsync(() => svc.DeleteAsync(giving.Id)); + } }