Files
SVSimServer/SVSim.UnitTests/Controllers/ArenaTwoPickBattleControllerTests.cs
gamer147 9776873073 fix(arena-tk2): include card_master_id in do_matching success response
The decompiled client's DoMatchingBase.SettingCardMasterId calls
jsonData["card_master_id"].ToInt() with no Keys.Contains guard when
matching_state ∈ {3004, 3007, 3011}. Omitting the field crashes the
client with KeyNotFoundException at Cute.NetworkManager+Connect.

Add CardMasterId to DoMatchingResponseDto with a default value of 1
(matching the /load/index response and prod captures). Extend the
controller test to assert the field is present.

Caught during the v1 smoke walk-through; full client log line:
  [Error: Unity Log] KeyNotFoundException: The given key was not
  present in the dictionary.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 00:52:57 -04:00

37 lines
1.6 KiB
C#

using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Controllers;
public class ArenaTwoPickBattleControllerTests
{
[Test]
public async Task DoMatching_AuthenticatedViewer_Returns3004WithBattleIdAndNodeUrl()
{
using var factory = new SVSimTestFactory();
var viewerId = await factory.SeedViewerAsync();
using var client = factory.CreateAuthenticatedClient(viewerId);
var req = new {
deck_no = 1L, need_init = 1, log = 1, excluded_field_id_list = new long[] { }, use_stage_select = 1, is_default_skin = 0,
viewer_id = "0", steam_id = 0, steam_session_ticket = "",
};
var resp = await client.PostAsync("/arena_two_pick_battle/do_matching", JsonContent.Create(req));
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
var body = await resp.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(body);
var root = doc.RootElement;
Assert.That(root.GetProperty("matching_state").GetInt32(), Is.EqualTo(3004));
var battleId = root.GetProperty("battle_id").GetString();
Assert.That(battleId, Is.Not.Null.And.Not.Empty);
var nodeUrl = root.GetProperty("node_server_url").GetString();
Assert.That(nodeUrl, Does.StartWith("ws://"));
// Required when matching_state ∈ {3004,3007,3011} per
// DoMatchingBase.SettingCardMasterId; client throws KeyNotFoundException without it.
Assert.That(root.GetProperty("card_master_id").GetInt32(), Is.EqualTo(1));
}
}