refactor(bp): flatten BattlePassLevelEntry — drop misnamed RewardData jsonb

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-26 21:57:47 -04:00
parent 141f34f817
commit 95b8f39ea5
9 changed files with 3134 additions and 541 deletions

View File

@@ -0,0 +1,83 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SVSim.Bootstrap.Importers;
using SVSim.Database;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Importers;
public class BattlePassImporterTests
{
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
[Test]
public async Task Imports_level_curve_from_seed_file()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new BattlePassImporter().ImportAsync(db, SeedDir);
var levels = await db.BattlePassLevels.OrderBy(e => e.Level).ToListAsync();
Assert.That(levels.Count, Is.EqualTo(100), "seed must contain 100 levels");
Assert.That(levels[0].Level, Is.EqualTo(1));
Assert.That(levels[0].RequiredPoint, Is.EqualTo(0));
Assert.That(levels[1].Level, Is.EqualTo(2));
Assert.That(levels[1].RequiredPoint, Is.EqualTo(500));
}
[Test]
public async Task Is_idempotent_on_rerun()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int before = await db.BattlePassLevels.CountAsync();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int after = await db.BattlePassLevels.CountAsync();
Assert.That(after, Is.EqualTo(before));
}
[Test]
public async Task Leaves_existing_rows_untouched_when_missing_from_seed()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
db.BattlePassLevels.Add(new SVSim.Database.Models.BattlePassLevelEntry
{
Level = 999, RequiredPoint = 12345,
});
await db.SaveChangesAsync();
await new BattlePassImporter().ImportAsync(db, SeedDir);
var legacy = await db.BattlePassLevels.FindAsync(999);
Assert.That(legacy, Is.Not.Null, "seed-missing row must be left intact");
Assert.That(legacy!.RequiredPoint, Is.EqualTo(12345));
}
[Test]
public async Task Empty_seed_file_is_no_op()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
string tmp = Path.Combine(Path.GetTempPath(), $"seed-{Guid.NewGuid()}");
Directory.CreateDirectory(tmp);
try
{
File.WriteAllText(Path.Combine(tmp, "battle-pass-levels.json"), "[]");
await new BattlePassImporter().ImportAsync(db, tmp);
int count = await db.BattlePassLevels.CountAsync();
Assert.That(count, Is.EqualTo(0));
}
finally { Directory.Delete(tmp, true); }
}
}

View File

@@ -7,11 +7,11 @@ using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Importers;
/// <summary>
/// Happy-path coverage for the 7 load-index importer classes introduced in Stage 9B
/// (RotationConfig, MyRotation, AvatarAbility, ArenaSeason, BattlePass, DailyLoginBonus,
/// Happy-path coverage for the load-index importer classes introduced in Stage 9B
/// (RotationConfig, MyRotation, AvatarAbility, ArenaSeason, DailyLoginBonus,
/// PreReleaseInfo). Each test instantiates the importer in isolation and verifies it inserts
/// rows from the corresponding seed file under <c>Data/seeds/</c>. Idempotency is spot-checked
/// in one test (BattlePass) to avoid duplicating the canonical 4-test set per importer.
/// rows from the corresponding seed file under <c>Data/seeds/</c>.
/// Idempotency, edge cases, and per-importer detail tests live in dedicated *ImporterTests files (e.g. BattlePassImporterTests).
/// </summary>
public class LoadIndexImporterTests
{
@@ -73,22 +73,6 @@ public class LoadIndexImporterTests
Assert.That(row!.FormatInfo, Is.Not.EqualTo("{}"), "format_info blob must be populated from seed");
}
[Test]
public async Task BattlePassImporter_writes_levels_and_is_idempotent()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int after1 = await db.BattlePassLevels.CountAsync();
await new BattlePassImporter().ImportAsync(db, SeedDir);
int after2 = await db.BattlePassLevels.CountAsync();
Assert.That(after1, Is.GreaterThan(0), "battle-pass-levels.json must produce rows");
Assert.That(after2, Is.EqualTo(after1), "rerun must be idempotent (no new rows)");
}
[Test]
public async Task DailyLoginBonusImporter_writes_bonus_rows()
{