2026-07-19 13:14:05 +00:00
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Heimdall.IntegrationTests.Factories;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
|
|
2026-07-21 10:24:11 +00:00
|
|
|
public class AssignmentsControllerTests : PostgresTestBase
|
2026-07-19 13:14:05 +00:00
|
|
|
{
|
|
|
|
|
private HttpClient? _cachedClient;
|
|
|
|
|
|
2026-07-21 10:24:11 +00:00
|
|
|
public AssignmentsControllerTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
|
2026-07-19 13:14:05 +00:00
|
|
|
|
|
|
|
|
private async Task<HttpClient> AdminClient()
|
|
|
|
|
{
|
|
|
|
|
if (_cachedClient is not null) return _cachedClient;
|
2026-07-21 10:24:11 +00:00
|
|
|
_cachedClient = await Factory.CreateAdminClientAsync();
|
2026-07-19 13:14:05 +00:00
|
|
|
return _cachedClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task AssignCamera_RequiresAuth_ReturnsUnauthorized()
|
|
|
|
|
{
|
2026-07-21 10:24:11 +00:00
|
|
|
var client = Factory.CreateClient();
|
2026-07-19 13:14:05 +00:00
|
|
|
var response = await client.PostAsJsonAsync("api/assignments", new
|
|
|
|
|
{
|
|
|
|
|
cameraId = Guid.NewGuid(),
|
|
|
|
|
agentId = Guid.NewGuid(),
|
|
|
|
|
reason = "test"
|
|
|
|
|
});
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task AssignCamera_UnknownCamera_ReturnsNotFound()
|
|
|
|
|
{
|
|
|
|
|
var client = await AdminClient();
|
|
|
|
|
var response = await client.PostAsJsonAsync("api/assignments", new
|
|
|
|
|
{
|
|
|
|
|
cameraId = Guid.NewGuid(),
|
|
|
|
|
agentId = Guid.NewGuid(),
|
|
|
|
|
reason = "test"
|
|
|
|
|
});
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.NotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetCameraAssignment_UnknownCamera_ReturnsNotFound()
|
|
|
|
|
{
|
|
|
|
|
var client = await AdminClient();
|
|
|
|
|
var response = await client.GetAsync($"api/assignments/camera/{Guid.NewGuid()}");
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.NotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task FailoverAgent_UnknownAgent_ReturnsNotFound()
|
|
|
|
|
{
|
|
|
|
|
var client = await AdminClient();
|
|
|
|
|
var response = await client.PostAsync($"api/assignments/failover/{Guid.NewGuid()}", null);
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.NotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ReleaseCamera_UnknownCamera_ReturnsOk()
|
|
|
|
|
{
|
|
|
|
|
// Releasing an unassigned camera is a no-op, should return 200
|
|
|
|
|
var client = await AdminClient();
|
|
|
|
|
var response = await client.DeleteAsync($"api/assignments/camera/{Guid.NewGuid()}");
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
}
|