R-1199 reopened: a box with no list of its own reads the household's from the hub and adopts it, pushes its default once only when no household saved one; every push names its source; an empty saved list stays empty; R-1216 (D28 = A): the install page's swap sentence only when host swap is really short (shared case table); unreleased
gates / gates (push) Successful in 1m55s
gates / gates (push) Successful in 1m55s
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// R-1199 reopened (2026-10-22): a household that unticks every mail must see an empty list after a restart — the hub
|
||||
// mails by that empty list. Before: omitempty dropped the [] and the getter turned the missing list into the defaults.
|
||||
// Both shapes: a fresh save, and the file Tester 1 and demo-hp actually hold (`{"cooldown_hours": 6}` only).
|
||||
// RED-PROOF: with the getter's nil → DefaultEnabledEvents restored, both assertions fail — seen failing 2026-10-22.
|
||||
func TestR1199Reopened_AnEmptySavedListStaysEmpty(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "s.json")
|
||||
s, _ := Load(p, log.New(io.Discard, "", 0))
|
||||
if err := s.SetNotificationPrefs(&NotificationPrefs{EnabledEvents: []string{}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s2, _ := Load(p, log.New(io.Discard, "", 0))
|
||||
if got := s2.GetNotificationPrefs().EnabledEvents; len(got) != 0 {
|
||||
t.Fatalf("a saved empty list came back as %v", got)
|
||||
}
|
||||
q := filepath.Join(t.TempDir(), "old.json")
|
||||
os.WriteFile(q, []byte(`{"notifications":{"cooldown_hours":6}}`), 0o600)
|
||||
s3, _ := Load(q, log.New(io.Discard, "", 0))
|
||||
if got := s3.GetNotificationPrefs().EnabledEvents; len(got) != 0 || !s3.NotificationPrefsSaved() {
|
||||
t.Fatalf("the live boxes' file shape reads as %v (saved=%t), want an empty saved list", got, s3.NotificationPrefsSaved())
|
||||
}
|
||||
// A box with nothing saved still shows the defaults.
|
||||
s4, _ := Load(filepath.Join(t.TempDir(), "n.json"), log.New(io.Discard, "", 0))
|
||||
if got := s4.GetNotificationPrefs().EnabledEvents; len(got) != len(DefaultEnabledEvents) {
|
||||
t.Fatalf("an unsaved box must show the defaults, got %d", len(got))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user