using System.Net; using System.Net; using System.Net.Http.Json; using System.Text.Json; using GameList.Domain; using GameList.Tests.Support; namespace GameList.Tests; public class StateTests { [Fact] public async Task Cannot_advance_to_results_when_locked() { using var factory = new TestWebApplicationFactory(); var client = factory.CreateClientWithCookies(); await client.RegisterAsync("player"); var toVote = await client.PostAsync("/api/me/phase/next", JsonContent.Create(new { })); toVote.EnsureSuccessStatusCode(); var toResults = await client.PostAsync("/api/me/phase/next", JsonContent.Create(new { })); Assert.Equal(HttpStatusCode.BadRequest, toResults.StatusCode); } [Fact] public async Task Admin_opening_results_moves_players_to_results_phase() { using var factory = new TestWebApplicationFactory(); var admin = factory.CreateClientWithCookies(); await admin.RegisterAsync("admin", admin: true); var player = factory.CreateClientWithCookies(); await player.RegisterAsync("user"); var toggle = await admin.PostAsJsonAsync("/api/admin/results", new { resultsOpen = true }); toggle.EnsureSuccessStatusCode(); var state = await player.GetFromJsonAsync("/api/state"); Assert.Equal((int)Phase.Results, state.GetProperty("CurrentPhase").GetInt32()); Assert.True(state.GetProperty("resultsOpen").GetBoolean()); } }