Files
ResolveSpec/pkg/common/update_merge_test.go
T
Hein 20ba8ed112 feat(update): allow clearing values with "" and null on update
Update handlers skipped empty strings and nulls, so a client could not
blank or null out a column. Every key present in the payload now
overwrites the stored value, including "" and null.

- add common.MergeUpdateValues and use it in resolvespec and restheadspec
- add Handler.SetDisallowNulls to skip null values (""still overwrites)
- websocketspec and mqttspec now write only the keys present in the
  payload via SetMap instead of updating the whole zeroed model, which
  clobbered absent fields
2026-09-30 17:03:42 +02:00

30 lines
840 B
Go

package common
import "testing"
func TestMergeUpdateValues(t *testing.T) {
newExisting := func() map[string]interface{} {
return map[string]interface{}{"name": "old", "note": "keep", "other": "x"}
}
incoming := map[string]interface{}{"name": "", "note": nil}
got := MergeUpdateValues(newExisting(), incoming, false)
if got["name"] != "" {
t.Errorf("name = %v, want empty string", got["name"])
}
if v, ok := got["note"]; !ok || v != nil {
t.Errorf("note = %v (present=%v), want nil", v, ok)
}
if got["other"] != "x" {
t.Errorf("absent key changed: %v", got["other"])
}
got = MergeUpdateValues(newExisting(), incoming, true)
if got["name"] != "" {
t.Errorf("disallowNulls: name = %v, want empty string", got["name"])
}
if got["note"] != "keep" {
t.Errorf("disallowNulls: note = %v, want keep", got["note"])
}
}