Skip to content

Commit 0077c94

Browse files
authored
fix #2 (#3)
* fix #2
1 parent 4c31f4c commit 0077c94

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

query/query.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func test(data interface{}, userQuery interface{}) (bool, error) {
196196

197197
} else {
198198

199+
if userQuery == nil || data == nil {
200+
return false, nil
201+
}
202+
199203
bool, err1 := rules.Eq.Match(data, userQuery)
200204

201205
if err1 != nil {

test/exists_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package test
22

33
import (
4-
"github.com/wearetheledger/go-couchdb-query-engine/query"
54
"testing"
5+
6+
"github.com/wearetheledger/go-couchdb-query-engine/query"
67
)
78

89
func TestExists(t *testing.T) {

test/main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var TestData = map[string]interface{}{
3636
"MARBLE3": map[string]interface{}{
3737
"objectType": "MARBLE",
3838
"owner": "arnold",
39+
"image": "https://example.com/image.png",
3940
"size": 5,
4041
"previousOwners": []string{
4142
"alice",
@@ -68,4 +69,4 @@ res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
6869
},
6970
},
7071
})
71-
*/
72+
*/

test/missing_properties_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/wearetheledger/go-couchdb-query-engine/query"
7+
)
8+
9+
func TestQueryWithSomeMissingProperties(t *testing.T) {
10+
11+
t.Run("Element should be returned when properties are missing in other records", func(t *testing.T) {
12+
13+
res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
14+
"selector": map[string]interface{}{
15+
"image": "https://example.com/image.png",
16+
},
17+
})
18+
19+
if err != nil {
20+
t.Error(err)
21+
}
22+
23+
if len(res) != 1 {
24+
t.Error("Query should have returned 1 results")
25+
}
26+
})
27+
}

0 commit comments

Comments
 (0)