Require suggestion before entering vote phase

This commit is contained in:
2026-02-07 13:18:55 +01:00
parent c3951b95ac
commit 9d3947714a
13 changed files with 77 additions and 18 deletions

View File

@@ -15,13 +15,13 @@ public class AdminTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.PostAsJsonAsync("/api/me/phase/next", new { }); // move to Vote
await admin.AdvanceToVoteAsync("Admin seed"); // move to Vote
var p1 = factory.CreateClientWithCookies();
await p1.RegisterAsync("alice");
var p2 = factory.CreateClientWithCookies();
await p2.RegisterAsync("bob");
await p2.PostAsJsonAsync("/api/me/phase/next", new { });
await p2.AdvanceToVoteAsync("Bob seed");
var s1 = await p1.CreateSuggestionAsync("A");
await p1.PostAsJsonAsync("/api/me/phase/next", new { });
@@ -111,7 +111,7 @@ public class AdminTests
var b = await player.CreateSuggestionAsync("Game B");
await player.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin link seed");
var same = await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
{
@@ -147,7 +147,7 @@ public class AdminTests
var a = await player.CreateSuggestionAsync("Game A");
var b = await player.CreateSuggestionAsync("Game B");
await player.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin unlink seed");
await admin.PostAsJsonAsync("/api/admin/link-suggestions", new
{
SourceSuggestionId = a,
@@ -269,7 +269,7 @@ public class AdminTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin vote status seed");
var p1 = factory.CreateClientWithCookies();
await p1.RegisterAsync("alice");
@@ -277,7 +277,7 @@ public class AdminTests
await p2.RegisterAsync("bob");
var s = await p1.CreateSuggestionAsync("Game");
await p1.PostAsJsonAsync("/api/me/phase/next", new { });
await p2.PostAsJsonAsync("/api/me/phase/next", new { });
await p2.AdvanceToVoteAsync("Bob vote seed");
await p1.PostAsJsonAsync("/api/votes", new
{
SuggestionId = s,
@@ -300,7 +300,7 @@ public class AdminTests
var p = factory.CreateClientWithCookies();
await p.RegisterAsync("player");
await p.PostAsJsonAsync("/api/me/phase/next", new { });
await p.AdvanceToVoteAsync("Player joker seed");
await p.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
var give = await admin.PostAsJsonAsync("/api/admin/joker", new { playerId = (await p.GetProfileIdAsync()) });
@@ -333,7 +333,7 @@ public class AdminTests
});
Assert.Equal(HttpStatusCode.BadRequest, beforeVotePhase.StatusCode);
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin link-phase seed");
await player.PostAsJsonAsync("/api/me/phase/next", new { });
await player.PostAsJsonAsync("/api/votes", new
@@ -373,9 +373,9 @@ public class AdminTests
var a = await p1.CreateSuggestionAsync("A");
var b = await p1.CreateSuggestionAsync("B");
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin unfinalize seed");
await p1.PostAsJsonAsync("/api/me/phase/next", new { });
await p2.PostAsJsonAsync("/api/me/phase/next", new { });
await p2.AdvanceToVoteAsync("P2 unfinalize seed");
await p1.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
await p2.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
@@ -400,7 +400,7 @@ public class AdminTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin unlink not-found seed");
var resp = await admin.PostAsJsonAsync("/api/admin/unlink-suggestions", new { suggestionId = 9999 });
resp.EnsureSuccessStatusCode();

View File

@@ -43,7 +43,7 @@ public class ResultsTests
await using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("user");
await client.PostAsJsonAsync("/api/me/phase/next", new { });
await client.AdvanceToVoteAsync("Results locked seed");
var resp = await client.GetAsync("/api/results");
Assert.Equal(System.Net.HttpStatusCode.BadRequest, resp.StatusCode);
}

View File

@@ -91,6 +91,7 @@ public class StateTests
await using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("advance");
await client.CreateSuggestionAsync("Advance game");
await factory.WithDbContextAsync(async db =>
{
@@ -121,6 +122,7 @@ public class StateTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.CreateSuggestionAsync("Admin game");
await admin.PostAsJsonAsync("/api/me/phase/next", new { }); // Vote
await factory.WithDbContextAsync(async db =>
@@ -143,6 +145,7 @@ public class StateTests
await using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("player");
await client.CreateSuggestionAsync("Player game");
var toVote = await client.PostAsync("/api/me/phase/next", JsonContent.Create(new { }));
toVote.EnsureSuccessStatusCode();
@@ -152,6 +155,20 @@ public class StateTests
Assert.Equal(HttpStatusCode.BadRequest, toResults.StatusCode);
}
[Fact]
public async Task Phase_next_from_suggest_requires_at_least_one_suggestion()
{
await using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("nosuggest");
var response = await client.PostAsJsonAsync("/api/me/phase/next", new { });
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
var me = await client.GetFromJsonAsync<JsonElement>("/api/me");
Assert.Equal(nameof(Phase.Suggest), me.GetProperty("currentPhase").GetString());
}
[Fact]
public async Task Admin_opening_results_moves_players_to_results_phase()
{
@@ -199,6 +216,7 @@ public class StateTests
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.CreateSuggestionAsync("Admin phase game");
await admin.PostAsJsonAsync("/api/me/phase/next", new { }); // to Vote
var back = await admin.PostAsJsonAsync("/api/me/phase/prev", new { });
back.EnsureSuccessStatusCode();

View File

@@ -602,6 +602,7 @@ public class SuggestionTests
});
await owner.PostAsJsonAsync("/api/me/phase/next", new { }); // Vote
await other.CreateSuggestionAsync("Other vote seed");
await other.PostAsJsonAsync("/api/me/phase/next", new { });
await other.PostAsJsonAsync("/api/votes", new
{

View File

@@ -49,4 +49,11 @@ internal static class TestClientExtensions
var me = await client.GetFromJsonAsync<JsonElement>("/api/me");
return Guid.Parse(me.GetProperty("id").GetString()!);
}
public static async Task AdvanceToVoteAsync(this HttpClient client, string suggestionName = "Seed game")
{
await client.CreateSuggestionAsync(suggestionName);
var response = await client.PostAsJsonAsync("/api/me/phase/next", new { });
response.EnsureSuccessStatusCode();
}
}

View File

@@ -78,7 +78,7 @@ public class VoteTests
await using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("invalid");
await client.PostAsJsonAsync("/api/me/phase/next", new { });
await client.AdvanceToVoteAsync("Invalid seed");
var resp = await client.PostAsJsonAsync("/api/votes", new
{
@@ -152,7 +152,7 @@ public class VoteTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin link seed");
var player = factory.CreateClientWithCookies();
await player.RegisterAsync("linker");
@@ -189,7 +189,7 @@ public class VoteTests
await using var factory = new TestWebApplicationFactory();
var admin = factory.CreateClientWithCookies();
await admin.RegisterAsync("admin", admin: true);
await admin.PostAsJsonAsync("/api/me/phase/next", new { });
await admin.AdvanceToVoteAsync("Admin chain seed");
var player = factory.CreateClientWithCookies();
await player.RegisterAsync("chain");