Skip to content

Commit

Permalink
Add test for top-level aggregate with compound relational filter
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Sep 11, 2023
1 parent 482be74 commit b60fe33
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions tests/integration/query/one_to_one/with_count_filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright 2023 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package one_to_one

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQueryOneToOneWithCountWithCompoundOrFilterThatIncludesRelation(t *testing.T) {
test := testUtils.TestCase{
Description: "One-to-one relation with count with _or filter that includes relation",
Actions: []any{
testUtils.SchemaUpdate{
Schema: bookAuthorGQLSchema,
},
testUtils.CreateDoc{
CollectionID: 0,
// bae-fd541c25-229e-5280-b44b-e5c2af3e374d
Doc: `{
"name": "Painted House",
"rating": 4.9
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
// bae-f60d6af6-92f7-5f11-9182-1d7273a5a9e8
Doc: `{
"name": "Some Book",
"rating": 4.0
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
// bae-1c890922-ddf9-5820-a888-c7f977848934
Doc: `{
"name": "Some Other Book",
"rating": 3.5
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
// bae-e8642720-08cb-5f5b-a8d6-7187c444a78d
Doc: `{
"name": "Yet Another Book",
"rating": 3.0
}`,
},
testUtils.CreateDoc{
CollectionID: 1,
// bae-41598f0c-19bc-5da6-813b-e80f14a10df3
Doc: `{
"name": "John Grisham",
"age": 65,
"verified": true,
"published_id": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d"
}`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "Some Writer",
"age": 45,
"verified": false,
"published_id": "bae-f60d6af6-92f7-5f11-9182-1d7273a5a9e8"
}`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "Some Other Writer",
"age": 35,
"verified": false,
"published_id": "bae-1c890922-ddf9-5820-a888-c7f977848934"
}`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "Yet Another Writer",
"age": 30,
"verified": false,
"published_id": "bae-e8642720-08cb-5f5b-a8d6-7187c444a78d"
}`,
},
testUtils.Request{
Request: `query {
Book(filter: {_or: [
{_and: [
{rating: {_ge: 4.0}},
{author: {age: {_le: 45}}}
]},
{_and: [
{rating: {_le: 3.5}},
{author: {age: {_ge: 35}}}
]}
]}) {
name
}
}`,
Results: []map[string]any{
{
"name": "Some Other Book",
},
{
"name": "Some Book",
},
},
},
testUtils.Request{
Request: `query {
_count(Book: {filter: {_or: [
{_not: {author: {age: {_lt: 65}}} },
{_not: {author: {age: {_gt: 30}}} }
]}})
}`,
Results: []map[string]any{
{
"_count": "2",
},
},
},
},
}

testUtils.AssertPanicAndSkipChangeDetection(
t,
func() {
testUtils.ExecuteTestCase(t, test)
},
)
}

0 comments on commit b60fe33

Please sign in to comment.