test(pack): cover additive accrual on existing gacha-point balance

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-28 23:27:56 -04:00
parent 723a97e3af
commit c7fb56f95f

View File

@@ -283,4 +283,43 @@ public class GachaPointServiceTests
Assert.That(viewer.GachaPointBalances, Is.Empty);
}
[Test]
public async Task Accrue_increments_existing_balance_on_second_call()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
db.Packs.Add(new PackConfigEntry
{
Id = 10008, BasePackId = 10008, PackCategory = PackCategory.LegendCardPack,
CommenceDate = DateTime.UtcNow.AddDays(-1), CompleteDate = DateTime.UtcNow.AddDays(30),
GachaPointConfig = new PackGachaPointConfig { ExchangeablePoint = 400, IncreaseGachaPoint = 1 },
ChildGachas =
{
new PackChildGachaEntry { GachaId = 100087, TypeDetail = 7, Cost = 100, CardCount = 8 },
},
});
await db.SaveChangesAsync();
var viewer = await db.Viewers.Include(v => v.GachaPointBalances).FirstAsync(v => v.Id == viewerId);
var pack = await db.Packs.Include(p => p.ChildGachas).FirstAsync(p => p.Id == 10008);
var child = pack.ChildGachas[0];
var svc = scope.ServiceProvider.GetRequiredService<IGachaPointService>();
// First accrual: creates the balance row.
svc.Accrue(viewer, pack, child, packNumber: 3);
await db.SaveChangesAsync();
// Second accrual: must hit the existing row (the `+=` branch), not create a duplicate.
svc.Accrue(viewer, pack, child, packNumber: 5);
await db.SaveChangesAsync();
Assert.That(viewer.GachaPointBalances, Has.Count.EqualTo(1),
"second Accrue must update the existing row, not create a duplicate");
Assert.That(viewer.GachaPointBalances.Single().Points, Is.EqualTo(8));
}
}