- Fix: InMemory database name now unique per test factory instance (was using process-wide env var, now per-host config via UseSetting) - Refactor: all integration tests use shared TestHelpers.CreateAdminClientAsync - New: register-admin endpoint (test/dev only) creates Admin users directly - New: TestHelpers.cs with extension method for admin client creation - Cleanup: removed bootstrap template files, old Counter/Weather pages - Cleanup: simplified app.css with MudBlazor-only styles - Seed: demo admin + demo site created in Development mode
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Heimdall.IntegrationTests.Factories;
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
public static class TestHelpers
|
|
{
|
|
private static readonly JsonSerializerOptions Json = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
/// <summary>
|
|
/// Register a new admin user and return an authenticated HttpClient.
|
|
/// Uses the test-only register-admin endpoint.
|
|
/// </summary>
|
|
public static async Task<HttpClient> CreateAdminClientAsync(this HeimdallWebApplicationFactory factory)
|
|
{
|
|
var email = $"admin-{Guid.NewGuid()}@heimdall.test";
|
|
var client = factory.CreateClient();
|
|
|
|
var response = await client.PostAsJsonAsync("api/auth/register-admin", new
|
|
{
|
|
email,
|
|
password = "AdminPwd123!",
|
|
displayName = "Test Admin"
|
|
});
|
|
|
|
var content = await response.Content.ReadFromJsonAsync<JsonElement>(Json);
|
|
var token = content.GetProperty("accessToken").GetString()!;
|
|
|
|
client.DefaultRequestHeaders.Authorization =
|
|
new AuthenticationHeaderValue("Bearer", token);
|
|
|
|
return client;
|
|
}
|
|
}
|