46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Elternbeirat.Contracts;
|
|
using Elternbeirat.Web.Features.Events;
|
|
using Elternbeirat.Web.Shared;
|
|
|
|
namespace Elternbeirat.Web.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the "what is coming up?" rule and the Berlin day behind it. Pure
|
|
/// logic, no PocketBase needed.
|
|
/// </summary>
|
|
public class UpcomingEventsTests
|
|
{
|
|
private static Event Event(string title, DateTime start) =>
|
|
new() { Id = "test", Title = title, Start = start };
|
|
|
|
[Fact]
|
|
public void Keeps_today_and_later_ordered_by_start()
|
|
{
|
|
var events = new[]
|
|
{
|
|
Event("Basar", new DateTime(2026, 11, 22, 9, 0, 0)),
|
|
Event("Gestern", new DateTime(2026, 9, 30, 19, 30, 0)),
|
|
Event("Heute früh", new DateTime(2026, 10, 1, 7, 0, 0)), // already begun, still today
|
|
Event("Sitzung", new DateTime(2026, 10, 8, 19, 30, 0)),
|
|
};
|
|
|
|
var upcoming = UpcomingEvents.From(events, new DateOnly(2026, 10, 1));
|
|
|
|
upcoming.Select(@event => @event.Title).ShouldBe(["Heute früh", "Sitzung", "Basar"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void Nothing_upcoming_gives_an_empty_list() =>
|
|
UpcomingEvents.From([Event("Vorbei", new DateTime(2026, 1, 1))], new DateOnly(2026, 10, 1))
|
|
.ShouldBeEmpty();
|
|
|
|
[Fact]
|
|
public void Berlin_day_starts_before_the_UTC_day()
|
|
{
|
|
// 22:30 UTC on 30 September is 00:30 on 1 October in Berlin (summer time).
|
|
var time = new FixedTimeProvider(new DateTimeOffset(2026, 9, 30, 22, 30, 0, TimeSpan.Zero));
|
|
|
|
BerlinClock.Today(time).ShouldBe(new DateOnly(2026, 10, 1));
|
|
}
|
|
}
|