Files
Heimdall/tests/Heimdall.IntegrationTests/Controllers/AssignmentsControllerTests.cs

72 lines
2.4 KiB
C#

using System.Net.Http.Json;
using System.Text.Json;
using Heimdall.IntegrationTests.Factories;
using Shouldly;
namespace Heimdall.IntegrationTests.Controllers;
public class AssignmentsControllerTests : PostgresTestBase
{
private HttpClient? _cachedClient;
public AssignmentsControllerTests(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 AssignCamera_RequiresAuth_ReturnsUnauthorized()
{
var client = Factory.CreateClient();
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_ReturnsForbidden()
{
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.Forbidden);
}
[Fact]
public async Task GetCameraAssignment_UnknownCamera_ReturnsForbidden()
{
var client = await AdminClient();
var response = await client.GetAsync($"api/assignments/camera/{Guid.NewGuid()}");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
}
[Fact]
public async Task FailoverAgent_UnknownAgent_ReturnsForbidden()
{
var client = await AdminClient();
var response = await client.PostAsync($"api/assignments/failover/{Guid.NewGuid()}", null);
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
}
[Fact]
public async Task ReleaseCamera_UnknownCamera_ReturnsForbidden()
{
// A missing camera is rejected by access policy before any release operation.
var client = await AdminClient();
var response = await client.DeleteAsync($"api/assignments/camera/{Guid.NewGuid()}");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
}
}