@@ -425,6 +425,12 @@ func TestFind(t *testing.T) {
425
425
{ID : "3" , Payload : map [string ]interface {}{"id" : "3" , "name" : "c" , "age" : 3 }},
426
426
{ID : "4" , Payload : map [string ]interface {}{"id" : "4" , "name" : "d" , "age" : 4 }},
427
427
{ID : "5" , Payload : map [string ]interface {}{"id" : "5" , "name" : "rest-layer-regexp" }},
428
+ {ID : "6" , Payload : map [string ]interface {}{"id" : "6" , "name" : "f" ,
429
+ "arr" : []interface {}{
430
+ map [string ]interface {}{"a" : "foo" , "b" : "bar" },
431
+ map [string ]interface {}{"a" : "foo" , "b" : "baz" },
432
+ },
433
+ }},
428
434
}
429
435
doPositiveFindTest := func (t * testing.T , h mongo.Handler , q * query.Query ) * resource.ItemList {
430
436
l , err := h .Find (context .Background (), q )
@@ -608,4 +614,21 @@ func TestFind(t *testing.T) {
608
614
}
609
615
t .Run ("then ItemList.Items should include all matching items" , itemsCheckFunc (expectItems , l ))
610
616
})
617
+ t .Run ("when quering for array of objects match" , func (t * testing.T ) {
618
+ l := doPositiveFindTest (t , h , & query.Query {
619
+ Predicate : query .MustParsePredicate (`{arr:{$elemMatch:{a:"foo"}}}` ),
620
+ })
621
+
622
+ t .Run ("then ItemList.Total should be deduced correctly" , totalCheckFunc (1 , l ))
623
+
624
+ expectItems := []* resource.Item {
625
+ {ID : "6" , ETag : "p-6" , Payload : map [string ]interface {}{"id" : "6" , "name" : "f" ,
626
+ "arr" : []interface {}{
627
+ map [string ]interface {}{"a" : "foo" , "b" : "bar" },
628
+ map [string ]interface {}{"a" : "foo" , "b" : "baz" },
629
+ },
630
+ }},
631
+ }
632
+ t .Run ("then ItemList.Items should include the first matching item" , itemsCheckFunc (expectItems , l ))
633
+ })
611
634
}
0 commit comments