diff --git a/frontend/src/features/offerings/pages/OfferingFormPage.test.tsx b/frontend/src/features/offerings/pages/OfferingFormPage.test.tsx index 29fb522..52cfe35 100644 --- a/frontend/src/features/offerings/pages/OfferingFormPage.test.tsx +++ b/frontend/src/features/offerings/pages/OfferingFormPage.test.tsx @@ -30,6 +30,24 @@ describe('OfferingFormPage', () => { expect(screen.getByText('Enterprise')).toBeInTheDocument(); }); + it('saves an offering without description and price note', async () => { + mockAuthenticated(); + renderApp('/offerings/new'); + + await screen.findByTestId('offering-form-submit', {}, { timeout: 10000 }); + expect(screen.getByLabelText(/optioneel|optional/i, { selector: '#offering-description' })).toBeInTheDocument(); + + await userEvent.type(screen.getByTestId('offering-title'), 'Gezin'); + await userEvent.type(screen.getByTestId('offering-price'), '€ 175'); + await userEvent.type(screen.getByTestId('offering-feature-0'), '1 uur fotografie'); + await userEvent.type(screen.getByTestId('offering-cta-label'), 'Boek'); + await userEvent.click(screen.getByTestId('offering-form-submit')); + + expect(await screen.findByTestId('offerings-title', {}, { timeout: 10000 })).toBeInTheDocument(); + expect(screen.getByText('Gezin')).toBeInTheDocument(); + expect(screen.queryByTestId('offering-description-error')).not.toBeInTheDocument(); + }); + it('shows a validation error when required fields are missing', async () => { mockAuthenticated(); renderApp('/offerings/new'); diff --git a/frontend/src/features/offerings/schemas/offering.ts b/frontend/src/features/offerings/schemas/offering.ts index 5c236e1..7adb6c9 100644 --- a/frontend/src/features/offerings/schemas/offering.ts +++ b/frontend/src/features/offerings/schemas/offering.ts @@ -3,15 +3,10 @@ import { z } from 'zod'; export const offeringFormSchema = z .object({ title: z.string().min(1, 'Title is required').max(100, 'Title must be 100 characters or fewer'), - description: z - .string() - .min(1, 'Description is required') - .max(500, 'Description must be 500 characters or fewer'), + /** Optional: an empty value is stored as an empty string. */ + description: z.string().max(500, 'Description must be 500 characters or fewer'), price: z.string().min(1, 'Price is required').max(50, 'Price must be 50 characters or fewer'), - priceNote: z - .string() - .min(1, 'Price note is required') - .max(100, 'Price note must be 100 characters or fewer'), + priceNote: z.string().max(100, 'Price note must be 100 characters or fewer'), features: z .array(z.string().min(1, 'Feature cannot be empty').max(200, 'Feature must be 200 characters or fewer')) .min(1, 'At least 1 feature is required') diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index ab28581..f547247 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -431,9 +431,9 @@ "editSlugButton": "Edit", "confirmSlugButton": "Confirm slug", "cancelSlugEditButton": "Cancel slug edit", - "descriptionLabel": "Description", + "descriptionLabel": "Description (optional)", "priceLabel": "Price", - "priceNoteLabel": "Price note", + "priceNoteLabel": "Price note (optional)", "featuresLabel": "Features", "addFeatureButton": "Add feature", "removeFeatureButton": "Remove", diff --git a/frontend/src/i18n/locales/nl/translation.json b/frontend/src/i18n/locales/nl/translation.json index b5d2112..4830c87 100644 --- a/frontend/src/i18n/locales/nl/translation.json +++ b/frontend/src/i18n/locales/nl/translation.json @@ -431,9 +431,9 @@ "editSlugButton": "Aanpassen", "confirmSlugButton": "Slug bevestigen", "cancelSlugEditButton": "Slug-bewerking annuleren", - "descriptionLabel": "Beschrijving", + "descriptionLabel": "Beschrijving (optioneel)", "priceLabel": "Prijs", - "priceNoteLabel": "Prijsnotitie", + "priceNoteLabel": "Prijsnotitie (optioneel)", "featuresLabel": "Kenmerken", "addFeatureButton": "Kenmerk toevoegen", "removeFeatureButton": "Verwijderen", diff --git a/openapi/slpsoftware.v1.json b/openapi/slpsoftware.v1.json index 4aa3e40..8561907 100644 --- a/openapi/slpsoftware.v1.json +++ b/openapi/slpsoftware.v1.json @@ -425,7 +425,10 @@ "type": "string" }, "description": { - "type": "string" + "type": [ + "null", + "string" + ] }, "endsAt": { "format": "date-time", @@ -452,7 +455,10 @@ "type": "string" }, "priceNote": { - "type": "string" + "type": [ + "null", + "string" + ] }, "slug": { "type": [ @@ -832,7 +838,10 @@ "type": "string" }, "description": { - "type": "string" + "type": [ + "null", + "string" + ] }, "endsAt": { "format": "date-time", @@ -859,7 +868,10 @@ "type": "string" }, "priceNote": { - "type": "string" + "type": [ + "null", + "string" + ] }, "slug": { "type": [ diff --git a/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsIndexMarkersTests.cs b/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsIndexMarkersTests.cs index 9bfa942..4d72663 100644 --- a/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsIndexMarkersTests.cs +++ b/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsIndexMarkersTests.cs @@ -71,6 +71,28 @@ public class OfferingsIndexMarkersTests "

Beschrijving

€ 300 eenmalig

"); } + [Fact] + public void WithoutDescription_NothingEmptyIsRendered() + { + var empty = Dto("Zwangerschap", price: "€ 175", note: "") with { Description = "" }; + + var html = OfferingsIndexMarkers.Html([empty]); + html.Should().Be("
"); + html.Should().NotContain("

"); + + 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("
  • Maatwerk

  • "); + } + [Fact] public async Task WithoutOfferings_BothMarkersAreEmpty() { diff --git a/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsServiceTests.cs b/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsServiceTests.cs index 9f968c2..fce3a8d 100644 --- a/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsServiceTests.cs +++ b/src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsServiceTests.cs @@ -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(); + } } diff --git a/src/SlpModularCms.Modules.Offerings/Models/CreateOfferingRequest.cs b/src/SlpModularCms.Modules.Offerings/Models/CreateOfferingRequest.cs index 9f3979a..1069950 100644 --- a/src/SlpModularCms.Modules.Offerings/Models/CreateOfferingRequest.cs +++ b/src/SlpModularCms.Modules.Offerings/Models/CreateOfferingRequest.cs @@ -4,9 +4,10 @@ namespace SlpModularCms.Modules.Offerings.Models; public record CreateOfferingRequest( [Required, MaxLength(100)] string Title, - [Required(AllowEmptyStrings = true), MaxLength(500)] string Description, + // Optional: missing, null and "" are all stored as "" (the websites that do not use them leave them out). + [MaxLength(500)] string? Description, [Required, MaxLength(50)] string Price, - [Required(AllowEmptyStrings = true), MaxLength(100)] string PriceNote, + [MaxLength(100)] string? PriceNote, [Required, FeaturesValidation] List Features, [Required(AllowEmptyStrings = true), MaxLength(50)] string CtaLabel, bool Featured = false, diff --git a/src/SlpModularCms.Modules.Offerings/Models/UpdateOfferingRequest.cs b/src/SlpModularCms.Modules.Offerings/Models/UpdateOfferingRequest.cs index b9d5d04..ec5e645 100644 --- a/src/SlpModularCms.Modules.Offerings/Models/UpdateOfferingRequest.cs +++ b/src/SlpModularCms.Modules.Offerings/Models/UpdateOfferingRequest.cs @@ -4,9 +4,10 @@ namespace SlpModularCms.Modules.Offerings.Models; public record UpdateOfferingRequest( [Required, MaxLength(100)] string Title, - [Required(AllowEmptyStrings = true), MaxLength(500)] string Description, + // Optional: missing, null and "" are all stored as "" (the websites that do not use them leave them out). + [MaxLength(500)] string? Description, [Required, MaxLength(50)] string Price, - [Required(AllowEmptyStrings = true), MaxLength(100)] string PriceNote, + [MaxLength(100)] string? PriceNote, [Required, FeaturesValidation] List Features, [Required(AllowEmptyStrings = true), MaxLength(50)] string CtaLabel, bool Featured = false, diff --git a/src/SlpModularCms.Modules.Offerings/Services/OfferingsIndexMarkers.cs b/src/SlpModularCms.Modules.Offerings/Services/OfferingsIndexMarkers.cs index 0c60aab..94ac0ea 100644 --- a/src/SlpModularCms.Modules.Offerings/Services/OfferingsIndexMarkers.cs +++ b/src/SlpModularCms.Modules.Offerings/Services/OfferingsIndexMarkers.cs @@ -64,10 +64,14 @@ public sealed partial class OfferingsIndexMarkers(IOfferingsService offerings) : { ["@type"] = "Offer", ["name"] = o.Title, - ["description"] = o.Description, ["url"] = baseUrl + "/#pakketten", }; + if (!string.IsNullOrWhiteSpace(o.Description)) + { + offer["description"] = o.Description; + } + if (ParsePrice(o.Price) is { } price) { offer["price"] = price; @@ -104,9 +108,18 @@ public sealed partial class OfferingsIndexMarkers(IOfferingsService offerings) : foreach (var o in list) { var priceLine = string.Join(' ', new[] { o.Price, o.PriceNote }.Where(part => !string.IsNullOrWhiteSpace(part))); - html.Append("
  • ").Append(WebUtility.HtmlEncode(o.Title)).Append("

    ") - .Append(WebUtility.HtmlEncode(o.Description)).Append("

    ") - .Append(WebUtility.HtmlEncode(priceLine)).Append("

  • "); + html.Append("
  • ").Append(WebUtility.HtmlEncode(o.Title)).Append("

    "); + if (!string.IsNullOrWhiteSpace(o.Description)) + { + html.Append("

    ").Append(WebUtility.HtmlEncode(o.Description)).Append("

    "); + } + + if (priceLine.Length > 0) + { + html.Append("

    ").Append(WebUtility.HtmlEncode(priceLine)).Append("

    "); + } + + html.Append("
  • "); } return html.Append("").ToString(); diff --git a/src/SlpModularCms.Modules.Offerings/Services/OfferingsService.cs b/src/SlpModularCms.Modules.Offerings/Services/OfferingsService.cs index e6b43ea..4513379 100644 --- a/src/SlpModularCms.Modules.Offerings/Services/OfferingsService.cs +++ b/src/SlpModularCms.Modules.Offerings/Services/OfferingsService.cs @@ -36,9 +36,9 @@ public class OfferingsService( Id = Guid.NewGuid(), Slug = await ResolveSlugAsync(request.Slug, request.Title), Title = request.Title, - Description = request.Description, + Description = request.Description ?? string.Empty, Price = request.Price, - PriceNote = request.PriceNote, + PriceNote = request.PriceNote ?? string.Empty, Features = request.Features, CtaLabel = request.CtaLabel, CategoryId = category?.Id, @@ -97,9 +97,9 @@ public class OfferingsService( } offering.Title = request.Title; - offering.Description = request.Description; + offering.Description = request.Description ?? string.Empty; offering.Price = request.Price; - offering.PriceNote = request.PriceNote; + offering.PriceNote = request.PriceNote ?? string.Empty; offering.Features = request.Features; offering.CtaLabel = request.CtaLabel; offering.CategoryId = category?.Id;