fix(tests): InMemory DB isolation + refactor test helpers

- 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
This commit is contained in:
Arnaud Dartois committed 2026-07-17 13:15:25 +00:00
1 parent 129bcfa9d7
commit da123ec544
60 files changed
+148 -59912

No files matched your search

@@ -1,6 +1,4 @@
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using Heimdall.IntegrationTests.Factories;
using Shouldly;
@@ -9,15 +7,8 @@ namespace Heimdall.IntegrationTests.Controllers;
public class SitesControllerTests : IClassFixture<HeimdallWebApplicationFactory>
{
private readonly HeimdallWebApplicationFactory _factory;
private static readonly JsonSerializerOptions Json = new()
{
PropertyNameCaseInsensitive = true
};
public SitesControllerTests(HeimdallWebApplicationFactory factory)
{
_factory = factory;
}
public SitesControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
[Fact]
public async Task GetSites_WithoutAuth_ReturnsUnauthorized()
@@ -30,44 +21,21 @@ public class SitesControllerTests : IClassFixture<HeimdallWebApplicationFactory>
[Fact]
public async Task CreateSite_WithAuth_ReturnsOk()
{
var client = await CreateAuthenticatedAdminClient();
var client = await _factory.CreateAdminClientAsync();
var response = await client.PostAsJsonAsync("api/sites", new
{
name = "Site Test",
address = "Paris",
timezone = "Europe/Paris"
});
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
}
[Fact]
public async Task ListSites_WithAuth_ReturnsOk()
{
var client = await CreateAuthenticatedAdminClient();
var client = await _factory.CreateAdminClientAsync();
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
}
private async Task<HttpClient> CreateAuthenticatedAdminClient()
{
var client = _factory.CreateClient();
// Login with seeded admin user
var loginResponse = await client.PostAsJsonAsync("api/auth/login", new
{
email = "testadmin@heimdall.test",
password = "TestAdmin123!"
});
var content = await loginResponse.Content
.ReadFromJsonAsync<AuthTestResponse>(Json);
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", content!.AccessToken);
return client;
}
}