Add backend test harness with mock SQLite
This commit is contained in:
35
GameList.Tests/ResultsTests.cs
Normal file
35
GameList.Tests/ResultsTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using GameList.Tests.Support;
|
||||
|
||||
namespace GameList.Tests;
|
||||
|
||||
public class ResultsTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Results_available_after_admin_unlocks()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var admin = factory.CreateClientWithCookies();
|
||||
await admin.RegisterAsync("admin", admin: true);
|
||||
|
||||
var player = factory.CreateClientWithCookies();
|
||||
await player.RegisterAsync("player");
|
||||
var suggestionId = await player.CreateSuggestionAsync("ResultGame");
|
||||
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
await player.PostAsJsonAsync("/api/votes", new { SuggestionId = suggestionId, Score = 8 });
|
||||
await player.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
|
||||
await admin.PostAsJsonAsync("/api/admin/results", new { resultsOpen = true });
|
||||
|
||||
await player.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
|
||||
var results = await player.GetFromJsonAsync<JsonElement>("/api/results");
|
||||
|
||||
Assert.True(results.GetArrayLength() >= 1);
|
||||
var first = results[0];
|
||||
Assert.Equal("ResultGame", first.GetProperty("Name").GetString());
|
||||
Assert.Equal(8, (int)first.GetProperty("Average").GetDouble());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user