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(); // Matches prod wire format: host:port/socket.io/, no scheme prefix. Assert.That(nodeUrl, Does.Contain("/socket.io/")); Assert.That(nodeUrl, Does.Not.StartWith("ws://")); Assert.That(nodeUrl, Does.Not.StartWith("http://")); // 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)); } }