Offerings: beschrijving en prijsnotitie optioneel (API, admin, index-markers, OpenAPI)

Ontbrekend/null/leeg wordt als lege string opgeslagen en teruggegeven;
JSON-LD laat description weg en de HTML-markers renderen geen lege <p>.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 14:14:43 +01:00
co-authored by Claude Sonnet 5.5
parent 46c3a0e6a2
commit d8141db050
11 changed files with 130 additions and 33 deletions
@@ -71,6 +71,28 @@ public class OfferingsIndexMarkersTests
"<p>Beschrijving</p><p>€ 300 eenmalig</p></li></ul></section>");
}
[Fact]
public void WithoutDescription_NothingEmptyIsRendered()
{
var empty = Dto("Zwangerschap", price: "€ 175", note: "") with { Description = "" };
var html = OfferingsIndexMarkers.Html([empty]);
html.Should().Be("<section id=\"packages-static\" aria-label=\"Pakketten\"><ul><li><h3>Zwangerschap</h3><p>€ 175</p></li></ul></section>");
html.Should().NotContain("<p></p>");
var json = OfferingsIndexMarkers.JsonLd([empty], "https://x.nl");
json.Should().NotContain("\"description\"");
json.Should().Contain("\"price\":\"175\"");
}
[Fact]
public void WithoutDescriptionAndPrice_TheListItemHasOnlyATitle()
{
var bare = Dto("Maatwerk", price: "", note: "") with { Description = "" };
OfferingsIndexMarkers.Html([bare]).Should().Contain("<li><h3>Maatwerk</h3></li>");
}
[Fact]
public async Task WithoutOfferings_BothMarkersAreEmpty()
{
@@ -288,15 +288,11 @@ public class OfferingsServiceTests
}
[Theory]
[InlineData(typeof(CreateOfferingRequest), "Description", true)]
[InlineData(typeof(CreateOfferingRequest), "PriceNote", true)]
[InlineData(typeof(CreateOfferingRequest), "CtaLabel", true)]
[InlineData(typeof(UpdateOfferingRequest), "Description", true)]
[InlineData(typeof(UpdateOfferingRequest), "PriceNote", true)]
[InlineData(typeof(UpdateOfferingRequest), "CtaLabel", true)]
[InlineData(typeof(CreateOfferingRequest), "Title", false)]
[InlineData(typeof(CreateOfferingRequest), "Price", false)]
public void Request_accepts_empty_text_only_for_description_pricenote_and_cta(Type request, string name, bool emptyAllowed)
public void Request_accepts_empty_text_only_for_cta(Type request, string name, bool emptyAllowed)
{
var parameter = request.GetConstructors()[0].GetParameters().Single(p => p.Name == name);
var required = (System.ComponentModel.DataAnnotations.RequiredAttribute)parameter
@@ -305,4 +301,43 @@ public class OfferingsServiceTests
required.IsValid(string.Empty).Should().Be(emptyAllowed);
required.IsValid(null).Should().BeFalse();
}
[Theory]
[InlineData(typeof(CreateOfferingRequest), "Description", 500)]
[InlineData(typeof(CreateOfferingRequest), "PriceNote", 100)]
[InlineData(typeof(UpdateOfferingRequest), "Description", 500)]
[InlineData(typeof(UpdateOfferingRequest), "PriceNote", 100)]
public void Description_and_pricenote_are_optional_but_limited(Type request, string name, int max)
{
var parameter = request.GetConstructors()[0].GetParameters().Single(p => p.Name == name);
parameter.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.RequiredAttribute), false).Should().BeEmpty();
((System.ComponentModel.DataAnnotations.MaxLengthAttribute)parameter
.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.MaxLengthAttribute), false).Single()).Length.Should().Be(max);
}
[Fact]
public async Task CreateAsync_StoresMissingDescriptionAndPriceNote_AsEmptyStrings()
{
var result = await CreateSut().CreateAsync(
new CreateOfferingRequest("Title", null, "€ 175", null, ["Feature 1"], "Contact"), Guid.NewGuid());
result.Description.Should().BeEmpty();
result.PriceNote.Should().BeEmpty();
}
[Fact]
public async Task UpdateAsync_ClearsDescriptionAndPriceNote_WhenOmitted()
{
var offering = ExistingOffering();
offering.Description = "old";
offering.PriceNote = "old note";
_repo.GetByIdAsync(offering.Id).Returns(offering);
var result = await CreateSut().UpdateAsync(
offering.Id, new UpdateOfferingRequest(offering.Title, null, "€ 175", null, ["Feature 1"], "Contact"), Guid.NewGuid());
result!.Description.Should().BeEmpty();
result.PriceNote.Should().BeEmpty();
}
}