using System.Net; using System.Net; using System.Net.Http.Json; using GameList.Tests.Support; namespace GameList.Tests; public class VoteTests { [Fact] public async Task Finalizing_votes_blocks_further_changes() { using var factory = new TestWebApplicationFactory(); var client = factory.CreateClientWithCookies(); await client.RegisterAsync("voter"); var suggestionId = await client.CreateSuggestionAsync("VoteGame"); await client.PostAsJsonAsync("/api/me/phase/next", new { }); var vote = await client.PostAsJsonAsync("/api/votes", new { SuggestionId = suggestionId, Score = 7 }); vote.EnsureSuccessStatusCode(); var finalize = await client.PostAsJsonAsync("/api/votes/finalize", new { Final = true }); finalize.EnsureSuccessStatusCode(); var change = await client.PostAsJsonAsync("/api/votes", new { SuggestionId = suggestionId, Score = 5 }); Assert.Equal(HttpStatusCode.BadRequest, change.StatusCode); } [Fact] public async Task Linked_votes_apply_to_all_linked_suggestions() { using var factory = new TestWebApplicationFactory(); var admin = factory.CreateClientWithCookies(); await admin.RegisterAsync("admin", admin: true); await admin.PostAsJsonAsync("/api/me/phase/next", new { }); var player = factory.CreateClientWithCookies(); await player.RegisterAsync("linker"); var id1 = await player.CreateSuggestionAsync("Game A"); var id2 = await player.CreateSuggestionAsync("Game B"); await player.PostAsJsonAsync("/api/me/phase/next", new { }); var linkResponse = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new { SourceSuggestionId = id1, TargetSuggestionId = id2 }); linkResponse.EnsureSuccessStatusCode(); var vote = await player.PostAsJsonAsync("/api/votes", new { SuggestionId = id1, Score = 9 }); vote.EnsureSuccessStatusCode(); var mine = await player.GetFromJsonAsync>("/api/votes/mine"); Assert.Equal(2, mine.Count); Assert.All(mine, v => Assert.Equal(9, v.Score)); } private record VoteRecord(int SuggestionId, int Score); }