feat(replay): wire arena two-pick finish hook

Same pattern as rank-battle: DoMatching stashes context; Finish takes
it and records history + played-together. Opponent identity is left
as placeholder fields until the resolver carries it through.

Test seeds an active ViewerArenaTwoPickRun so RecordBattleResultAsync
does not throw no_active_run during the e2e flow.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-10 08:22:19 -04:00
parent 81aac701f4
commit 0996074287
2 changed files with 119 additions and 3 deletions

View File

@@ -173,6 +173,59 @@ public class ReplayControllerTests
Assert.That(infoBody!.ReplayList, Is.Empty);
}
[Test]
public async Task ArenaTwoPickFinish_writes_history_row_visible_from_ReplayInfo()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync(steamId: 76_561_198_000_000_001UL);
// Seed an active arena run so RecordBattleResultAsync doesn't throw no_active_run.
using (var scope = factory.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
db.Set<ViewerArenaTwoPickRun>().Add(new ViewerArenaTwoPickRun
{
ViewerId = viewerId,
EntryId = 1,
ClassId = 1,
MaxBattleCount = 5,
WinCount = 0,
LossCount = 0,
ResultListJson = "[]",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
});
await db.SaveChangesAsync();
}
var store = factory.Services.GetRequiredService<IBattleContextStore>();
store.Set(viewerId, new BattleContext(
BattleId: 999_888_777L,
BattleType: 4, DeckFormat: 10, TwoPickType: 0,
SelfClassId: 1, SelfSubClassId: 0, SelfCharaId: 1, SelfRotationId: "0",
OpponentViewerId: 0, OpponentName: "TwoPickBot", OpponentClassId: 2,
OpponentSubClassId: 0, OpponentCharaId: 1, OpponentCountryCode: "",
OpponentEmblemId: 0, OpponentDegreeId: 0, OpponentRotationId: "0",
BattleStartTime: DateTime.UtcNow));
var client = factory.CreateAuthenticatedClient(viewerId);
var finishResp = await client.PostAsJsonAsync("/arena_two_pick_battle/finish", new
{
viewer_id = "0",
steam_id = 0,
steam_session_ticket = "",
battle_result = 1,
});
Assert.That(finishResp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
var infoBody = await client.PostAsJsonAsync("/replay/info", EmptyBody())
.ContinueWith(t => t.Result.Content.ReadFromJsonAsync<ReplayInfoResponseDto>())
.Unwrap();
Assert.That(infoBody!.ReplayList, Has.Count.EqualTo(1));
Assert.That(infoBody.ReplayList[0].OpponentName, Is.EqualTo("TwoPickBot"));
}
private static ViewerBattleHistory NewRow(long viewerId, long battleId, DateTime createTime) => new()
{
ViewerId = viewerId,