package warningconfig import ( "github.com/gogf/gf/v2/encoding/gjson" "testing" ) func TestNotificationFieldPresenceSurvivesSnapshot(t *testing.T) { for _, supplied := range []bool{false, true} { data := map[string]any{"itemType": 1, "warnUnit": 1, "firstWarn": 100, "isEnabled": 1} if supplied { data["appNotifyEnabled"] = 0 data["wxTemplateId"] = "" } config, err := configFromBatchInfo(gjson.New(data)) if err != nil { t.Fatal(err) } if config.AppNotifyProvided != supplied || config.WxTemplateProvided != supplied { t.Fatalf("presence lost: %+v", config) } detail := &Detail{Config: config} snapshot := detail.Snapshot(config) restored := configFromDetailSnapshot(snapshot, Config{}) if restored.AppNotifyProvided != supplied || restored.WxTemplateProvided != supplied { t.Fatalf("snapshot presence lost: %+v", restored) } } } func TestNotificationSnapshotPreservesFallbackWhenAbsent(t *testing.T) { fallback := Config{AppNotifyEnabled: 1, AppNotifyProvided: true, WxTemplateID: "existing", WxTemplateProvided: true} restored := configFromDetailSnapshot(gjson.New(map[string]any{"configSet": true, "warnUnit": 1}), fallback) if restored.AppNotifyEnabled != 1 || restored.WxTemplateID != "existing" { t.Fatalf("fallback overwritten: %+v", restored) } }