From b44354315a18c12cd9afa95799f0719f18908645 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Wed, 10 Jun 2026 08:06:36 -0400 Subject: [PATCH] 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 --- .../Controllers/ReplayControllerTests.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/SVSim.UnitTests/Controllers/ReplayControllerTests.cs b/SVSim.UnitTests/Controllers/ReplayControllerTests.cs index 5ede95e..da63f6f 100644 --- a/SVSim.UnitTests/Controllers/ReplayControllerTests.cs +++ b/SVSim.UnitTests/Controllers/ReplayControllerTests.cs @@ -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(); @@ -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()) .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()) .Unwrap();