feat(packs): PackImporter stubs pass + IsEnabled gate in active-packs

PackImporter now runs a second pass over pack-stubs.json, inserting
PackConfigEntry placeholders for any pack_id NOT already present from
the live-capture packs.json pass. Synthesized stubs default
IsEnabled=false; live-capture rows default IsEnabled=true.

PackRepository.GetActivePacks filters by IsEnabled in addition to the
date window, so synthesized stubs stay hidden until an operator opts
them in (UPDATE Packs SET IsEnabled=true WHERE Id=...).

Bundles Task 6 + Task 11 because adding pack-stubs.json to the
test-fixture set surfaces an extra row in PackControllerFullCatalogTests'
35-pack count assertion; the filter is what makes the test resilient.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-30 21:52:27 -04:00
parent 72c8fe627b
commit f7407fe382
5 changed files with 197 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SVSim.Bootstrap.Importers;
using SVSim.Database;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Importers;
public class PackImporterStubsTests
{
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
[Test]
public async Task Live_capture_overrides_stub_on_conflict()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new PackImporter().ImportAsync(db, SeedDir);
// 10001 is in both packs.json (no is_enabled -> defaults true) and pack-stubs.json
// (is_enabled=false). Live capture wins -> IsEnabled stays true and gacha_detail
// is the packs.json value, not "STUB CLC".
var live = await db.Packs.FirstAsync(p => p.Id == 10001);
Assert.That(live.IsEnabled, Is.True);
Assert.That(live.GachaDetail, Does.Not.Contain("STUB"));
}
[Test]
public async Task Stub_only_packs_are_inserted_with_IsEnabled_false()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new PackImporter().ImportAsync(db, SeedDir);
// 95001 is stub-only -> inserted with IsEnabled=false and the stub's gacha_detail.
var stub = await db.Packs.FirstAsync(p => p.Id == 95001);
Assert.That(stub.IsEnabled, Is.False);
Assert.That(stub.GachaDetail, Is.EqualTo("7th Anniv stub"));
}
}

View File

@@ -41,6 +41,33 @@ public class PackRepositoryTests
Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 }));
}
[Test]
public async Task GetActivePacks_excludes_IsEnabled_false_rows()
{
using var factory = new SVSimTestFactory();
var now = new DateTime(2026, 5, 24, 12, 0, 0, DateTimeKind.Utc);
await SeedPack(factory, 10001, 10001, PackCategory.None, now.AddDays(-1), now.AddDays(1));
using (var scope = factory.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
db.Packs.Add(new PackConfigEntry
{
Id = 10002, BasePackId = 10002, PackCategory = PackCategory.None,
CommenceDate = now.AddDays(-1), CompleteDate = now.AddDays(1),
GachaType = 1, GachaDetail = "disabled",
IsEnabled = false,
});
await db.SaveChangesAsync();
}
using var scopeRepo = factory.Services.CreateScope();
var repo = scopeRepo.ServiceProvider.GetRequiredService<IPackRepository>();
var packs = await repo.GetActivePacks(now);
Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 }));
}
[Test]
public async Task GetPack_includes_child_gachas_and_banners()
{