Versendung mit .ics Kalenderdatei

This commit is contained in:
concierge committed 2026-11-18 08:13:10 +01:00
1 parent c08d43e7dd
commit dc20d7ec5a
13 files changed
+650 -54

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
package domain
import (
"strings"
"testing"
"time"
)
func TestCalendarICSWritesTimedEvents(t *testing.T) {
start := time.Date(2026, 11, 22, 18, 0, 0, 0, time.Local)
ics := CalendarICS("Gottesdienstplan Pfarrei", []CalendarEvent{
{
UID: "assignment-1", Start: start, DurationMinutes: 60,
Summary: "Abendmesse, Hochfest", Location: "St. Andreas",
Description: "Dienst: Lektor; Bitte 10 Minuten früher da sein.",
},
})
for _, want := range []string{
"BEGIN:VCALENDAR\r\n",
"VERSION:2.0\r\n",
"BEGIN:VEVENT\r\n",
"UID:assignment-1@lektorenplan\r\n",
"DTSTART:20261122T180000\r\n",
"DTEND:20261122T190000\r\n",
"SUMMARY:Abendmesse\\, Hochfest\r\n",
"LOCATION:St. Andreas\r\n",
"DESCRIPTION:Dienst: Lektor\\; Bitte 10 Minuten früher da sein.\r\n",
"END:VCALENDAR\r\n",
} {
if !strings.Contains(ics, want) {
t.Fatalf("calendar misses %q:\n%s", want, ics)
}
}
if strings.Contains(ics, "\n\n") {
t.Fatal("calendar must use CRLF line endings")
}
}
func TestCalendarICSFoldsLongLines(t *testing.T) {
start := time.Date(2026, 11, 22, 10, 0, 0, 0, time.Local)
long := strings.Repeat("ä", 90)
ics := CalendarICS("Plan", []CalendarEvent{{UID: "x", Start: start, Summary: long}})
for _, line := range strings.Split(ics, "\r\n") {
if len([]byte(line)) > 75 {
t.Fatalf("line exceeds 75 octets: %q", line)
}
}
if !strings.Contains(ics, "\r\n ") {
t.Fatal("expected folded continuation line")
}
}
func TestCalendarICSEscapesBackslashesAndNewlines(t *testing.T) {
ics := CalendarICS("Plan", []CalendarEvent{{
UID: "x", Start: time.Now(), Summary: "A\\B", Description: "Zeile 1\nZeile 2",
}})
if !strings.Contains(ics, "SUMMARY:A\\\\B\r\n") {
t.Fatalf("backslash not escaped:\n%s", ics)
}
if !strings.Contains(ics, "DESCRIPTION:Zeile 1\\nZeile 2\r\n") {
t.Fatalf("newline not escaped:\n%s", ics)
}
}