Files
felhom.eu/hub/internal/store/household_prefs_test.go
T

37 lines
2.0 KiB
Go

package store
import "testing"
// R-1199 reopened: the one-time backfill marks a row a box wrote (updated_at ≠ created_at) and leaves a seeded row
// unmarked; it runs once (a later push marked by the handler is not re-judged); SaveNotificationPrefs never clears
// the mark. The live hub's six rows, read 2026-10-22, are the shapes below.
// RED-PROOF: with the backfill's `saved` forced false, the first assertion fails — seen failing 2026-10-22.
func TestHouseholdSaved_BackfillMarksPushedRowsOnce(t *testing.T) {
s := newTestStore(t)
// A seeded row (Tester-2's shape) and a pushed row (demo-felhom's shape), written as the old hub wrote them.
s.db.Exec(`INSERT INTO customer_notifications (customer_id, email, enabled_events, created_at, updated_at, household_saved)
VALUES ('seeded', 'a@example.hu', '["node_down"]', '2026-10-04 16:30:00', '2026-10-04 16:30:00', 0),
('pushed', 'b@example.hu', '["disk_warning"]', '2026-02-16 19:22:40', '2026-09-24 09:39:35', 0)`)
s.db.Exec(`DELETE FROM hub_settings WHERE key = ?`, householdSavedBackfillKey)
if err := s.migrateHouseholdSaved(); err != nil {
t.Fatal(err)
}
if p, _ := s.GetNotificationPrefs("pushed"); p == nil || !p.HouseholdSaved {
t.Fatalf("a row a box wrote must be marked household_saved: %+v", p)
}
if p, _ := s.GetNotificationPrefs("seeded"); p == nil || p.HouseholdSaved {
t.Fatalf("a seeded row must not be marked: %+v", p)
}
// Runs once: a row changed after the backfill is not re-judged by it.
s.db.Exec(`UPDATE customer_notifications SET updated_at = '2026-10-23 00:00:00' WHERE customer_id = 'seeded'`)
s.migrateHouseholdSaved()
if p, _ := s.GetNotificationPrefs("seeded"); p.HouseholdSaved {
t.Fatal("the backfill ran a second time")
}
// A plain save never clears the mark.
s.SaveNotificationPrefs("pushed", "b@example.hu", []string{"node_down"}, 6)
if p, _ := s.GetNotificationPrefs("pushed"); !p.HouseholdSaved {
t.Fatal("SaveNotificationPrefs cleared the household mark")
}
}