feat(rank-battle): AiStart returns ai_id + camelCase self/oppo_info
AiStartInternal builds the self MatchContext, picks a bot from IBotRoster, projects to the AiBattleStartResponseDto with camelCase wire keys (sleeveId, emblemId, ... — see ai-start.md). turnState=0 (player first) is the safe default per the ai-start.md TODO; live capture would clarify the enum. No deck → ai_id=-1 fallback (the documented "no AI assigned" sentinel per AIBattleStartTask.cs:21). 3 new wire-shape tests assert the camelCase keys land verbatim in the JSON, plus self/oppo info come from the right sources. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,76 @@ public class RankBattleControllerTests
|
||||
Assert.That(j3.GetProperty("battle_id").GetString(), Is.EqualTo(j2.GetProperty("battle_id").GetString()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AiStart_rotation_returns_ai_id_plus_self_oppo_info_camelCase_keys()
|
||||
{
|
||||
await using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync(displayName: "TestViewer");
|
||||
await factory.SeedGlobalsAsync();
|
||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", new { });
|
||||
var raw = await resp.Content.ReadAsStringAsync();
|
||||
|
||||
using var doc = JsonDocument.Parse(raw);
|
||||
var data = doc.RootElement;
|
||||
Assert.That(data.GetProperty("ai_id").GetInt32(), Is.InRange(4001, 4008));
|
||||
Assert.That(data.GetProperty("turnState").GetInt32(), Is.EqualTo(0));
|
||||
|
||||
// Literal camelCase wire-key checks — these MUST be present verbatim
|
||||
// (client uses JsonData.Keys.Contains).
|
||||
Assert.That(raw, Does.Contain("\"userName\""), "Wire key must be camelCase, not snake_case.");
|
||||
Assert.That(raw, Does.Contain("\"sleeveId\""));
|
||||
Assert.That(raw, Does.Contain("\"emblemId\""));
|
||||
Assert.That(raw, Does.Contain("\"degreeId\""));
|
||||
Assert.That(raw, Does.Contain("\"fieldId\""));
|
||||
Assert.That(raw, Does.Contain("\"isOfficial\""));
|
||||
Assert.That(raw, Does.Contain("\"classId\""));
|
||||
Assert.That(raw, Does.Contain("\"charaId\""));
|
||||
Assert.That(raw, Does.Contain("\"isMasterRank\""));
|
||||
Assert.That(raw, Does.Contain("\"battlePoint\""));
|
||||
Assert.That(raw, Does.Contain("\"masterPoint\""));
|
||||
// self_info / oppo_info / country_code stay snake_case (the outliers per ai-start.md).
|
||||
Assert.That(raw, Does.Contain("\"self_info\""));
|
||||
Assert.That(raw, Does.Contain("\"oppo_info\""));
|
||||
Assert.That(raw, Does.Contain("\"country_code\""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AiStart_self_info_reflects_caller_user_name()
|
||||
{
|
||||
await using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync(displayName: "Alice");
|
||||
await factory.SeedGlobalsAsync();
|
||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", new { });
|
||||
using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
|
||||
var selfInfo = doc.RootElement.GetProperty("self_info");
|
||||
|
||||
Assert.That(selfInfo.GetProperty("userName").GetString(), Is.EqualTo("Alice"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AiStart_oppo_info_reflects_roster_pick()
|
||||
{
|
||||
await using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync(displayName: "PlayerA");
|
||||
await factory.SeedGlobalsAsync();
|
||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, 1);
|
||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/ai_rotation_rank_battle/start", new { });
|
||||
using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
|
||||
var oppoInfo = doc.RootElement.GetProperty("oppo_info");
|
||||
|
||||
// BotRoster's stub names contain "AI" — verify the roster was consulted.
|
||||
Assert.That(oppoInfo.GetProperty("userName").GetString(), Does.Contain("AI"));
|
||||
Assert.That(oppoInfo.GetProperty("classId").GetInt32(), Is.InRange(1, 8));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Finish_emits_stubbed_zeros_with_battle_result_echo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user