feat(mvp): complete Blazor UI + User Management + integration tests
This commit is contained in:
1 parent
b217c932e8
commit
38816aec8a
26 files changed
+1893
-45
No files matched your search
@@ -0,0 +1,73 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Heimdall.IntegrationTests.Factories;
|
||||
using Shouldly;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
[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 CreateAuthenticatedAdminClient();
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user