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,71 @@
using System.Net;
using System.Net;
using System.Net.Http.Json;
using GameList.Tests.Support;
namespace GameList.Tests;
public class SuggestionTests
{
[Fact]
public async Task Player_cannot_exceed_five_suggestions()
{
using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("suggestor");
for (var i = 0; i < 5; i++)
{
var resp = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = $"Game {i}",
Genre = (string?)null,
Description = (string?)null,
ScreenshotUrl = (string?)null,
YoutubeUrl = (string?)null,
GameUrl = (string?)null,
MinPlayers = (int?)null,
MaxPlayers = (int?)null
});
resp.EnsureSuccessStatusCode();
}
var sixth = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = "Overflow",
Genre = (string?)null,
Description = (string?)null,
ScreenshotUrl = (string?)null,
YoutubeUrl = (string?)null,
GameUrl = (string?)null,
MinPlayers = (int?)null,
MaxPlayers = (int?)null
});
Assert.Equal(HttpStatusCode.BadRequest, sixth.StatusCode);
}
[Fact]
public async Task Unreachable_screenshot_url_is_rejected()
{
using var factory = new TestWebApplicationFactory();
factory.HttpHandler.SetResponder(_ => new HttpResponseMessage(HttpStatusCode.BadRequest));
var client = factory.CreateClientWithCookies();
await client.RegisterAsync("imgtester");
var response = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = "Needs image",
Genre = (string?)null,
Description = (string?)null,
ScreenshotUrl = "http://example.com/image.png",
YoutubeUrl = (string?)null,
GameUrl = (string?)null,
MinPlayers = (int?)null,
MaxPlayers = (int?)null
});
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
}