refactor(giving): drop unused accessor from category service + add deactivate-missing test

This commit is contained in:
Chris Chen
2026-05-28 16:33:27 -07:00
parent 798dfa3fe0
commit cb15d30980
2 changed files with 13 additions and 6 deletions
@@ -35,7 +35,7 @@ public class GivingCategoryServiceTests
public async Task CreateAsync_ReturnsId_AndDefaultsActive()
{
using var db = BuildDb();
var svc = new GivingCategoryService(db, BuildAccessor());
var svc = new GivingCategoryService(db);
var id = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Tithe", Name_zh = "什一" });
@@ -49,7 +49,7 @@ public class GivingCategoryServiceTests
public async Task GetAllAsync_ExcludesInactive_ByDefault()
{
using var db = BuildDb();
var svc = new GivingCategoryService(db, BuildAccessor());
var svc = new GivingCategoryService(db);
var id1 = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Active" });
var id2 = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Gone" });
await svc.DeactivateAsync(id2);
@@ -65,7 +65,7 @@ public class GivingCategoryServiceTests
public async Task DeactivateAsync_SetsIsActiveFalse()
{
using var db = BuildDb();
var svc = new GivingCategoryService(db, BuildAccessor());
var svc = new GivingCategoryService(db);
var id = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Temp" });
await svc.DeactivateAsync(id);
@@ -78,8 +78,16 @@ public class GivingCategoryServiceTests
public async Task UpdateAsync_Throws_WhenMissing()
{
using var db = BuildDb();
var svc = new GivingCategoryService(db, BuildAccessor());
var svc = new GivingCategoryService(db);
await Assert.ThrowsAsync<KeyNotFoundException>(() =>
svc.UpdateAsync(999, new UpdateGivingCategoryRequest { Name_en = "X" }));
}
[Fact]
public async Task DeactivateAsync_Throws_WhenMissing()
{
using var db = BuildDb();
var svc = new GivingCategoryService(db);
await Assert.ThrowsAsync<KeyNotFoundException>(() => svc.DeactivateAsync(999));
}
}
@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using ROLAC.API.Data;
using ROLAC.API.DTOs.Giving;
@@ -9,7 +8,7 @@ namespace ROLAC.API.Services;
public class GivingCategoryService : IGivingCategoryService
{
private readonly AppDbContext _db;
public GivingCategoryService(AppDbContext db, IHttpContextAccessor http) => _db = db;
public GivingCategoryService(AppDbContext db) => _db = db;
public async Task<List<GivingCategoryDto>> GetAllAsync(bool includeInactive)
{