Files
felhom-controller/controller/internal/settings/app_update_seed_test.go
T
admin bc278944a3
gates / gates (push) Successful in 25s
controller v0.264.0: the household is told when an update is undone or held, in its language
app_update_undone / app_update_held events (09 decision 15), on by
default and seeded once on existing boxes; R-606 update sentences as
key+args rendered per reader; R-646 startup applied-meta backfill for
apps current with the catalog; R-620 a disabled notifier WARNs once per
event type. Needs hub v0.120.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-09-23 13:51:21 +02:00

49 lines
1.4 KiB
Go

package settings
import (
"io"
"log"
"os"
"path/filepath"
"testing"
)
// v0.264.0 — the one-time, ADD-ONLY seed of the two update event types into a household's stored prefs.
//
// COMPANION RED-PROOF (REPORT.md): drop the seedAppUpdateEvents call from Load — the first assertion fails.
func TestSeedAppUpdateEvents_AddOnlyOnce(t *testing.T) {
p := filepath.Join(t.TempDir(), "settings.json")
if err := os.WriteFile(p, []byte(`{"notifications":{"email":"h@example.hu","enabled_events":["backup_failed"]}}`), 0o600); err != nil {
t.Fatal(err)
}
lg := log.New(io.Discard, "", 0)
s, err := Load(p, lg)
if err != nil {
t.Fatal(err)
}
ev := s.Notifications.EnabledEvents
has := func(list []string, x string) bool {
for _, e := range list {
if e == x {
return true
}
}
return false
}
if !has(ev, "backup_failed") || !has(ev, "app_update_undone") || !has(ev, "app_update_held") {
t.Fatalf("the household's choice must be kept and both types added, got %v", ev)
}
// The household opts out of one; a restart must NOT add it back.
s.Notifications.EnabledEvents = []string{"backup_failed", "app_update_held"}
if err := s.save(); err != nil {
t.Fatal(err)
}
s2, err := Load(p, lg)
if err != nil {
t.Fatal(err)
}
if has(s2.Notifications.EnabledEvents, "app_update_undone") {
t.Errorf("a later opt-out must stick — the seed runs once, got %v", s2.Notifications.EnabledEvents)
}
}