fix(pack): tutorial pack_open ThenIncludes OwnedItemEntry.Item

Without .ThenInclude(i => i.Item), the OwnedItemEntry.Item nav defaults to a
new ItemEntry() with Id=0 (project_ef_nav_include_pitfall), so the
FirstOrDefault(i => i.Item.Id == ticketItemId) lookup never matched. The
ticket was never decremented and reward_list omitted the post-state entry —
on the next /tutorial/pack_info the pack stayed visible and the client
re-clicked into plain /pack/open, which 501s on type_detail=5.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-28 20:15:31 -04:00
parent b50a884af9
commit ac077dfc13
4 changed files with 74 additions and 1 deletions

View File

@@ -40,6 +40,11 @@ public class PackControllerTests
await factory.SeedGlobalsAsync();
long viewerId = await factory.SeedViewerAsync(tutorialState: 41);
// Seed the starter ticket the gift_receive step would have granted. /tutorial/pack_open
// is supposed to decrement this count by `pack_number` (1) and emit a post-state entry
// into reward_list (per project_wire_reward_list_post_state).
await factory.SeedOwnedItemAsync(viewerId, itemId: 90001, count: 1, itemName: "Starter Legendary Ticket");
// Pack 99047 (starter legendary) has base_pack_id=90001. The minimal card seed only
// creates set 10001, so we seed set 90001 explicitly for the pool resolver.
using (var scope = factory.Services.CreateScope())
@@ -80,6 +85,23 @@ public class PackControllerTests
"Starter pack 99047/990047 delivers 8 cards (child_gacha.card_count=8).");
Assert.That(await factory.GetViewerTutorialStateAsync(viewerId), Is.EqualTo(100));
// Ticket decrement: the legendary starter ticket (90001) should be consumed.
Assert.That(await factory.GetOwnedItemCountAsync(viewerId, 90001), Is.EqualTo(0),
"Tutorial pack_open must decrement the gating ticket; otherwise /tutorial/pack_info " +
"keeps showing the pack and the client re-clicks into /pack/open (501 on type_detail=5).");
// reward_list must carry a post-state item entry for the ticket. RewardType=4 (Item),
// RewardId=90001, RewardNum=0 (post-state total, NOT delta).
var rewardList = root.GetProperty("reward_list");
var ticketEntry = rewardList.EnumerateArray()
.FirstOrDefault(e => e.GetProperty("reward_type").GetInt32() == 4
&& e.GetProperty("reward_id").GetInt64() == 90001);
Assert.That(ticketEntry.ValueKind, Is.Not.EqualTo(JsonValueKind.Undefined),
"reward_list must include a type=4 entry for the consumed ticket (90001) so the " +
"client's _userItemDict updates immediately — project_wire_reward_list_post_state.");
Assert.That(ticketEntry.GetProperty("reward_num").GetInt32(), Is.EqualTo(0),
"RewardNum is the post-state TOTAL, not the delta consumed.");
}
[Test]