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:
1 parent
129bcfa9d7
commit
da123ec544
60 files changed
+148
-59912
No files matched your search
@@ -151,21 +151,30 @@ using (var scope = app.Services.CreateScope())
|
||||
}
|
||||
}
|
||||
|
||||
// In Testing, seed an admin user for integration tests
|
||||
if (app.Environment.IsEnvironment("Testing"))
|
||||
// Seed demo admin in Development (NOT Testing — tests create their own users)
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
var testAdmin = await userManager.FindByEmailAsync("testadmin@heimdall.test");
|
||||
var testAdmin = await userManager.FindByEmailAsync("admin@heimdall.test");
|
||||
if (testAdmin is null)
|
||||
{
|
||||
testAdmin = new Heimdall.Domain.Entities.AppUser
|
||||
{
|
||||
UserName = "testadmin@heimdall.test",
|
||||
Email = "testadmin@heimdall.test",
|
||||
DisplayName = "Test Admin"
|
||||
UserName = "admin@heimdall.test",
|
||||
Email = "admin@heimdall.test",
|
||||
DisplayName = "Admin"
|
||||
};
|
||||
await userManager.CreateAsync(testAdmin, "TestAdmin123!");
|
||||
await userManager.CreateAsync(testAdmin, "Admin123!");
|
||||
await userManager.AddToRoleAsync(testAdmin, AppRoles.Admin);
|
||||
}
|
||||
|
||||
var demoDb = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var demoSite = await demoDb.Sites.FirstOrDefaultAsync(s => s.Name == "Site Démo");
|
||||
if (demoSite is null)
|
||||
{
|
||||
demoSite = new Heimdall.Domain.Entities.Site("Site Démo", "Paris", "Europe/Paris");
|
||||
demoDb.Sites.Add(demoSite);
|
||||
await demoDb.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user