Practice/deck editing mostly there

This commit is contained in:
gamer147
2026-05-24 00:17:28 -04:00
parent 21b97269ff
commit bdff142d16
14 changed files with 588 additions and 59 deletions

View File

@@ -55,12 +55,14 @@ public class DeckControllerTests
using var doc = JsonDocument.Parse(body);
var decks = doc.RootElement.GetProperty("user_deck_list");
Assert.That(decks.GetArrayLength(), Is.EqualTo(2),
"Only Rotation-format decks should be returned for a Rotation request.");
var names = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i].GetProperty("deck_name").GetString())
// Real decks are tagged is_complete_deck=1; padding placeholders are 0.
var realNames = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i])
.Where(d => d.GetProperty("is_complete_deck").GetInt32() == 1)
.Select(d => d.GetProperty("deck_name").GetString())
.ToList();
Assert.That(names, Is.EquivalentTo(new[] { "Slot 1", "Slot 2" }));
Assert.That(realNames, Is.EquivalentTo(new[] { "Slot 1", "Slot 2" }),
"Only Rotation-format decks should be returned for a Rotation request.");
}
[Test]
@@ -78,8 +80,12 @@ public class DeckControllerTests
using var doc = JsonDocument.Parse(body);
var decks = doc.RootElement.GetProperty("user_deck_list");
Assert.That(decks.GetArrayLength(), Is.EqualTo(1));
Assert.That(decks[0].GetProperty("deck_name").GetString(), Is.EqualTo("Unlimited Deck"));
var realDecks = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i])
.Where(d => d.GetProperty("is_complete_deck").GetInt32() == 1)
.ToList();
Assert.That(realDecks.Count, Is.EqualTo(1));
Assert.That(realDecks[0].GetProperty("deck_name").GetString(), Is.EqualTo("Unlimited Deck"));
}
[Test]
@@ -96,7 +102,55 @@ public class DeckControllerTests
using var doc = JsonDocument.Parse(body);
var decks = doc.RootElement.GetProperty("user_deck_list");
Assert.That(decks.GetArrayLength(), Is.EqualTo(0));
var realDeckCount = Enumerable.Range(0, decks.GetArrayLength())
.Count(i => decks[i].GetProperty("is_complete_deck").GetInt32() == 1);
Assert.That(realDeckCount, Is.EqualTo(0));
}
[Test]
public async Task MyList_pads_response_to_max_deck_slots_with_empty_placeholders()
{
// The client only renders a "New Deck" tile by converting the first response entry whose
// card_id_array is [] into a CreateNew slot (DeckUI.DeckViewData.CreateDeckViewList).
// Prod always pads the deck list to the per-format cap (36 in the 2026-05-23 capture)
// with empty placeholders. Without padding, the button never appears.
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync();
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1, "Slot 1");
await factory.SeedDeckAsync(viewerId, Format.Rotation, 2, "Slot 2");
using var client = factory.CreateAuthenticatedClient(viewerId);
var response = await client.PostAsync("/deck/my_list", JsonBody(DeckFormatRequestJson(Format.Rotation)));
var body = await response.Content.ReadAsStringAsync();
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK), body);
using var doc = JsonDocument.Parse(body);
var decks = doc.RootElement.GetProperty("user_deck_list");
Assert.That(decks.GetArrayLength(), Is.EqualTo(36),
"Response should pad to MaxDeckSlots (36) so the client can render the New Deck tile.");
// Real decks have is_complete_deck=1; placeholders have is_complete_deck=0. This is the
// distinguishing marker the client itself uses (DeckData.is_complete_deck in DeckData.cs).
var empties = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i])
.Where(d => d.GetProperty("is_complete_deck").GetInt32() == 0)
.ToList();
Assert.That(empties.Count, Is.EqualTo(34),
"Two real decks + 34 empty placeholders = 36 slots.");
var firstEmpty = empties[0];
Assert.That(firstEmpty.GetProperty("deck_name").GetString(), Is.EqualTo(""));
Assert.That(firstEmpty.GetProperty("card_id_array").GetArrayLength(), Is.EqualTo(0));
Assert.That(firstEmpty.GetProperty("class_id").GetInt32(), Is.EqualTo(1));
Assert.That(firstEmpty.GetProperty("sleeve_id").GetInt32(), Is.EqualTo(3000011));
Assert.That(firstEmpty.GetProperty("is_available_deck").GetInt32(), Is.EqualTo(1));
// Padded slot numbers must not collide with real ones, and together they must cover [1..36].
var allDeckNos = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i].GetProperty("deck_no").GetInt32())
.OrderBy(n => n)
.ToList();
Assert.That(allDeckNos, Is.EqualTo(Enumerable.Range(1, 36).ToList()));
}
// ---- get_empty_deck_number ----
@@ -234,12 +288,13 @@ public class DeckControllerTests
var body = await response.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(body);
var decks = doc.RootElement.GetProperty("user_deck_list");
Assert.That(decks.GetArrayLength(), Is.EqualTo(2),
"/deck/update should hand back the full refreshed list, saving the client a follow-up.");
var names = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i].GetProperty("deck_name").GetString())
var realNames = Enumerable.Range(0, decks.GetArrayLength())
.Select(i => decks[i])
.Where(d => d.GetProperty("is_complete_deck").GetInt32() == 1)
.Select(d => d.GetProperty("deck_name").GetString())
.ToList();
Assert.That(names, Is.EquivalentTo(new[] { "Existing", "Second" }));
Assert.That(realNames, Is.EquivalentTo(new[] { "Existing", "Second" }),
"/deck/update should hand back the full refreshed list, saving the client a follow-up.");
}
// ---- single-field mutations ----