using System.Net; using System.Text; using System.Text.Json; using SVSim.UnitTests.Infrastructure; namespace SVSim.UnitTests.Controllers; /// /// Drives the importer + controller against the real prod capture (35 packs). Guards against /// regressions in either layer caused by future capture refreshes. /// public class PackControllerProdCaptureTests { [Test] public async Task Info_returns_full_35_pack_catalog_from_prod_capture() { // The default captures dir has both pack-info-fixture.json (3 packs) and // pack-info-2026-05-23.json (35 packs). LoadCapture sorts by name descending and // "pack-info-fixture.json" > "pack-info-2026-05-23.json" lexicographically, so the // fixture would win. Copy captures to a temp dir, drop the fixture, then seed from there. var sourceDir = Path.Combine(AppContext.BaseDirectory, "Data", "prod-captures"); var tempDir = Path.Combine(Path.GetTempPath(), "svsim-pack-prod-" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); try { foreach (var src in Directory.EnumerateFiles(sourceDir)) { if (Path.GetFileName(src).Equals("pack-info-fixture.json", StringComparison.OrdinalIgnoreCase)) continue; File.Copy(src, Path.Combine(tempDir, Path.GetFileName(src))); } using var factory = new SVSimTestFactory(); await factory.SeedGlobalsAsync(tempDir); // imports the 35-pack pack-info-2026-05-23.json long viewerId = await factory.SeedViewerAsync(); using var client = factory.CreateAuthenticatedClient(viewerId); var response = await client.PostAsync( "/pack/info", new StringContent("""{"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""", Encoding.UTF8, "application/json")); var body = await response.Content.ReadAsStringAsync(); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK), body); using var doc = JsonDocument.Parse(body); var list = doc.RootElement.GetProperty("pack_config_list"); Assert.That(list.GetArrayLength(), Is.EqualTo(35), "Full prod capture should yield 35 active packs as of 2026-05-23."); // Spot-check pack 99047 (LegendCardPack throwback, pack_category=1) bool sawSpecial = false; for (int i = 0; i < list.GetArrayLength(); i++) { var el = list[i]; if (el.GetProperty("parent_gacha_id").GetInt32() == 99047) { Assert.That(el.GetProperty("pack_category").GetInt32(), Is.EqualTo(1), "99047 is a LegendCardPack (category 1) in the prod capture."); sawSpecial = true; break; } } Assert.That(sawSpecial, Is.True, "pack 99047 must be in the prod capture output."); } finally { try { Directory.Delete(tempDir, recursive: true); } catch { /* best-effort cleanup */ } } } }