package governance import ( "encoding/json" "strings" "testing" "time" ) // The frontend source-settings parser requires the next_refresh_at KEY to // exist whenever a connection is listed — null is a first-class value ("manual // only"), not something to omit. A `omitempty` here once blanked the entire // settings page in the deployed stack because every source defaulted to // manual-only and the strict parser rejected the key-less payload. func TestSourceConnectionViewAlwaysProjectsNextRefreshAt(t *testing.T) { view := SourceConnectionView{ID: "conn-1", SourceType: SourceTypePP, Name: "PP", Enabled: true, ScheduleConfigured: false, HealthStatus: SourceHealthHealthy, ItemCount: 621, UpdatedAt: time.Now().UTC()} payload, err := json.Marshal([]SourceConnectionView{view}) if err != nil { t.Fatal(err) } if !strings.Contains(string(payload), `"next_refresh_at":null`) { t.Fatalf("manual-only connection must project next_refresh_at:null, got %s", payload) } at := time.Now().UTC().Truncate(time.Second) view.NextRefreshAt = &at payload, err = json.Marshal([]SourceConnectionView{view}) if err != nil { t.Fatal(err) } if !strings.Contains(string(payload), `"next_refresh_at":"`) { t.Fatalf("scheduled connection must project a timestamp, got %s", payload) } }