fix(pack): /pack/info reads ItemId via shadow FK, not nav property
PackController.Info's ownedItemsByItemId projection used `i.Item.Id` to key the dict — EF translates that to the FK column today, but any future model change that breaks the nav→column mapping would fall back to client eval and collapse every key to 0 (the default Item constructor's Id), silently hiding every tutorial pack via item_number=0. EF.Property<int> reads the shadow FK directly and is robust to nav changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,38 @@ namespace SVSim.UnitTests.Controllers;
|
||||
|
||||
public class PackControllerTests
|
||||
{
|
||||
[Test]
|
||||
public async Task PackInfo_item_number_reflects_owned_ticket_count()
|
||||
{
|
||||
// Verifies the ownedItemsByItemId projection in PackController.Info — the dict that
|
||||
// drives child_gacha_info.item_number. Tutorial flow filters packs by item_number > 0,
|
||||
// so a regression on the projection (e.g. nav-eval collapsing to 0) silently hides
|
||||
// any pack that requires a ticket.
|
||||
using var factory = new SVSimTestFactory();
|
||||
await factory.SeedGlobalsAsync();
|
||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 41);
|
||||
|
||||
// Seed item 90001 with count 7 — the legendary starter ticket the tutorial gift grants.
|
||||
await factory.SeedOwnedItemAsync(viewerId, itemId: 90001, count: 7, itemName: "Starter Legendary Ticket");
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var json = """{"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||
var response = await client.PostAsync("/pack/info",
|
||||
new StringContent(json, Encoding.UTF8, "application/json"));
|
||||
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
|
||||
// Find pack 99047 (the starter legendary) and verify its child gacha reports item_number=7.
|
||||
var pack99047 = doc.RootElement.GetProperty("pack_config_list").EnumerateArray()
|
||||
.First(p => p.GetProperty("parent_gacha_id").GetInt32() == 99047);
|
||||
var childWithTicket = pack99047.GetProperty("child_gacha_info").EnumerateArray()
|
||||
.First(c => c.TryGetProperty("item_id", out var iid) && iid.GetString() == "90001");
|
||||
Assert.That(childWithTicket.GetProperty("item_number").GetInt32(), Is.EqualTo(7),
|
||||
"child_gacha_info.item_number must reflect the viewer's owned count of the gating " +
|
||||
"item; client filters tutorial packs on item_number > 0.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TutorialPackInfo_returns_same_list_as_pack_info()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user