- Ajoute Testcontainers.PostgreSql v4.13.0\n- PostgreSqlContainerFixture: collection fixture xUnit avec postgres:17-alpine\n- HeimdallWebApplicationFactory: accepte connectionString pour vrai PostgreSQL\n- PostgresTestBase: classe de base pour tous les tests integration\n- Ajoute [Collection("Postgres")] aux 9 classes de test\n- Database:MigrateOnStartup active quand PostgreSQL est utilise\n- Programme le Hangfire (skip en test via isTesting)\n\nAvant: InMemory (pas de contraintes, comportement different)\nApres: Vrai PostgreSQL dans un container temporaire\n\nTests: 226/226 passed (61 integration avec vrai PostgreSQL)
82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Heimdall.IntegrationTests.Factories;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
public class EventsControllerTests : PostgresTestBase
|
|
{
|
|
private HttpClient? _cachedClient;
|
|
|
|
public EventsControllerTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
|
|
|
|
private async Task<HttpClient> AdminClient()
|
|
{
|
|
if (_cachedClient is not null) return _cachedClient;
|
|
_cachedClient = await Factory.CreateAdminClientAsync();
|
|
return _cachedClient;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateEvent_WithoutAuth_ReturnsUnauthorized()
|
|
{
|
|
// Events endpoint requires ApiKey auth (agents), not JWT
|
|
var client = Factory.CreateClient();
|
|
var response = await client.PostAsJsonAsync("api/events", new
|
|
{
|
|
cameraId = Guid.NewGuid(),
|
|
type = 0,
|
|
confidence = 0.95
|
|
});
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetEventById_RequiresAuth_ReturnsUnauthorized()
|
|
{
|
|
var client = Factory.CreateClient();
|
|
var response = await client.GetAsync($"api/events/{Guid.NewGuid()}");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task QueryEvents_RequiresAuth_ReturnsUnauthorized()
|
|
{
|
|
var client = Factory.CreateClient();
|
|
var response = await client.GetAsync("api/events");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetEventById_UnknownId_ReturnsNotFound()
|
|
{
|
|
var client = await AdminClient();
|
|
var response = await client.GetAsync($"api/events/{Guid.NewGuid()}");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.NotFound);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task QueryEvents_NoFilters_ReturnsOk()
|
|
{
|
|
var client = await AdminClient();
|
|
var response = await client.GetAsync("api/events?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
var content = await response.Content.ReadFromJsonAsync<JsonElement>();
|
|
content.GetProperty("items").GetArrayLength().ShouldBe(0);
|
|
content.GetProperty("totalCount").GetInt32().ShouldBe(0);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetRecentByCamera_UnknownCamera_ReturnsEmpty()
|
|
{
|
|
var client = await AdminClient();
|
|
var response = await client.GetAsync($"api/events/camera/{Guid.NewGuid()}");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
var content = await response.Content.ReadFromJsonAsync<JsonElement>();
|
|
content.GetArrayLength().ShouldBe(0);
|
|
}
|
|
}
|