Files
LektorenPlan/web/web/guest_range_test.go
T

48 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"net/http/httptest"
"testing"
"lektorenplan/domain"
)
func TestGuestRangeDefaultsToFourWeeks(t *testing.T) {
today := domain.MustDate("2026-11-17") // Tuesday
minDate := domain.MustDate("2026-11-15")
maxDate := domain.MustDate("2027-06-30")
request := httptest.NewRequest("GET", "/guest", nil)
rng := guestRangeFromRequest(request, today, minDate, maxDate)
if got := domain.Key(rng.Start); got != "2026-11-17" {
t.Errorf("default start = %s, want today", got)
}
if got := domain.Key(rng.End); got != "2026-12-15" {
t.Errorf("default end = %s, want four weeks", got)
}
}
func TestGuestRangeClampsToSundayAndLatestPlannedDay(t *testing.T) {
today := domain.MustDate("2026-11-17")
minDate := domain.MustDate("2026-11-15")
maxDate := domain.MustDate("2026-12-24")
request := httptest.NewRequest("GET", "/guest?start=2026-01-01&end=2027-01-01", nil)
rng := guestRangeFromRequest(request, today, minDate, maxDate)
if got := domain.Key(rng.Start); got != domain.Key(minDate) {
t.Errorf("start = %s, want the most recent Sunday %s", got, domain.Key(minDate))
}
if got := domain.Key(rng.End); got != domain.Key(maxDate) {
t.Errorf("end = %s, want the latest planned day %s", got, domain.Key(maxDate))
}
}
func TestGuestRangeSwapsReversedInput(t *testing.T) {
today := domain.MustDate("2026-11-17")
minDate := domain.MustDate("2026-11-15")
maxDate := domain.MustDate("2026-12-31")
request := httptest.NewRequest("GET", "/guest?start=2026-12-10&end=2026-11-20", nil)
rng := guestRangeFromRequest(request, today, minDate, maxDate)
if rng.End.Before(rng.Start) {
t.Fatalf("range not normalized: %s – %s", domain.Key(rng.Start), domain.Key(rng.End))
}
}