From 9130d6de11f48d8c0109133806643a9934d099bc Mon Sep 17 00:00:00 2001 From: gamer147 Date: Tue, 9 Jun 2026 14:59:39 -0400 Subject: [PATCH] test(inventory): pack-open shape produces acquire history Co-Authored-By: Claude Sonnet 4.6 --- .../Inventory/InventoryHistoryTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs b/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs index 34a4231..4a86e70 100644 --- a/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs +++ b/SVSim.UnitTests/Services/Inventory/InventoryHistoryTests.cs @@ -242,6 +242,36 @@ public class InventoryHistoryTests Assert.That(row.RewardDetailId, Is.EqualTo(0)); } + [Test] + public async Task PackOpen_path_appends_to_acquire_history_when_source_is_set() + { + // Direct exercise of the GrantSource plumbing as a stand-in for the real /pack/open route. + // After Task 11 migrates PackController.Open, a higher-level E2E test could replace this; + // for now this asserts the integration shape Pack open will fall into. + using var factory = new SVSim.UnitTests.Infrastructure.SVSimTestFactory(); + long viewerId = await factory.SeedViewerAsync(); + long cardId = await factory.SeedCardAsync(); + using var scope = factory.Services.CreateScope(); + var inv = scope.ServiceProvider.GetRequiredService(); + + await using (var tx = await inv.BeginAsync(viewerId, configure: c => c.Source = GrantSource.PackOpen)) + { + await tx.GrantAsync(SVSim.Database.Enums.UserGoodsType.Card, cardId, 1); + await tx.GrantAsync(SVSim.Database.Enums.UserGoodsType.Card, cardId, 1); + await tx.CommitAsync(); + } + + using var verifyScope = factory.Services.CreateScope(); + var ctx = verifyScope.ServiceProvider.GetRequiredService(); + var rows = await ctx.ViewerAcquireHistory.AsNoTracking() + .Where(h => h.ViewerId == viewerId) + .OrderBy(h => h.Id) + .ToListAsync(); + Assert.That(rows, Has.Count.EqualTo(2)); + Assert.That(rows.All(r => r.AcquireType == (int)GrantSource.PackOpen), Is.True); + Assert.That(rows.All(r => r.Message == "From buying card packs"), Is.True); + } + [Test] public async Task Commit_prunes_history_above_retention_cap_per_viewer() {