diff --git a/tests/integration/query/simple/with_dockey_test.go b/tests/integration/query/simple/with_dockey_test.go new file mode 100644 index 0000000000..c45b649b3e --- /dev/null +++ b/tests/integration/query/simple/with_dockey_test.go @@ -0,0 +1,91 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithDocKeyFilter(t *testing.T) { + tests := []testUtils.QueryTestCase{ + { + Description: "Simple query with basic filter (key by DocKey arg)", + Query: `query { + users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + { + Description: "Simple query with basic filter (key by DocKey arg), no results", + Query: `query { + users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009g") { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`)}, + }, + Results: []map[string]interface{}{}, + }, + { + Description: "Simple query with basic filter (key by DocKey arg), partial results", + Query: `query { + users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + } + + for _, test := range tests { + executeTestCase(t, test) + } +} diff --git a/tests/integration/query/simple/with_dockeys_test.go b/tests/integration/query/simple/with_dockeys_test.go new file mode 100644 index 0000000000..0bd380c026 --- /dev/null +++ b/tests/integration/query/simple/with_dockeys_test.go @@ -0,0 +1,125 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithDocKeysFilter(t *testing.T) { + tests := []testUtils.QueryTestCase{ + { + Description: "Simple query with basic filter (single key by DocKeys arg)", + Query: `query { + users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + { + Description: "Simple query with basic filter (single key by DocKeys arg), no results", + Query: `query { + users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009g"]) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`)}, + }, + Results: []map[string]interface{}{}, + }, + { + Description: "Simple query with basic filter (duplicate key by DocKeys arg), partial results", + Query: `query { + users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + { + Description: "Simple query with basic filter (multiple key by DocKeys arg), partial results", + Query: `query { + users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-1378ab62-e064-5af4-9ea6-49941c8d8f94"]) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + (`{ + "Name": "Jim", + "Age": 27 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "Jim", + "Age": uint64(27), + }, + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + } + + for _, test := range tests { + executeTestCase(t, test) + } +} diff --git a/tests/integration/query/simple/with_filter/README.md b/tests/integration/query/simple/with_filter/README.md new file mode 100644 index 0000000000..6564b27c60 --- /dev/null +++ b/tests/integration/query/simple/with_filter/README.md @@ -0,0 +1,3 @@ +# With filter integration tests + +Dedicated directory for simple schema integration tests targeting filter stuff. diff --git a/tests/integration/query/simple/with_filter/utils.go b/tests/integration/query/simple/with_filter/utils.go new file mode 100644 index 0000000000..69382c8eaa --- /dev/null +++ b/tests/integration/query/simple/with_filter/utils.go @@ -0,0 +1,30 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +var userCollectionGQLSchema = (` + type users { + Name: String + Age: Int + HeightM: Float + Verified: Boolean + } +`) + +func executeTestCase(t *testing.T, test testUtils.QueryTestCase) { + testUtils.ExecuteQueryTestCase(t, userCollectionGQLSchema, []string{"users"}, test) +} diff --git a/tests/integration/query/simple/with_filter/with_and_test.go b/tests/integration/query/simple/with_filter/with_and_test.go new file mode 100644 index 0000000000..071fb4d1a0 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_and_test.go @@ -0,0 +1,60 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntGreaterThanAndIntLessThanFilter(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with logical compound filter (and)", + Query: `query { + users(filter: {_and: [{Age: {_gt: 20}}, {Age: {_lt: 50}}]}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + (`{ + "Name": "Carlo", + "Age": 55 + }`), + (`{ + "Name": "Alice", + "Age": 19 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + "Age": uint64(32), + }, + { + "Name": "John", + "Age": uint64(21), + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_eq_float_test.go b/tests/integration/query/simple/with_filter/with_eq_float_test.go new file mode 100644 index 0000000000..f64d6a724a --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_eq_float_test.go @@ -0,0 +1,49 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithFloatEqualsFilterBlock(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic float filter", + Query: `query { + users(filter: {HeightM: {_eq: 2.1}}) { + Name + HeightM + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "HeightM": float64(2.1), + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_eq_int_test.go b/tests/integration/query/simple/with_filter/with_eq_int_test.go new file mode 100644 index 0000000000..193877c4a3 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_eq_int_test.go @@ -0,0 +1,48 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntEqualsFilterBlock(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic filter(age)", + Query: `query { + users(filter: {Age: {_eq: 21}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_eq_string_test.go b/tests/integration/query/simple/with_filter/with_eq_string_test.go new file mode 100644 index 0000000000..0e0646bd9b --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_eq_string_test.go @@ -0,0 +1,122 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithStringFilterBlock(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic filter (Name)", + Query: `query { + users(filter: {Name: {_eq: "John"}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithStringFilterBlockAndSelect(t *testing.T) { + tests := []testUtils.QueryTestCase{ + { + Description: "Simple query with basic filter and selection", + Query: `query { + users(filter: {Name: {_eq: "John"}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + }, + { + Description: "Simple query with basic filter and selection (diff from filter)", + Query: `query { + users(filter: {Name: {_eq: "John"}}) { + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Age": uint64(21), + }, + }, + }, + { + Description: "Simple query with basic filter(name), no results", + Query: `query { + users(filter: {Name: {_eq: "Bob"}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`)}, + }, + Results: []map[string]interface{}{}, + }, + } + + for _, test := range tests { + executeTestCase(t, test) + } +} diff --git a/tests/integration/query/simple/with_filter/with_ge_float_test.go b/tests/integration/query/simple/with_filter/with_ge_float_test.go new file mode 100644 index 0000000000..1b372d8782 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_ge_float_test.go @@ -0,0 +1,107 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithHeightMGEFilterBlockWithEqualValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic ge int filter with equal value", + Query: `query { + users(filter: {HeightM: {_ge: 2.1}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithHeightMGEFilterBlockWithLesserValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic ge int filter with lesser value", + Query: `query { + users(filter: {HeightM: {_ge: 2.0999999999999}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithHeightMGEFilterBlockWithLesserIntValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic ge int filter with lesser int value", + Query: `query { + users(filter: {HeightM: {_ge: 2}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_ge_int_test.go b/tests/integration/query/simple/with_filter/with_ge_int_test.go new file mode 100644 index 0000000000..d3e03a7d33 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_ge_int_test.go @@ -0,0 +1,77 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntGEFilterBlockWithEqualValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic ge int filter with equal value", + Query: `query { + users(filter: {Age: {_ge: 32}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithIntGEFilterBlockWithGreaterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic ge int filter with greater value", + Query: `query { + users(filter: {Age: {_ge: 31}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_gt_float_test.go b/tests/integration/query/simple/with_filter/with_gt_float_test.go new file mode 100644 index 0000000000..5e4eb1fc4c --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_gt_float_test.go @@ -0,0 +1,130 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithFloatGreaterThanFilterBlock(t *testing.T) { + tests := []testUtils.QueryTestCase{ + { + Description: "Simple query with basic float greater than filter", + Query: `query { + users(filter: {HeightM: {_gt: 2.0999999999999}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + }, + { + Description: "Simple query with basic float greater than filter, no results", + Query: `query { + users(filter: {HeightM: {_gt: 40}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{}, + }, + { + Description: "Simple query with basic float greater than filter, multiple results", + Query: `query { + users(filter: {HeightM: {_gt: 1.8199999999999}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + { + "Name": "John", + }, + }, + }, + } + + for _, test := range tests { + executeTestCase(t, test) + } +} + +func TestQuerySimpleWithFloatGreaterThanFilterBlockWithIntFilterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic float greater than filter, with int filter value", + Query: `query { + users(filter: {HeightM: {_gt: 2}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_gt_int_test.go b/tests/integration/query/simple/with_filter/with_gt_int_test.go new file mode 100644 index 0000000000..e9be2a8b48 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_gt_int_test.go @@ -0,0 +1,103 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntGreaterThanFilterBlock(t *testing.T) { + tests := []testUtils.QueryTestCase{ + { + Description: "Simple query with basic filter(age), greater than", + Query: `query { + users(filter: {Age: {_gt: 20}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 19 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + { + Description: "Simple query with basic filter(age), no results", + Query: `query { + users(filter: {Age: {_gt: 40}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{}, + }, + { + Description: "Simple query with basic filter(age), multiple results", + Query: `query { + users(filter: {Age: {_gt: 20}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + "Age": uint64(32), + }, + { + "Name": "John", + "Age": uint64(21), + }, + }, + }, + } + + for _, test := range tests { + executeTestCase(t, test) + } +} diff --git a/tests/integration/query/simple/with_filter/with_in_test.go b/tests/integration/query/simple/with_filter/with_in_test.go new file mode 100644 index 0000000000..600f8714e9 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_in_test.go @@ -0,0 +1,60 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntInFilter(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with special filter (or)", + Query: `query { + users(filter: {Age: {_in: [19, 40, 55]}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + (`{ + "Name": "Carlo", + "Age": 55 + }`), + (`{ + "Name": "Alice", + "Age": 19 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "Alice", + "Age": uint64(19), + }, + { + "Name": "Carlo", + "Age": uint64(55), + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_le_float_test.go b/tests/integration/query/simple/with_filter/with_le_float_test.go new file mode 100644 index 0000000000..0b33f3c238 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_le_float_test.go @@ -0,0 +1,107 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithFloatLEFilterBlockWithEqualValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic le float filter with equal value", + Query: `query { + users(filter: {HeightM: {_le: 1.82}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithFloatLEFilterBlockWithGreaterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic le float filter with greater value", + Query: `query { + users(filter: {HeightM: {_le: 1.820000000001}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithFloatLEFilterBlockWithGreaterIntValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic le float filter with greater int value", + Query: `query { + users(filter: {HeightM: {_le: 2}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_le_int_test.go b/tests/integration/query/simple/with_filter/with_le_int_test.go new file mode 100644 index 0000000000..f7c4c37738 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_le_int_test.go @@ -0,0 +1,77 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntLEFilterBlockWithEqualValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic le int filter with equal value", + Query: `query { + users(filter: {Age: {_le: 21}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithIntLEFilterBlockWithGreaterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic le int filter with greater value", + Query: `query { + users(filter: {Age: {_le: 22}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_lt_float_test.go b/tests/integration/query/simple/with_filter/with_lt_float_test.go new file mode 100644 index 0000000000..1850d0b402 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_lt_float_test.go @@ -0,0 +1,77 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithFloatLessThanFilterBlockWithGreaterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic lt float filter with greater value", + Query: `query { + users(filter: {HeightM: {_lt: 1.820000000001}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithFloatLessThanFilterBlockWithGreaterIntValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic lt float filter with greater int value", + Query: `query { + users(filter: {HeightM: {_lt: 2}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "HeightM": 2.1 + }`, + `{ + "Name": "Bob", + "HeightM": 1.82 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_lt_int_test.go b/tests/integration/query/simple/with_filter/with_lt_int_test.go new file mode 100644 index 0000000000..8e51863c85 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_lt_int_test.go @@ -0,0 +1,47 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntLessThanFilterBlockWithGreaterValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic lt int filter with greater value", + Query: `query { + users(filter: {Age: {_lt: 22}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_nin_test.go b/tests/integration/query/simple/with_filter/with_nin_test.go new file mode 100644 index 0000000000..77a247cc57 --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_nin_test.go @@ -0,0 +1,58 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithNotInFilter(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with not-in filter", + Query: `query { + users(filter: {Age: {_nin: [19, 40, 55]}}) { + Name + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "Age": 21 + }`, + `{ + "Name": "Bob", + "Age": 32 + }`, + `{ + "Name": "Carlo", + "Age": 55 + }`, + `{ + "Name": "Alice", + "Age": 19 + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "Bob", + }, + { + "Name": "John", + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_or_test.go b/tests/integration/query/simple/with_filter/with_or_test.go new file mode 100644 index 0000000000..321c6cad9b --- /dev/null +++ b/tests/integration/query/simple/with_filter/with_or_test.go @@ -0,0 +1,60 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithIntEqualToXOrYFilter(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with logical compound filter (or)", + Query: `query { + users(filter: {_or: [{Age: {_eq: 55}}, {Age: {_eq: 19}}]}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`), + (`{ + "Name": "Carlo", + "Age": 55 + }`), + (`{ + "Name": "Alice", + "Age": 19 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "Alice", + "Age": uint64(19), + }, + { + "Name": "Carlo", + "Age": uint64(55), + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter_test.go b/tests/integration/query/simple/with_filter_test.go deleted file mode 100644 index 3181713116..0000000000 --- a/tests/integration/query/simple/with_filter_test.go +++ /dev/null @@ -1,581 +0,0 @@ -// Copyright 2022 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 simple - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestQuerySimpleWithDocKeyFilter(t *testing.T) { - tests := []testUtils.QueryTestCase{ - { - Description: "Simple query with basic filter (key by DocKey arg)", - Query: `query { - users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - { - Description: "Simple query with basic filter (key by DocKey arg), no results", - Query: `query { - users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009g") { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`)}, - }, - Results: []map[string]interface{}{}, - }, - { - Description: "Simple query with basic filter (key by DocKey arg), partial results", - Query: `query { - users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - } - - for _, test := range tests { - executeTestCase(t, test) - } -} - -func TestQuerySimpleWithDocKeysFilter(t *testing.T) { - tests := []testUtils.QueryTestCase{ - { - Description: "Simple query with basic filter (single key by DocKeys arg)", - Query: `query { - users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - { - Description: "Simple query with basic filter (single key by DocKeys arg), no results", - Query: `query { - users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009g"]) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`)}, - }, - Results: []map[string]interface{}{}, - }, - { - Description: "Simple query with basic filter (duplicate key by DocKeys arg), partial results", - Query: `query { - users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - { - Description: "Simple query with basic filter (multiple key by DocKeys arg), partial results", - Query: `query { - users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-1378ab62-e064-5af4-9ea6-49941c8d8f94"]) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`), - (`{ - "Name": "Jim", - "Age": 27 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "Jim", - "Age": uint64(27), - }, - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - } - - for _, test := range tests { - executeTestCase(t, test) - } -} - -func TestQuerySimpleWithKeyFilterBlock(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with basic filter (key by filter block)", - Query: `query { - users(filter: {_key: {_eq: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - } - - executeTestCase(t, test) -} - -func TestQuerySimpleWithStringFilterBlock(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with basic filter (Name)", - Query: `query { - users(filter: {Name: {_eq: "John"}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - } - - executeTestCase(t, test) -} - -func TestQuerySimpleWithStringFilterBlockAndSelect(t *testing.T) { - tests := []testUtils.QueryTestCase{ - { - Description: "Simple query with basic filter and selection", - Query: `query { - users(filter: {Name: {_eq: "John"}}) { - Name - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - }, - }, - }, - { - Description: "Simple query with basic filter and selection (diff from filter)", - Query: `query { - users(filter: {Name: {_eq: "John"}}) { - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Age": uint64(21), - }, - }, - }, - { - Description: "Simple query with basic filter(name), no results", - Query: `query { - users(filter: {Name: {_eq: "Bob"}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`)}, - }, - Results: []map[string]interface{}{}, - }, - } - - for _, test := range tests { - executeTestCase(t, test) - } -} - -func TestQuerySimpleWithNumberEqualsFilterBlock(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with basic filter(age)", - Query: `query { - users(filter: {Age: {_eq: 21}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - } - - executeTestCase(t, test) -} - -func TestQuerySimpleWithNumberGreaterThanFilterBlock(t *testing.T) { - tests := []testUtils.QueryTestCase{ - { - Description: "Simple query with basic filter(age), greater than", - Query: `query { - users(filter: {Age: {_gt: 20}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 19 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - { - Description: "Simple query with basic filter(age), no results", - Query: `query { - users(filter: {Age: {_gt: 40}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{}, - }, - { - Description: "Simple query with basic filter(age), multiple results", - Query: `query { - users(filter: {Age: {_gt: 20}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "Bob", - "Age": uint64(32), - }, - { - "Name": "John", - "Age": uint64(21), - }, - }, - }, - } - - for _, test := range tests { - executeTestCase(t, test) - } -} - -func TestQuerySimpleWithNumberGreaterThanAndNumberLessThanFilter(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with logical compound filter (and)", - Query: `query { - users(filter: {_and: [{Age: {_gt: 20}}, {Age: {_lt: 50}}]}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`), - (`{ - "Name": "Carlo", - "Age": 55 - }`), - (`{ - "Name": "Alice", - "Age": 19 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "Bob", - "Age": uint64(32), - }, - { - "Name": "John", - "Age": uint64(21), - }, - }, - } - - executeTestCase(t, test) -} - -func TestQuerySimpleWithNumberEqualToXOrYFilter(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with logical compound filter (or)", - Query: `query { - users(filter: {_or: [{Age: {_eq: 55}}, {Age: {_eq: 19}}]}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`), - (`{ - "Name": "Carlo", - "Age": 55 - }`), - (`{ - "Name": "Alice", - "Age": 19 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "Alice", - "Age": uint64(19), - }, - { - "Name": "Carlo", - "Age": uint64(55), - }, - }, - } - - executeTestCase(t, test) -} - -func TestQuerySimpleWithNumberInFilter(t *testing.T) { - test := testUtils.QueryTestCase{ - Description: "Simple query with special filter (or)", - Query: `query { - users(filter: {Age: {_in: [19, 40, 55]}}) { - Name - Age - } - }`, - Docs: map[int][]string{ - 0: { - (`{ - "Name": "John", - "Age": 21 - }`), - (`{ - "Name": "Bob", - "Age": 32 - }`), - (`{ - "Name": "Carlo", - "Age": 55 - }`), - (`{ - "Name": "Alice", - "Age": 19 - }`)}, - }, - Results: []map[string]interface{}{ - { - "Name": "Alice", - "Age": uint64(19), - }, - { - "Name": "Carlo", - "Age": uint64(55), - }, - }, - } - - executeTestCase(t, test) -} diff --git a/tests/integration/query/simple/with_key_test.go b/tests/integration/query/simple/with_key_test.go new file mode 100644 index 0000000000..2d6e1d7a89 --- /dev/null +++ b/tests/integration/query/simple/with_key_test.go @@ -0,0 +1,48 @@ +// Copyright 2022 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimpleWithKeyFilterBlock(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with basic filter (key by filter block)", + Query: `query { + users(filter: {_key: {_eq: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"}}) { + Name + Age + } + }`, + Docs: map[int][]string{ + 0: { + (`{ + "Name": "John", + "Age": 21 + }`), + (`{ + "Name": "Bob", + "Age": 32 + }`)}, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Age": uint64(21), + }, + }, + } + + executeTestCase(t, test) +}