Skip to content

Commit

Permalink
test: Add tests for inline array grouping (sourcenetwork#752)
Browse files Browse the repository at this point in the history
Add tests for inline array grouping
  • Loading branch information
AndrewSisley authored Aug 23, 2022
1 parent 13e1661 commit 1b42922
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions tests/integration/query/inline_array/with_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// 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 inline_array

import (
"testing"

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

func TestQueryInlineArrayWithGroupByString(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple inline array with no filter, mixed integers, group by string",
Query: `query {
users (groupBy: [Name]) {
Name
_group {
FavouriteIntegers
}
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "Shahzad",
"FavouriteIntegers": [-1, 2, -1, 1, 0]
}`,
`{
"Name": "Shahzad",
"FavouriteIntegers": [1, -2, 1, -1, 0]
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "Shahzad",
"_group": []map[string]interface{}{
{
"FavouriteIntegers": []int64{-1, 2, -1, 1, 0},
},
{
"FavouriteIntegers": []int64{1, -2, 1, -1, 0},
},
},
},
},
}

executeTestCase(t, test)
}

func TestQueryInlineArrayWithGroupByArray(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple inline array with no filter, mixed integers, group by array",
Query: `query {
users (groupBy: [FavouriteIntegers]) {
FavouriteIntegers
_group {
Name
}
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "Andy",
"FavouriteIntegers": [-1, 2, -1, 1, 0]
}`,
`{
"Name": "Shahzad",
"FavouriteIntegers": [-1, 2, -1, 1, 0]
}`,
`{
"Name": "John",
"FavouriteIntegers": [1, 2, 3]
}`,
},
},
Results: []map[string]interface{}{
{
"FavouriteIntegers": []int64{-1, 2, -1, 1, 0},
"_group": []map[string]interface{}{
{
"Name": "Shahzad",
},
{
"Name": "Andy",
},
},
},
{
"FavouriteIntegers": []int64{1, 2, 3},
"_group": []map[string]interface{}{
{
"Name": "John",
},
},
},
},
}

executeTestCase(t, test)
}

0 comments on commit 1b42922

Please sign in to comment.