diff --git a/public/swagger/swagger.yaml b/public/swagger/swagger.yaml index 9c8bb13..b8d5d2e 100644 --- a/public/swagger/swagger.yaml +++ b/public/swagger/swagger.yaml @@ -13,6 +13,7 @@ info: servers: - url: http://api.dndex.lan:8080/ +- url: http://authapi.dndex.lan:8080/ paths: /who: diff --git a/public/vue/dndex-ui b/public/vue/dndex-ui index ef4bfae..ae4e0a3 160000 --- a/public/vue/dndex-ui +++ b/public/vue/dndex-ui @@ -1 +1 @@ -Subproject commit ef4bfae193a599c4fe7016a64e56663caf06f470 +Subproject commit ae4e0a319c0c9a0d22c03df66985c802053f8f05 diff --git a/storage/driver/boltdb.go b/storage/driver/boltdb.go index 34dfb3b..8c3516b 100644 --- a/storage/driver/boltdb.go +++ b/storage/driver/boltdb.go @@ -288,7 +288,8 @@ func applyUnset(doc, operator bson.M) (bson.M, error) { if len(nesting) > 1 { mInterface, ok := doc[nesting[0]] if !ok { - return nil, fmt.Errorf("path does not exist: %s (%s): %+v", k, nesting[0], doc) + continue + //return nil, fmt.Errorf("path does not exist: %s (%s): %+v", k, nesting[0], doc) } m, ok := mInterface.(map[string]interface{}) if !ok { @@ -320,7 +321,8 @@ func applySet(doc, operator bson.M) (bson.M, error) { if len(nesting) > 1 { mInterface, ok := doc[nesting[0]] if !ok { - return nil, fmt.Errorf("path does not exist: %s (%s): %+v", k, nesting[0], doc) + mInterface = map[string]interface{}{} + //return nil, fmt.Errorf("path does not exist: %s (%s): %+v", k, nesting[0], doc) } m, ok := mInterface.(map[string]interface{}) if !ok { diff --git a/storage/driver/boltdb_test.go b/storage/driver/boltdb_test.go index 4038252..826de8f 100644 --- a/storage/driver/boltdb_test.go +++ b/storage/driver/boltdb_test.go @@ -444,6 +444,11 @@ func TestApplySet(t *testing.T) { doc: bson.M{"hello": bson.M{"world": "not hi"}}, want: bson.M{"hello": bson.M{"world": "not hi", "notworld": "hi"}}, }, + "add to nonexisting, nested field": { + operator: bson.M{"hello.notworld.notnotworld": "hi"}, + doc: bson.M{"hello": bson.M{"world": "not hi"}}, + want: bson.M{"hello": bson.M{"world": "not hi", "notworld": bson.M{"notnotworld": "hi"}}}, + }, } for name, d := range cases { @@ -459,3 +464,55 @@ func TestApplySet(t *testing.T) { }) } } + +func TestApplyUnset(t *testing.T) { + cases := map[string]struct { + doc bson.M + operator bson.M + want bson.M + }{ + "noop on empty": {}, + "noop on full": { + doc: bson.M{"hello": "world"}, + want: bson.M{"hello": "world"}, + }, + "del one field on full": { + operator: bson.M{"hi": "mom"}, + doc: bson.M{"hello": "world", "hi": "mom"}, + want: bson.M{"hello": "world"}, + }, + "del only field on full": { + operator: bson.M{"hello": ""}, + doc: bson.M{"hello": "world"}, + want: bson.M{}, + }, + "del existing, nested field": { + operator: bson.M{"hello.world": ""}, + doc: bson.M{"hello": bson.M{"world": "not hi"}}, + want: bson.M{"hello": bson.M{}}, + }, + "del to existing, nested field": { + operator: bson.M{"hello.notworld": ""}, + doc: bson.M{"hello": bson.M{"world": "not hi", "notworld": "hi"}}, + want: bson.M{"hello": bson.M{"world": "not hi"}}, + }, + "del to nonexisting, nested field": { + operator: bson.M{"hello.notworld.notnotworld": "hi"}, + doc: bson.M{"hello": bson.M{"world": "not hi"}}, + want: bson.M{"hello": bson.M{"world": "not hi"}}, + }, + } + + for name, d := range cases { + c := d + t.Run(name, func(t *testing.T) { + out, err := applyUnset(c.doc, c.operator) + if err != nil { + t.Fatal(err) + } + if fmt.Sprint(out) != fmt.Sprint(c.want) { + t.Fatalf("(%+v, %+v) => want \n%+v\n, got \n%+v", c.doc, c.operator, c.want, out) + } + }) + } +} diff --git a/storage/graph_test.go b/storage/graph_test.go index 28b237e..cbe4a6a 100644 --- a/storage/graph_test.go +++ b/storage/graph_test.go @@ -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 {