mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-02 19:41:57 +00:00
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
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user