Previously the API (heimdall-central) and Blazor UI (heimdall-web) ran as separate containers with the Blazor Server making internal HTTP calls to the API. This caused the Blazor circuit to disconnect when the API was unreachable (network error → "Une erreur réseau est survenue"). Now both serve from the same .NET process on the same port: - All 16 API controllers, ExceptionFilter, and SignalR hubs integrated into Heimdall.Web - JWT auth, CORS, rate limiting configured in the unified Program.cs - Dockerfile.central entrypoint runs web/Heimdall.Web.dll - docker-compose simplified: heimdall-central service removed - CI publishes heimdall-web image instead of heimdall-central Also fixes timezone validation on Alpine/tzdata-less environments and enables FluentValidation auto-validation in the API project.
122 lines
3.2 KiB
C#
122 lines
3.2 KiB
C#
using FluentValidation.TestHelper;
|
|
using Heimdall.Application.DTOs;
|
|
using Heimdall.Application.Validators;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Application.Tests.Validators;
|
|
|
|
public class CreateSiteValidatorTests
|
|
{
|
|
private readonly CreateSiteValidator _sut = new();
|
|
|
|
[Fact]
|
|
public void ValidRequest_Minimal_PassesValidation()
|
|
{
|
|
var request = new CreateSiteRequest("Main Office", null, null);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidRequest_WithAllFields_PassesValidation()
|
|
{
|
|
// Some CI/container environments lack tzdata; use a fallback
|
|
var tz = "Europe/Paris";
|
|
try { TimeZoneInfo.FindSystemTimeZoneById(tz); }
|
|
catch { tz = "UTC"; }
|
|
|
|
var request = new CreateSiteRequest(
|
|
"Main Office",
|
|
"123 Main St, Paris",
|
|
tz);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyName_FailsValidation()
|
|
{
|
|
var request = new CreateSiteRequest(string.Empty, null, null);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
result.ShouldHaveValidationErrorFor(x => x.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void NameExceedsMaxLength_FailsValidation()
|
|
{
|
|
var request = new CreateSiteRequest(new string('A', 201), null, null);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
result.ShouldHaveValidationErrorFor(x => x.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddressExceedsMaxLength_FailsValidation()
|
|
{
|
|
var request = new CreateSiteRequest(
|
|
"Main Office",
|
|
new string('A', 501),
|
|
null);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
result.ShouldHaveValidationErrorFor(x => x.Address);
|
|
}
|
|
|
|
[Fact]
|
|
public void InvalidTimezone_FailsValidation()
|
|
{
|
|
// Skip if tzdata not available in this environment
|
|
// Use "Europe/Paris" (not UTC) — UTC is built into the runtime
|
|
// even without tzdata, so it would pass the skip check incorrectly.
|
|
try { TimeZoneInfo.FindSystemTimeZoneById("Europe/Paris"); }
|
|
catch { return; }
|
|
|
|
var request = new CreateSiteRequest(
|
|
"Main Office",
|
|
null,
|
|
"Mars/Olympus");
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeFalse();
|
|
result.ShouldHaveValidationErrorFor(x => x.Timezone);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidTimezone_WithSubregion_PassesValidation()
|
|
{
|
|
var tz = "America/Argentina/Buenos_Aires";
|
|
try { TimeZoneInfo.FindSystemTimeZoneById(tz); }
|
|
catch { return; } // skip if tzdata not available
|
|
|
|
var request = new CreateSiteRequest("Main Office", null, tz);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
result.IsValid.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyTimezone_PassesValidation()
|
|
{
|
|
var request = new CreateSiteRequest(
|
|
"Main Office",
|
|
null,
|
|
string.Empty);
|
|
|
|
var result = _sut.TestValidate(request);
|
|
|
|
result.IsValid.ShouldBeTrue();
|
|
}
|
|
}
|