Gastansicht, Verbesserungen bei Planung

This commit is contained in:
concierge committed 2026-11-18 07:57:00 +01:00
1 parent b3afa3ef32
commit c08d43e7dd
38 files changed
+3845 -219

No files matched your search

+157
View File
@@ -0,0 +1,157 @@
package domain
import "testing"
func TestPersonLabelsUsesShortCodeAndNumbersDuplicates(t *testing.T) {
people := []Person{
{ID: "p1", FirstName: "Anna", LastName: "Berg"},
{ID: "p2", FirstName: "Anton", LastName: "Berg"},
{ID: "p3", ShortCode: "MK", FirstName: "Markus", LastName: "Klein"},
{ID: "p4", FirstName: "Mia", LastName: "Sommer"},
}
labels := PersonLabels(people)
cases := map[string]string{"p1": "AB1", "p2": "AB2", "p3": "MK", "p4": "MS"}
for id, want := range cases {
if got := labels[id]; got != want {
t.Errorf("label for %s = %q, want %q", id, got, want)
}
}
}
func TestMatchesWeekdayPreferenceTreatsHighFeastsLikeSundays(t *testing.T) {
sundayOnly := Person{PreferredWeekdays: []int{1}}
if !sundayOnly.MatchesWeekdayPreference(2, 10*60, true) {
t.Fatal("a Sunday preference must cover a high feast on another weekday")
}
if sundayOnly.MatchesWeekdayPreference(2, 10*60, false) {
t.Fatal("an ordinary Monday must not match a Sunday preference")
}
morningSunday := Person{
PreferredWeekdays: []int{1},
PreferredWeekdayPeriods: []WeekdayPeriodPreference{
{Weekday: 1, Period: PeriodMorning},
},
}
if !morningSunday.MatchesWeekdayPreference(2, 10*60, true) {
t.Fatal("a high feast in the morning should match the Sunday morning preference")
}
if morningSunday.MatchesWeekdayPreference(2, 18*60, true) {
t.Fatal("a high feast in the evening must not match the Sunday morning preference")
}
}
func TestMatchesWeekdayPreferenceUsesPeriodBounds(t *testing.T) {
person := Person{
PreferredWeekdays: []int{2},
PreferredWeekdayPeriods: []WeekdayPeriodPreference{
{Weekday: 2, Period: PeriodMorning},
},
}
if !person.MatchesWeekdayPreference(2, 11*60+59, false) {
t.Error("11:59 belongs to the morning")
}
if person.MatchesWeekdayPreference(2, 12*60, false) {
t.Error("12:00 must no longer count as morning")
}
if person.MatchesWeekdayPreference(2, 16*60+59, false) {
t.Error("16:59 belongs to the afternoon, not the morning")
}
person.PreferredWeekdayPeriods = []WeekdayPeriodPreference{{Weekday: 2, Period: PeriodEvening}}
if !person.MatchesWeekdayPreference(2, 17*60, false) {
t.Error("17:00 belongs to the evening")
}
}
func plannerFixture(person Person) (ServicePlanner, ServiceOccurrence) {
church := Church{ID: "c1", Name: "St. Andreas"}
// 2026-11-16 is a Monday.
service := ServiceOccurrence{
ID: "s1", ChurchID: church.ID, Date: MustDate("2026-11-16"),
TimeMinutes: 18 * 60, Title: "Abendmesse", LectorsNeeded: 1,
}
planner := ServicePlanner{
People: []Person{person},
Services: []ServiceOccurrence{service},
Churches: []Church{church},
Options: DefaultPlannerOptions(),
}
return planner, service
}
func TestPlannerBeyondPreferencesRequiresExplicitPass(t *testing.T) {
person := Person{
ID: "p1", FirstName: "Anna", LastName: "Berg", Roles: []Role{RoleLector},
PreferredWeekdays: []int{1}, Active: true, MaxPerMonth: 1,
}
planner, _ := plannerFixture(person)
planner.Options.RespectPreferredWeekdays = true
result := planner.Plan()
if len(result.Unfilled) != 1 || len(result.Assignments) != 0 {
t.Fatalf("without permission the slot must stay open, got %#v", result)
}
person.AllowBeyondPreferences = true
planner, _ = plannerFixture(person)
planner.Options.RespectPreferredWeekdays = true
planner.Options.AllowBeyondPreferences = true
result = planner.Plan()
if len(result.Unfilled) != 0 || len(result.Assignments) != 1 {
t.Fatalf("expected a fallback assignment, got %#v", result)
}
if !result.Assignments[0].BeyondPreferences {
t.Fatal("fallback assignment must be marked as beyond preferences")
}
person.AllowBeyondPreferences = false
planner, _ = plannerFixture(person)
planner.Options.AllowBeyondPreferences = true
if result := planner.Plan(); len(result.Assignments) != 0 {
t.Fatal("a person without permission must not be planned beyond preferences")
}
}
func TestPlannerTreatsHighFeastAsSunday(t *testing.T) {
person := Person{
ID: "p1", FirstName: "Anna", LastName: "Berg", Roles: []Role{RoleLector},
PreferredWeekdays: []int{1}, Active: true, MaxPerMonth: 6,
}
planner, service := plannerFixture(person)
planner.LiturgicalDays = []LiturgicalDay{{
Date: service.Date, Title: "Hochfest", Rank: RankSolemnity,
}}
result := planner.Plan()
if len(result.Assignments) != 1 || len(result.Unfilled) != 0 {
t.Fatalf("high feast must match a Sunday preference, got %#v", result)
}
if result.Assignments[0].BeyondPreferences {
t.Fatal("a matched high feast is not beyond preferences")
}
}
func TestCandidateSuggestionsMarkBeyondPreferences(t *testing.T) {
service := ServiceOccurrence{
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
TimeMinutes: 18 * 60, Title: "Abendmesse", LectorsNeeded: 1,
}
sundayOnly := Person{
ID: "p1", FirstName: "Anna", LastName: "Berg", Roles: []Role{RoleLector},
PreferredWeekdays: []int{1}, Active: true, MaxPerMonth: 6,
}
suggestions := CandidateSuggestions(service, RoleLector,
[]Person{sundayOnly}, nil, nil, []ServiceOccurrence{service}, nil, false, nil)
if len(suggestions) != 1 || !suggestions[0].Blocked || suggestions[0].BeyondPreferences {
t.Fatalf("person without permission should be blocked, got %#v", suggestions)
}
sundayOnly.AllowBeyondPreferences = true
suggestions = CandidateSuggestions(service, RoleLector,
[]Person{sundayOnly}, nil, nil, []ServiceOccurrence{service}, nil, false, nil)
if len(suggestions) != 1 || suggestions[0].Blocked || !suggestions[0].BeyondPreferences {
t.Fatalf("flagged person should be suggested beyond preferences, got %#v", suggestions)
}
if suggestions[0].Person.PreferenceNote() != "" {
t.Fatal("unexpected preference note")
}
}