package notify import ( "encoding/json" "io" "log" "path/filepath" "strings" "testing" "time" "gitea.dooplex.hu/admin/felhom-controller/internal/settings" ) // D84 (`09` §3 decision 309; `07-backup-architecture.md` §8.2f): the household's ONE mail at the press names the app, // the end date and how to take it back — in the household's language, with the date in that language's form. // RED-PROOF: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-press.txt. func TestD84_OffsiteEndScheduledEvent(t *testing.T) { ends := time.Date(2026, 12, 15, 10, 30, 0, 0, time.UTC) for _, lang := range []string{"hu", "en"} { sett, err := settings.Load(filepath.Join(t.TempDir(), "settings.json"), log.New(io.Discard, "", 0)) if err != nil { t.Fatal(err) } if err := sett.SetLanguage(lang); err != nil { t.Fatal(err) } n := &Notifier{settings: sett, logger: log.New(io.Discard, "", 0)} var et, sev, msg, cust string var det []byte calls := 0 n.pushFn = func(eventType, severity, message, customer string, details interface{}) { calls++ et, sev, msg, cust = eventType, severity, message, customer det, _ = json.Marshal(details) } n.NotifyOffsiteEndScheduled("vikunja", "2026-11-15T10:30:00Z", "2026-12-15T10:30:00Z", ends) if calls != 1 || et != "offsite_end_scheduled" || sev != "info" { t.Fatalf("%s: calls=%d type=%q severity=%q", lang, calls, et, sev) } // the wire sentence is always Hungarian: the app, the day, the way back for _, want := range []string{"vikunja", "2026. 12. 15.", "Mentések oldalon", "„Mégis megtartom”"} { if !strings.Contains(msg, want) { t.Errorf("%s: the Hungarian sentence %q lacks %q", lang, msg, want) } } if strings.Contains(msg, "15..") || strings.Contains(msg, "%") { t.Errorf("%s: the Hungarian sentence is malformed: %q", lang, msg) } if lang == "hu" { if cust != "" { t.Errorf("a Hungarian household sends nothing extra, got %q", cust) } } else { for _, want := range []string{"vikunja", "2026-12-15", "Backups page", "“Keep it after all”"} { if !strings.Contains(cust, want) { t.Errorf("the English sentence %q lacks %q", cust, want) } } if strings.Contains(cust, "2026. 12.") || strings.Contains(cust, "%") { t.Errorf("the English sentence carries the Hungarian date form or a verb: %q", cust) } } // the details: stack_name (the hub's headline names the app from it) and the press's own key for _, want := range []string{`"stack_name":"vikunja"`, `"removed_at":"2026-11-15T10:30:00Z"`, `"ends_at":"2026-12-15T10:30:00Z"`, `"subject":"vikunja|2026-11-15T10:30:00Z"`} { if !strings.Contains(string(det), want) { t.Errorf("%s: details %s lack %s", lang, det, want) } } } }