2026-07-16 21:19:16 +00:00
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
using Heimdall.IntegrationTests.Factories;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
|
|
|
|
|
|
public class SitesControllerTests : IClassFixture<HeimdallWebApplicationFactory>
|
|
|
|
|
{
|
|
|
|
|
private readonly HeimdallWebApplicationFactory _factory;
|
|
|
|
|
|
2026-07-17 13:15:25 +00:00
|
|
|
public SitesControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
|
2026-07-16 21:19:16 +00:00
|
|
|
|
|
|
|
|
[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()
|
|
|
|
|
{
|
2026-07-17 13:15:25 +00:00
|
|
|
var client = await _factory.CreateAdminClientAsync();
|
2026-07-16 21:19:16 +00:00
|
|
|
var response = await client.PostAsJsonAsync("api/sites", new
|
|
|
|
|
{
|
|
|
|
|
name = "Site Test",
|
|
|
|
|
address = "Paris",
|
|
|
|
|
timezone = "Europe/Paris"
|
|
|
|
|
});
|
2026-07-19 20:53:48 +00:00
|
|
|
var body = await response.Content.ReadAsStringAsync();
|
|
|
|
|
await File.WriteAllTextAsync("/tmp/test-response-body.txt", body);
|
2026-07-16 21:19:16 +00:00
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ListSites_WithAuth_ReturnsOk()
|
|
|
|
|
{
|
2026-07-17 13:15:25 +00:00
|
|
|
var client = await _factory.CreateAdminClientAsync();
|
2026-07-16 21:19:16 +00:00
|
|
|
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
}
|