- 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
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Net.Http.Json;
|
|
using Heimdall.IntegrationTests.Factories;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
public class SitesControllerTests : IClassFixture<HeimdallWebApplicationFactory>
|
|
{
|
|
private readonly HeimdallWebApplicationFactory _factory;
|
|
|
|
public SitesControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
|
|
|
|
[Fact]
|
|
public async Task GetSites_WithoutAuth_ReturnsUnauthorized()
|
|
{
|
|
var client = _factory.CreateClient();
|
|
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateSite_WithAuth_ReturnsOk()
|
|
{
|
|
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 _factory.CreateAdminClientAsync();
|
|
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
}
|
|
}
|