H2: Hero-module (tabellen en migratie, beheer-API, publieke GET /hero, afbeeldingsupload met focus, opschoonservice, teksten) en OpenAPI-snapshot

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 15:46:55 +01:00
co-authored by Claude Sonnet 5.5
parent 43925cbf37
commit ae04120d8c
31 changed files with 4221 additions and 3 deletions
@@ -0,0 +1,73 @@
using System.Net;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SlpModularCms.Modules.Hero.Data;
namespace SlpModularCms.Api.Tests;
/// <summary>The Hero module on the real master host and the real, migrated database.</summary>
public class HeroOnTheMasterHostTests : IClassFixture<ApiWebApplicationFactory>
{
private readonly ApiWebApplicationFactory _factory;
public HeroOnTheMasterHostTests(ApiWebApplicationFactory factory) => _factory = factory;
[Fact]
public async Task Capabilities_ListTheHeroModule()
{
var response = await _factory.CreateClient().GetAsync("/api/v1/System/capabilities");
using var doc = System.Text.Json.JsonDocument.Parse(await response.Content.ReadAsStringAsync());
doc.RootElement.GetProperty("modules").EnumerateArray().Select(e => e.GetString()).Should().Contain("Hero");
}
[Fact]
public async Task WithoutAHero_ThePublicEndpointAnswers204_WithTheShortCache()
{
var response = await _factory.CreateClient().GetAsync("/api/v1/hero");
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
response.Headers.CacheControl!.ToString().Should().Be("public, max-age=60");
}
[Theory]
[InlineData("GET", "/api/v1/hero/all")]
[InlineData("PUT", "/api/v1/hero")]
[InlineData("POST", "/api/v1/hero/images")]
[InlineData("DELETE", "/api/v1/hero/images/11111111-2222-3333-4444-555555555555")]
[InlineData("PUT", "/api/v1/hero/images/11111111-2222-3333-4444-555555555555/focus")]
public async Task Management_RequiresAnAdministrator(string method, string url)
{
var request = new HttpRequestMessage(new HttpMethod(method), url);
if (method == "POST")
{
request.Content = new MultipartFormDataContent { { new ByteArrayContent([1, 2, 3]), "file", "x.jpg" } };
}
var response = await _factory.CreateClient().SendAsync(request);
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}
[Theory]
[InlineData("/media/hero/0123456789abcdef/wide-960.webp")]
[InlineData("/media/hero/0123456789abcdef/../../secret")]
[InlineData("/media/originals/anything.jpg")]
public async Task TheMediaEndpoint_AnswersAPlain404_ForAnythingNotStored(string url)
{
var response = await _factory.CreateClient().GetAsync(url);
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}
[Fact]
public void HeroMigrations_MatchTheModel()
{
_ = _factory.CreateClient(); // starts the host and migrates
using var scope = _factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<HeroDbContext>();
db.Database.HasPendingModelChanges().Should().BeFalse("every model change needs its migration and snapshot");
}
}
@@ -21,7 +21,7 @@ public class SiteContractTests
public void TheMasterCms_ReferencesEveryModule()
{
SiteFiles.Modules("SlpModularCms.Api").Should().BeEquivalentTo(
["Availability", "Contact", "Identity", "Master", "Offerings"],
["Availability", "Contact", "Hero", "Identity", "Master", "Offerings"],
"the master Api is the all-modules composition the CI builds and tests");
}
@@ -29,7 +29,7 @@ public class SiteContractTests
public void SlpSoftware_IsTheFullComposition()
{
SiteFiles.Modules(SiteFiles.SlpSoftware).Should().BeEquivalentTo(
["Availability", "Contact", "Identity", "Master", "Offerings"]);
["Availability", "Contact", "Hero", "Identity", "Master", "Offerings"]);
}
[Fact]
@@ -37,7 +37,7 @@ public class SiteContractTests
{
// Not a master/slave setup: no Master module, so /System/capabilities does not list it.
SiteFiles.Modules(SiteFiles.AndreaSlopFotografie).Should().BeEquivalentTo(
["Availability", "Contact", "Identity", "Offerings"]);
["Availability", "Contact", "Hero", "Identity", "Offerings"]);
}
[Theory]