Skip to content

Commit

Permalink
PR(TEST): Add group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Jun 8, 2023
1 parent 69b1ceb commit 10bbbbb
Show file tree
Hide file tree
Showing 10 changed files with 894 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/integration/explain/debug/group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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 test_explain_debug

import (
"testing"

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

var groupPattern = dataMap{
"explain": dataMap{
"selectTopNode": dataMap{
"groupNode": dataMap{
"selectNode": dataMap{
"pipeNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
}

func TestDebugExplainRequestWithGroupByOnParent(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with group-by on parent.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [age]) {
age
_group {
name
}
}
}`,

ExpectedFullGraph: []dataMap{groupPattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

func TestDebugExplainRequestWithGroupByTwoFieldsOnParent(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with group-by two fields on parent.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [age, name]) {
age
_group {
name
}
}
}`,

ExpectedFullGraph: []dataMap{groupPattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
157 changes: 157 additions & 0 deletions tests/integration/explain/debug/group_with_average_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// 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 test_explain_debug

import (
"testing"

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

var debugGroupAveragePattern = dataMap{
"explain": dataMap{
"selectTopNode": dataMap{
"averageNode": dataMap{
"countNode": dataMap{
"sumNode": dataMap{
"groupNode": dataMap{
"selectNode": dataMap{
"pipeNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
},
},
},
}

func TestDebugExplainRequestWithGroupByWithAverageOnAnInnerField(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with group-by with average on inner field.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [name]) {
name
_avg(_group: {field: age})
}
}`,

ExpectedPatterns: []dataMap{debugGroupAveragePattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

func TestDebugExplainRequestWithAverageInsideTheInnerGroupOnAField(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with group-by with average of the inner _group on a field.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [name]) {
name
_avg(_group: {field: _avg})
_group(groupBy: [verified]) {
verified
_avg(_group: {field: age})
}
}
}`,

ExpectedPatterns: []dataMap{debugGroupAveragePattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

func TestDebugExplainRequestWithAverageInsideTheInnerGroupOnAFieldAndNestedGroupBy(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with group-by with average of the inner _group on a field and nested group-by.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [name]) {
name
_avg(_group: {field: _avg})
_group(groupBy: [verified]) {
verified
_avg(_group: {field: age})
_group (groupBy: [age]){
age
}
}
}
}`,

ExpectedPatterns: []dataMap{debugGroupAveragePattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

func TestDebugExplainRequestWithAverageInsideTheInnerGroupAndNestedGroupByWithAverage(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with average inside the inner _group and nested groupBy with average.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author (groupBy: [name]) {
name
_avg(_group: {field: _avg})
_group(groupBy: [verified]) {
verified
_avg(_group: {field: age})
_group (groupBy: [age]){
age
_avg(_group: {field: age})
}
}
}
}`,

ExpectedPatterns: []dataMap{debugGroupAveragePattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
47 changes: 47 additions & 0 deletions tests/integration/explain/debug/group_with_dockey_child_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 test_explain_debug

import (
"testing"

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

func TestDebugExplainRequestWithDockeysOnInnerGroupSelection(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with dockeys on inner _group.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author(
groupBy: [age]
) {
age
_group(dockeys: ["bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"]) {
name
}
}
}`,

ExpectedPatterns: []dataMap{groupPattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
82 changes: 82 additions & 0 deletions tests/integration/explain/debug/group_with_dockey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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 test_explain_debug

import (
"testing"

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

func TestDebugExplainRequestWithDockeyOnParentGroupBy(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with a dockey on parent groupBy.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author(
groupBy: [age],
dockey: "bae-6a4c5bc5-b044-5a03-a868-8260af6f2254"
) {
age
_group {
name
}
}
}`,

ExpectedPatterns: []dataMap{groupPattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}

func TestDebugExplainRequestWithDockeysAndFilterOnParentGroupBy(t *testing.T) {
test := testUtils.TestCase{

Description: "Explain (debug) request with dockeys and filter on parent groupBy.",

Actions: []any{
explainUtils.SchemaForExplainTests,

testUtils.ExplainRequest{

Request: `query @explain(type: debug) {
Author(
groupBy: [age],
filter: {age: {_eq: 20}},
dockeys: [
"bae-6a4c5bc5-b044-5a03-a868-8260af6f2254",
"bae-4ea9d148-13f3-5a48-a0ef-9ffd344caeed"
]
) {
age
_group {
name
}
}
}`,

ExpectedPatterns: []dataMap{groupPattern},
},
},
}

explainUtils.ExecuteTestCase(t, test)
}
Loading

0 comments on commit 10bbbbb

Please sign in to comment.