Adds S3-compatible snapshot storage (Alarik) with AWS Signature V4, upload, thumbnail, and delete operations. Backfills Phase 2 & 3 with 27 new tests covering camera assignment strategies, event CRUD with filtering, snapshot attachment, and API contract validation. - SnapshotService with S3 REST API via HttpClient + SigV4 signing - 10 unit tests for CameraAssignmentService (assign, release, failover, history) - 9 unit tests for CameraEventService (create, query, filter, delete, snapshot) - 8 integration tests for AssignmentsController + EventsController - SnapshotService registration with 5-min timeout HTTP client
83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Heimdall.IntegrationTests.Factories;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
public class EventsControllerTests : IClassFixture<HeimdallWebApplicationFactory>
|
|
{
|
|
private readonly HeimdallWebApplicationFactory _factory;
|
|
private HttpClient? _cachedClient;
|
|
|
|
public EventsControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
|
|
|
|
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);
|
|
}
|
|
}
|