fix(replay-tests): supply BaseRequest auth fields in PostAsJsonAsync bodies
Following the 216dcab fix that added [FromBody] BaseRequest _ to the
Info action, the existing tests' empty new {} payloads no longer satisfy
[ApiController] model validation (BaseRequest.ViewerId is non-nullable
string). Use the same EmptyBody() shape as RankBattleControllerTests
to mirror the production wire.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,18 @@ namespace SVSim.UnitTests.Controllers;
|
||||
|
||||
public class ReplayControllerTests
|
||||
{
|
||||
// Minimal BaseRequest-shaped body. The translation middleware (in prod) and the
|
||||
// [FromBody] BaseRequest _ binding (in tests) both require the auth fields to
|
||||
// be present even when their values are unused — same pattern as
|
||||
// RankBattleControllerTests.FinishBody. The actual viewer_id comes from the
|
||||
// session claim, not the body.
|
||||
private static object EmptyBody() => new
|
||||
{
|
||||
viewer_id = "0",
|
||||
steam_id = 0,
|
||||
steam_session_ticket = "",
|
||||
};
|
||||
|
||||
[Test]
|
||||
public async Task ReplayInfo_returns_empty_list_for_fresh_viewer()
|
||||
{
|
||||
@@ -18,7 +30,7 @@ public class ReplayControllerTests
|
||||
long viewerId = await factory.SeedViewerAsync(steamId: 76_561_198_000_000_001UL);
|
||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/replay/info", new { });
|
||||
var resp = await client.PostAsJsonAsync("/replay/info", EmptyBody());
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadFromJsonAsync<ReplayInfoResponseDto>();
|
||||
@@ -42,7 +54,7 @@ public class ReplayControllerTests
|
||||
}
|
||||
|
||||
var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var body = await client.PostAsJsonAsync("/replay/info", new { })
|
||||
var body = await client.PostAsJsonAsync("/replay/info", EmptyBody())
|
||||
.ContinueWith(t => t.Result.Content.ReadFromJsonAsync<ReplayInfoResponseDto>())
|
||||
.Unwrap();
|
||||
|
||||
@@ -66,7 +78,7 @@ public class ReplayControllerTests
|
||||
}
|
||||
|
||||
var client = factory.CreateAuthenticatedClient(viewerA);
|
||||
var body = await client.PostAsJsonAsync("/replay/info", new { })
|
||||
var body = await client.PostAsJsonAsync("/replay/info", EmptyBody())
|
||||
.ContinueWith(t => t.Result.Content.ReadFromJsonAsync<ReplayInfoResponseDto>())
|
||||
.Unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user