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,46 @@
using System.Net.Http.Json;
using System.Text.Json;
namespace GameList.Tests.Support;
internal static class TestClientExtensions
{
public static Task<HttpResponseMessage> RegisterAsync(this HttpClient client, string username, bool admin = false)
{
return client.PostAsJsonAsync("/api/auth/register", new
{
Username = username,
Password = "Pass123!",
DisplayName = $"{username}-name",
AdminKey = admin ? "admin-key" : null
});
}
public static Task<HttpResponseMessage> LoginAsync(this HttpClient client, string username, string password)
{
return client.PostAsJsonAsync("/api/auth/login", new
{
Username = username,
Password = password
});
}
public static async Task<int> CreateSuggestionAsync(this HttpClient client, string name)
{
var response = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = name,
Genre = "Coop",
Description = (string?)null,
ScreenshotUrl = (string?)null,
YoutubeUrl = (string?)null,
GameUrl = (string?)null,
MinPlayers = (int?)null,
MaxPlayers = (int?)null
});
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadFromJsonAsync<JsonElement>();
return json.GetProperty("Id").GetInt32();
}
}