fix(expense-snapshot): validate functional class + stamp DeletedBy on soft delete
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,12 @@ public class ExpenseSnapshotServiceTests
|
||||
db.ExpenseCategoryGroups.Add(new ExpenseCategoryGroup { Id = 1, Name_en = "Facilities" });
|
||||
db.ExpenseSubCategories.Add(new ExpenseSubCategory { Id = 1, GroupId = 1, Name_en = "Rent" });
|
||||
db.SaveChanges();
|
||||
return (new ExpenseSnapshotService(db), db);
|
||||
|
||||
var claims = new[] { new Claim(ClaimTypes.NameIdentifier, userId) };
|
||||
var ctx = new DefaultHttpContext { User = new(new ClaimsIdentity(claims)) };
|
||||
var http = new Mock<IHttpContextAccessor>();
|
||||
http.Setup(x => x.HttpContext).Returns(ctx);
|
||||
return (new ExpenseSnapshotService(db, http.Object), db);
|
||||
}
|
||||
|
||||
private static CreateExpenseSnapshotRequest Rent() => new()
|
||||
@@ -62,6 +67,15 @@ public class ExpenseSnapshotServiceTests
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => svc.CreateAsync(r));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Create_WithInvalidFunctionalClass_Throws()
|
||||
{
|
||||
var (svc, _) = Build();
|
||||
var r = Rent();
|
||||
r.Lines[0].FunctionalClass = "NotAClass";
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => svc.CreateAsync(r));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetById_ReturnsLines_TotalsAndCreatorName()
|
||||
{
|
||||
@@ -138,4 +152,14 @@ public class ExpenseSnapshotServiceTests
|
||||
Assert.Empty(await svc.GetAllAsync());
|
||||
Assert.Null(await db.ExpenseSnapshots.FirstOrDefaultAsync(s => s.Id == id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Delete_StampsDeletedBy()
|
||||
{
|
||||
var (svc, db) = Build("deleter-1");
|
||||
var id = await svc.CreateAsync(Rent());
|
||||
await svc.DeleteAsync(id);
|
||||
var row = await db.ExpenseSnapshots.IgnoreQueryFilters().FirstAsync(s => s.Id == id);
|
||||
Assert.Equal("deleter-1", row.DeletedBy);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user