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,4 +1,3 @@
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using Heimdall.IntegrationTests.Factories;
@@ -15,7 +14,7 @@ public class UsersControllerTests : IClassFixture<HeimdallWebApplicationFactory>
[Fact]
public async Task ListUsers_WithAdminAuth_ReturnsOk()
{
var client = await CreateAdminClient();
var client = await _factory.CreateAdminClientAsync();
var response = await client.GetAsync("api/users?page=1&pageSize=20");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
}
@@ -23,7 +22,7 @@ public class UsersControllerTests : IClassFixture<HeimdallWebApplicationFactory>
[Fact]
public async Task CreateUser_WithAdminAuth_ReturnsOk()
{
var client = await CreateAdminClient();
var client = await _factory.CreateAdminClientAsync();
var response = await client.PostAsJsonAsync("api/users", new
{
email = $"newuser-{Guid.NewGuid()}@heimdall.test",
@@ -37,8 +36,7 @@ public class UsersControllerTests : IClassFixture<HeimdallWebApplicationFactory>
[Fact]
public async Task LockUser_WithAdminAuth_ReturnsOk()
{
var client = await CreateAdminClient();
var client = await _factory.CreateAdminClientAsync();
var createResponse = await client.PostAsJsonAsync("api/users", new
{
email = $"lockuser-{Guid.NewGuid()}@heimdall.test",
@@ -56,8 +54,7 @@ public class UsersControllerTests : IClassFixture<HeimdallWebApplicationFactory>
[Fact]
public async Task ResetPassword_WithAdminAuth_ReturnsTemporaryPassword()
{
var client = await CreateAdminClient();
var client = await _factory.CreateAdminClientAsync();
var createResponse = await client.PostAsJsonAsync("api/users", new
{
email = $"resetpwd-{Guid.NewGuid()}@heimdall.test",
@@ -74,18 +71,4 @@ public class UsersControllerTests : IClassFixture<HeimdallWebApplicationFactory>
var resetContent = await resetResponse.Content.ReadFromJsonAsync<JsonElement>();
resetContent.GetProperty("temporaryPassword").GetString().ShouldNotBeNullOrEmpty();
}
private async Task<HttpClient> CreateAdminClient()
{
var client = _factory.CreateClient();
var loginResponse = await client.PostAsJsonAsync("api/auth/login", new
{
email = "testadmin@heimdall.test",
password = "TestAdmin123!"
});
var content = await loginResponse.Content.ReadFromJsonAsync<AuthTestResponse>();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", content!.AccessToken);
return client;
}
}