Allow setting fields previously unset, like adding a connection when it was nil in db

This commit is contained in:
breel
2020-07-26 02:37:02 -06:00
parent 962a0b0585
commit 363d3143e8
5 changed files with 91 additions and 3 deletions

View File

@@ -342,6 +342,34 @@ func TestIntegration(t *testing.T) {
}
})
t.Run("graph.Update connections when none previously", func(t *testing.T) {
cleanFill()
one := randomOne()
one.Connections = nil
err := graph.Insert(ctx, "col", one)
if err != nil {
t.Fatal(err)
}
err = graph.Update(ctx, "col", one.Query(), operator.Set{Key: entity.Connections + ".newfriend", Value: randomOne()})
if err != nil {
t.Fatal(err)
}
ones, err = graph.ListCaseInsensitive(ctx, "col", one.Name)
if err != nil {
t.Fatal(err)
}
if len(ones) != 1 {
t.Fatal(ones)
}
if len(ones[0].Connections) != 1 {
t.Fatal(ones[0].Connections)
}
if _, ok := ones[0].Connections["newfriend"]; !ok {
t.Fatal(ones[0].Connections)
}
})
}
func randomOne() entity.One {