36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
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());
|
|
}
|
|
}
|