- Cameras API: CRUD with service/controller/DTOs + Blazor page - Docker: production-grade compose with healthchecks, .env, Makefile, networks - Healthchecks: /healthz (liveness) and /readyz (readiness) endpoints - Testing: 13 integration tests (Auth, Sites, Users, Cameras controllers) - Users: create, list, lock, reset-password - Cameras: create with site, list by site - Environment: .env.example, docker-compose.override.yml for dev - Infrastructure: ICameraService registered in DI
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
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()
|
|
{
|
|
var client = await CreateAdminClient();
|
|
|
|
// First create a site
|
|
var siteResponse = await client.PostAsJsonAsync("api/sites", new
|
|
{
|
|
name = "Camera Test Site",
|
|
timezone = "UTC"
|
|
});
|
|
var siteContent = await siteResponse.Content.ReadFromJsonAsync<SiteTestResponse>();
|
|
var siteId = siteContent!.Id;
|
|
|
|
// Create a camera
|
|
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()
|
|
{
|
|
var client = await CreateAdminClient();
|
|
var response = await client.GetAsync($"api/cameras/by-site/{Guid.NewGuid()}?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
}
|
|
|
|
private async Task<HttpClient> CreateAdminClient()
|
|
{
|
|
var client = _factory.CreateClient();
|
|
var loginResponse = await client.PostAsJsonAsync("api/auth/login", new
|
|
{
|
|
email = "testadmin@heimdall.test",
|
|
password = "TestAdmin123!"
|
|
});
|
|
var content = await loginResponse.Content.ReadFromJsonAsync<AuthTestResponse>();
|
|
client.DefaultRequestHeaders.Authorization =
|
|
new AuthenticationHeaderValue("Bearer", content!.AccessToken);
|
|
return client;
|
|
}
|
|
}
|
|
|
|
public record SiteTestResponse(Guid Id, string Name);
|