IMatchingBridge.RegisterPendingBattle now takes a MatchContext; PendingBattle carries it; BattleSession stores it. ArenaTwoPickBattleController builds ctx from IMatchContextBuilder. ScriptedLifecycle still uses ScriptedProfiles for the player half — Tasks 5/6 migrate the lifecycle. Existing tests updated: MatchingBridgeTests, BattleNodeFlowTests, InMemoryBattleSessionStoreTests, BattleSessionDispatchTests, BattleSession PumpTests, ArenaTwoPickBattleControllerTests (which now seeds a TK2 run + adds a no-active-run 400 case). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
3.5 KiB
C#
83 lines
3.5 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SVSim.Database;
|
|
using SVSim.Database.Models;
|
|
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();
|
|
await SeedCompleteTwoPickRunAsync(factory, viewerId);
|
|
|
|
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.Contain("/socket.io/"));
|
|
Assert.That(nodeUrl, Does.Not.StartWith("ws://"));
|
|
Assert.That(nodeUrl, Does.Not.StartWith("http://"));
|
|
Assert.That(root.GetProperty("card_master_id").GetInt32(), Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DoMatching_NoActiveRun_Returns400WithErrorCode()
|
|
{
|
|
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.BadRequest));
|
|
var body = await resp.Content.ReadAsStringAsync();
|
|
using var doc = JsonDocument.Parse(body);
|
|
Assert.That(doc.RootElement.GetProperty("error_code").GetString(),
|
|
Is.EqualTo("arena_two_pick_no_active_run"));
|
|
}
|
|
|
|
private static async Task SeedCompleteTwoPickRunAsync(SVSimTestFactory factory, long viewerId)
|
|
{
|
|
using var scope = factory.Services.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
|
var deck = Enumerable.Range(1, 30).Select(i => 100_011_000L + i).ToList();
|
|
db.ViewerArenaTwoPickRuns.Add(new ViewerArenaTwoPickRun
|
|
{
|
|
ViewerId = viewerId,
|
|
EntryId = 1,
|
|
ClassId = 1,
|
|
LeaderSkinId = 1,
|
|
SelectedCardIdsJson = JsonSerializer.Serialize(deck),
|
|
IsSelectCompleted = true,
|
|
MaxBattleCount = 5,
|
|
CandidateClassIdsJson = "[1,2,3]",
|
|
PendingPickSetsJson = "[]",
|
|
ResultListJson = "[]",
|
|
NextCandidateId = 1,
|
|
});
|
|
await db.SaveChangesAsync();
|
|
}
|
|
}
|