2026-07-17 06:18:56 +00:00
|
|
|
using System.Net.Http.Json;
|
2026-07-17 13:15:25 +00:00
|
|
|
using System.Text.Json;
|
2026-07-17 06:18:56 +00:00
|
|
|
using Heimdall.IntegrationTests.Factories;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
|
|
|
|
|
|
public class CamerasControllerTests : IClassFixture<HeimdallWebApplicationFactory>
|
|
|
|
|
{
|
|
|
|
|
private readonly HeimdallWebApplicationFactory _factory;
|
|
|
|
|
|
|
|
|
|
public CamerasControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CreateCamera_WithAuth_ReturnsOk()
|
|
|
|
|
{
|
2026-07-17 13:15:25 +00:00
|
|
|
var client = await _factory.CreateAdminClientAsync();
|
2026-07-17 06:18:56 +00:00
|
|
|
|
|
|
|
|
var siteResponse = await client.PostAsJsonAsync("api/sites", new
|
|
|
|
|
{
|
|
|
|
|
name = "Camera Test Site",
|
|
|
|
|
timezone = "UTC"
|
|
|
|
|
});
|
2026-07-17 13:15:25 +00:00
|
|
|
var siteContent = await siteResponse.Content.ReadFromJsonAsync<JsonElement>();
|
|
|
|
|
var siteId = siteContent.GetProperty("id").GetGuid();
|
2026-07-17 06:18:56 +00:00
|
|
|
|
|
|
|
|
var cameraResponse = await client.PostAsJsonAsync("api/cameras", new
|
|
|
|
|
{
|
|
|
|
|
siteId,
|
|
|
|
|
name = "Caméra Entrée",
|
|
|
|
|
rtspUrl = "rtsp://192.168.1.100:554/stream1",
|
|
|
|
|
manufacturer = "Hikvision",
|
|
|
|
|
model = "DS-2CD2T47G2-L"
|
|
|
|
|
});
|
|
|
|
|
cameraResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ListCameras_BySite_ReturnsOk()
|
|
|
|
|
{
|
2026-07-17 13:15:25 +00:00
|
|
|
var client = await _factory.CreateAdminClientAsync();
|
2026-07-17 06:18:56 +00:00
|
|
|
var response = await client.GetAsync($"api/cameras/by-site/{Guid.NewGuid()}?page=1&pageSize=10");
|
|
|
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
|
|
|
}
|
|
|
|
|
}
|