feat(inventory): TrySpendAsync covers all 4 wallets + freeplay
Crystal/Rupy/RedEther freeplay no-op (returns configured amount, balance unchanged); SpotPoint always real. Insufficient returns current balance; success returns post-deduction balance. SVSimTestFactory gains freeplayEnabled ctor overload that upserts the Freeplay GameConfigSection row after EnsureSeedData. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -28,9 +28,11 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
private long _nextSeededShortUdid = 400_000_001;
|
||||
private readonly bool _freeplayEnabled;
|
||||
|
||||
public SVSimTestFactory()
|
||||
public SVSimTestFactory(bool freeplayEnabled = false)
|
||||
{
|
||||
_freeplayEnabled = freeplayEnabled;
|
||||
// SQLite :memory: lives only as long as a connection is open — keep ours open for the
|
||||
// factory's lifetime so the DbContext can reattach to the same DB across scopes.
|
||||
_connection = new SqliteConnection("DataSource=:memory:");
|
||||
@@ -59,6 +61,19 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
|
||||
db.Database.EnsureCreated();
|
||||
db.EnsureSeedDataAsync().GetAwaiter().GetResult();
|
||||
|
||||
if (_freeplayEnabled)
|
||||
{
|
||||
using var seedScope = host.Services.CreateScope();
|
||||
var seedDb = seedScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
const string freeplayJson = "{\"Enabled\":true,\"CurrencyAmount\":99999,\"CardCopies\":3}";
|
||||
var existing = seedDb.GameConfigs.FirstOrDefault(s => s.SectionName == "Freeplay");
|
||||
if (existing is null)
|
||||
seedDb.GameConfigs.Add(new SVSim.Database.Models.GameConfigSection { SectionName = "Freeplay", ValueJson = freeplayJson });
|
||||
else
|
||||
existing.ValueJson = freeplayJson;
|
||||
seedDb.SaveChanges();
|
||||
}
|
||||
|
||||
// Reference data is no longer HasData-seeded; load the CSVs via the same importer
|
||||
// production uses so tests exercise the same code path. CardCosmeticRewards skipped —
|
||||
// FK to Cards would reject every row against the minimal 3-card test seed below.
|
||||
|
||||
Reference in New Issue
Block a user