feat(import): import decks; remove obsolete default-deck cloning

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-29 18:42:07 -04:00
parent d7e5557d61
commit 4965851238
3 changed files with 197 additions and 83 deletions

View File

@@ -223,4 +223,123 @@ public class AdminControllerTests
Assert.That(await factory.GetOwnedItemCountAsync(viewerId, 88888), Is.EqualTo(0),
"Unknown item master id must not be inserted.");
}
[Test]
public async Task ImportViewer_imports_deck_with_correct_format_and_skips_unknown_cards()
{
using var factory = new SVSimTestFactory();
const ulong steamId = 76_561_198_111_222_337UL;
long viewerId = await factory.SeedViewerAsync(steamId: steamId);
int classId, leaderSkinId; long sleeveId;
using (var scope = factory.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
classId = (await db.Classes.FirstAsync()).Id;
sleeveId = (await db.Sleeves.FirstAsync()).Id;
leaderSkinId = (await db.LeaderSkins.FirstAsync()).Id;
}
using var client = factory.CreateClient();
var response = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
{
SteamId = steamId,
Decks = new List<ImportDeck>
{
new()
{
DeckFormat = 1, // wire Rotation
DeckNo = 1,
DeckName = "Imported Rotation",
ClassId = classId,
SleeveId = sleeveId,
LeaderSkinId = leaderSkinId,
CardIdArray = new List<long> { 10001001L, 10001001L, 99999999L }, // last is unknown
}
}
});
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK),
await response.Content.ReadAsStringAsync());
var body = await response.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
Assert.That(body!.SkippedCardCount, Is.EqualTo(1), "Unknown deck card 99999999 counts as skipped.");
using var scope2 = factory.Services.CreateScope();
var db2 = scope2.ServiceProvider.GetRequiredService<SVSimDbContext>();
var stored = await db2.Viewers
.Include(v => v.Decks).ThenInclude(d => d.Cards).ThenInclude(c => c.Card)
.FirstAsync(v => v.Id == viewerId);
var deck = stored.Decks.Single(d => d.Name == "Imported Rotation");
Assert.That(deck.Format, Is.EqualTo(Format.Rotation));
Assert.That(deck.Cards.Single().Card.Id, Is.EqualTo(10001001L));
Assert.That(deck.Cards.Single().Count, Is.EqualTo(2), "Two copies of 10001001 grouped.");
}
[Test]
public async Task ImportViewer_myrotation_deck_gets_rotation_id()
{
using var factory = new SVSimTestFactory();
await factory.SeedGlobalsAsync(); // populates MyRotationSettings
const ulong steamId = 76_561_198_111_222_338UL;
long viewerId = await factory.SeedViewerAsync(steamId: steamId);
int classId, leaderSkinId; long sleeveId;
using (var scope = factory.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
classId = (await db.Classes.FirstAsync()).Id;
sleeveId = (await db.Sleeves.FirstAsync()).Id;
leaderSkinId = (await db.LeaderSkins.FirstAsync()).Id;
}
using var client = factory.CreateClient();
var response = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
{
SteamId = steamId,
Decks = new List<ImportDeck>
{
new()
{
DeckFormat = 5, // wire MyRotation
DeckNo = 1,
DeckName = "Imported MyRot",
ClassId = classId,
SleeveId = sleeveId,
LeaderSkinId = leaderSkinId,
CardIdArray = new List<long> { 10001001L },
}
}
});
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK),
await response.Content.ReadAsStringAsync());
var body = await response.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
using var scope2 = factory.Services.CreateScope();
var db2 = scope2.ServiceProvider.GetRequiredService<SVSimDbContext>();
var deck = await db2.Set<SVSim.Database.Models.ShadowverseDeckEntry>()
.FirstAsync(d => d.Name == "Imported MyRot");
Assert.That(deck.Format, Is.EqualTo(Format.MyRotation));
Assert.That(deck.MyRotationId, Is.Not.Null.And.Not.Empty,
"MyRotation decks need a rotation id or the client NREs on click.");
}
[Test]
public async Task ImportViewer_fresh_user_has_no_decks_when_none_imported()
{
using var factory = new SVSimTestFactory();
using var client = factory.CreateClient();
var response = await client.PostAsJsonAsync("/admin/import_viewer", new ImportViewerRequest
{
SteamId = 76_561_198_111_222_339UL,
DisplayName = "No Decks"
});
var body = await response.Content.ReadFromJsonAsync<ImportViewerResponse>(JsonOptions);
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var stored = await db.Viewers.Include(v => v.Decks).FirstAsync(v => v.Id == body!.ViewerId);
Assert.That(stored.Decks, Is.Empty,
"Default-deck cloning was removed; a fresh viewer with no imported decks has none.");
}
}