Add backend test harness with mock SQLite

This commit is contained in:
2026-02-05 17:46:56 +01:00
parent 87fa1974dd
commit 7e2d9ba9b8
11 changed files with 480 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
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<JsonElement>("/api/state");
Assert.Equal((int)Phase.Results, state.GetProperty("CurrentPhase").GetInt32());
Assert.True(state.GetProperty("resultsOpen").GetBoolean());
}
}