Skip to content

Commit

Permalink
fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sneljo1 committed Jun 19, 2018
1 parent 4c31f4c commit 94ff071
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func test(data interface{}, userQuery interface{}) (bool, error) {

last := true

if userQuery == nil || data == nil {
return false, nil
}

if canDecend(userQuery) && reflect.TypeOf(userQuery).Kind() == reflect.Map {

userQuery, ok := userQuery.(map[string]interface{})
Expand Down
3 changes: 2 additions & 1 deletion test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var TestData = map[string]interface{}{
"MARBLE3": map[string]interface{}{
"objectType": "MARBLE",
"owner": "arnold",
"image": "https://example.com/image.png",
"size": 5,
"previousOwners": []string{
"alice",
Expand Down Expand Up @@ -68,4 +69,4 @@ res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
},
},
})
*/
*/
27 changes: 27 additions & 0 deletions test/missing_properties_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test

import (
"testing"

"github.com/wearetheledger/go-couchdb-query-engine/query"
)

func TestQueryWithSomeMissingProperties(t *testing.T) {

t.Run("Element should be returned when properties are missing in other records", func(t *testing.T) {

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
"selector": map[string]interface{}{
"image": "https://example.com/image.png",
},
})

if err != nil {
t.Error(err)
}

if len(res) != 1 {
t.Error("Query should have returned 1 results")
}
})
}

0 comments on commit 94ff071

Please sign in to comment.