Add comprehensive backend test suite and helper access
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using GameList.Tests.Support;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GameList.Tests;
|
||||
|
||||
@@ -29,6 +29,62 @@ public class VoteTests
|
||||
Assert.Equal(HttpStatusCode.BadRequest, change.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Score_out_of_range_rejected()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("score");
|
||||
var id = await client.CreateSuggestionAsync("RangeGame");
|
||||
await client.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/api/votes", new { SuggestionId = id, Score = 11 });
|
||||
Assert.Equal(HttpStatusCode.BadRequest, resp.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Invalid_suggestion_id_rejected()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("invalid");
|
||||
await client.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/api/votes", new { SuggestionId = 9999, Score = 5 });
|
||||
Assert.Equal(HttpStatusCode.BadRequest, resp.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Votes_require_display_name()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("anon");
|
||||
var id = await client.CreateSuggestionAsync("NeedName");
|
||||
|
||||
await factory.WithDbContextAsync(async db =>
|
||||
{
|
||||
var p = await db.Players.FirstAsync();
|
||||
p.DisplayName = null;
|
||||
await db.SaveChangesAsync();
|
||||
});
|
||||
|
||||
await client.PostAsJsonAsync("/api/me/phase/next", new { });
|
||||
var resp = await client.PostAsJsonAsync("/api/votes", new { SuggestionId = id, Score = 5 });
|
||||
Assert.Equal(HttpStatusCode.BadRequest, resp.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Finalize_only_in_vote_phase()
|
||||
{
|
||||
using var factory = new TestWebApplicationFactory();
|
||||
var client = factory.CreateClientWithCookies();
|
||||
await client.RegisterAsync("phase");
|
||||
|
||||
var resp = await client.PostAsJsonAsync("/api/votes/finalize", new { Final = true });
|
||||
Assert.Equal(HttpStatusCode.BadRequest, resp.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Linked_votes_apply_to_all_linked_suggestions()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user