test(inventory): pack-open shape produces acquire history
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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<SVSim.Database.Services.Inventory.IInventoryService>();
|
||||
|
||||
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<SVSim.Database.SVSimDbContext>();
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user