Offerings: banner krijgt positie top|bottom (backend, migratie, admin-tab, OpenAPI)
- OfferingBanner.Position ('top'|'bottom'); bestaande banners worden 'bottom' (migratie AddOfferingBannerPosition)
- GET /api/v1/offerings/banner?position=top|bottom: zonder parameter bottom, 204 zonder actieve banner, 400 bij ongeldige waarde; antwoord bevat position
- Max 1 actieve banner per positie (laatst gewijzigde binnen de planning wint); top en bottom kunnen tegelijk actief zijn
- Top: tekst max 120 tekens, titel optioneel; bottom: titel verplicht
- Admin: Banner-tab met twee secties (Boven/Onder), eigen aanmaken en aan/uit per plek
- OpenAPI-snapshot met de hand bijgewerkt (geen lokale MariaDB): CI bevestigt
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,9 +28,9 @@ public class OfferingBannersServiceTests
|
||||
new(_repo, Substitute.For<ILogger<OfferingBannersService>>(), _time, _cache);
|
||||
|
||||
private static OfferingBanner Banner(string title, bool active = true, DateTimeOffset? from = null, DateTimeOffset? to = null,
|
||||
DateTimeOffset? updated = null) => new()
|
||||
DateTimeOffset? updated = null, string position = "bottom") => new()
|
||||
{
|
||||
Id = Guid.NewGuid(), Title = title, Text = "Tekst", IsActive = active, StartsAt = from, EndsAt = to,
|
||||
Id = Guid.NewGuid(), Position = position, Title = title, Text = "Tekst", IsActive = active, StartsAt = from, EndsAt = to,
|
||||
UpdatedAt = updated ?? Now.AddDays(-1),
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ public class OfferingBannersServiceTests
|
||||
public async Task GetActive_ReturnsNull_WhenNothingIsSwitchedOn()
|
||||
{
|
||||
Switched();
|
||||
(await Sut().GetActiveAsync()).Should().BeNull();
|
||||
(await Sut().GetActiveAsync("bottom")).Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,9 +51,9 @@ public class OfferingBannersServiceTests
|
||||
banner.LinkUrl = "/aanbieding";
|
||||
Switched(banner);
|
||||
|
||||
var result = await Sut().GetActiveAsync();
|
||||
var result = await Sut().GetActiveAsync("bottom");
|
||||
|
||||
result.Should().Be(new PublicOfferingBannerDto("Actie", "Tekst", "Bekijk", "/aanbieding"));
|
||||
result.Should().Be(new PublicOfferingBannerDto("Actie", "Tekst", "Bekijk", "/aanbieding", "bottom"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,24 +64,24 @@ public class OfferingBannersServiceTests
|
||||
Banner("past", to: Now.AddHours(-1)),
|
||||
Banner("ended-exactly-now", to: Now));
|
||||
|
||||
(await Sut().GetActiveAsync()).Should().BeNull();
|
||||
(await Sut().GetActiveAsync("bottom")).Should().BeNull();
|
||||
|
||||
_time.Advance(TimeSpan.FromHours(2));
|
||||
(await Sut().GetActiveAsync())!.Title.Should().Be("future");
|
||||
(await Sut().GetActiveAsync("bottom"))!.Title.Should().Be("future");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetActive_StartsInclusive()
|
||||
{
|
||||
Switched(Banner("now", from: Now));
|
||||
(await Sut().GetActiveAsync())!.Title.Should().Be("now");
|
||||
(await Sut().GetActiveAsync("bottom"))!.Title.Should().Be("now");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetActive_PicksTheMostRecentlyChanged_WhenSeveralQualify()
|
||||
{
|
||||
Switched(Banner("old", updated: Now.AddDays(-5)), Banner("new", updated: Now.AddDays(-1)));
|
||||
(await Sut().GetActiveAsync())!.Title.Should().Be("new");
|
||||
(await Sut().GetActiveAsync("bottom"))!.Title.Should().Be("new");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -176,12 +176,79 @@ public class OfferingBannersServiceTests
|
||||
maxLength.Length.Should().Be(max);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Title")]
|
||||
[InlineData("Text")]
|
||||
public void TitleAndText_AreRequired(string name)
|
||||
[Fact]
|
||||
public async Task GetActive_FiltersOnPosition_SoTopAndBottomCanBeActiveAtTheSameTime()
|
||||
{
|
||||
var parameter = typeof(OfferingBannerRequest).GetConstructors()[0].GetParameters().Single(p => p.Name == name);
|
||||
Switched(Banner("beneden", position: "bottom"), Banner("boven", position: "top"));
|
||||
|
||||
var top = await Sut().GetActiveAsync("top");
|
||||
var bottom = await Sut().GetActiveAsync("bottom");
|
||||
|
||||
top.Should().Be(new PublicOfferingBannerDto("boven", "Tekst", null, null, "top"));
|
||||
bottom!.Title.Should().Be("beneden");
|
||||
bottom.Position.Should().Be("bottom");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetActive_MaxOnePerPosition_MostRecentlyChangedWinsWithinThePosition()
|
||||
{
|
||||
Switched(
|
||||
Banner("top-old", updated: Now.AddDays(-5), position: "top"),
|
||||
Banner("top-new", updated: Now.AddDays(-1), position: "top"),
|
||||
Banner("bottom-newest", updated: Now, position: "bottom"));
|
||||
|
||||
(await Sut().GetActiveAsync("top"))!.Title.Should().Be("top-new");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetActive_ScheduleAppliesPerPosition()
|
||||
{
|
||||
Switched(Banner("top-future", from: Now.AddHours(1), position: "top"), Banner("bottom-now"));
|
||||
|
||||
(await Sut().GetActiveAsync("top")).Should().BeNull();
|
||||
(await Sut().GetActiveAsync("bottom"))!.Title.Should().Be("bottom-now");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Create_StoresThePosition_AndAllowsAnEmptyTitleOnTop()
|
||||
{
|
||||
OfferingBanner? saved = null;
|
||||
await _repo.AddAsync(Arg.Do<OfferingBanner>(b => saved = b));
|
||||
|
||||
var dto = await Sut().CreateAsync(new OfferingBannerRequest("", "Korte tekst", Position: "top"), Guid.NewGuid());
|
||||
|
||||
saved!.Position.Should().Be("top");
|
||||
saved.Title.Should().BeEmpty();
|
||||
dto.Position.Should().Be("top");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Position_DefaultsToBottom_AndOnlyTopAndBottomAreValid()
|
||||
{
|
||||
new OfferingBannerRequest("T", "X").Position.Should().Be("bottom");
|
||||
Validate(new OfferingBannerRequest("T", "X", Position: "top")).Should().BeEmpty();
|
||||
Validate(new OfferingBannerRequest("T", "X", Position: "left")).Should().HaveCount(1);
|
||||
Validate(new OfferingBannerRequest("T", "X", Position: "")).Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Top_TextIsLimitedTo120_TitleMayBeEmpty()
|
||||
{
|
||||
Validate(new OfferingBannerRequest("", new string('a', 120), Position: "top")).Should().BeEmpty();
|
||||
Validate(new OfferingBannerRequest("", new string('a', 121), Position: "top")).Should().HaveCount(1);
|
||||
Validate(new OfferingBannerRequest("T", new string('a', 300), Position: "bottom")).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Bottom_NeedsATitle(string title)
|
||||
=> Validate(new OfferingBannerRequest(title, "X", Position: "bottom")).Should().HaveCount(1);
|
||||
|
||||
[Fact]
|
||||
public void Text_IsRequired()
|
||||
{
|
||||
var parameter = typeof(OfferingBannerRequest).GetConstructors()[0].GetParameters().Single(p => p.Name == "Text");
|
||||
var required = (RequiredAttribute)parameter.GetCustomAttributes(typeof(RequiredAttribute), false).Single();
|
||||
|
||||
required.IsValid("").Should().BeFalse();
|
||||
|
||||
Reference in New Issue
Block a user