From 8bfa6c875bf5d56377613cdf0d10090ebea980fc Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Tue, 21 Jun 2022 11:15:12 -0400 Subject: [PATCH] Add tests for grouping by undefined value --- .../query/simple/with_group_test.go | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/integration/query/simple/with_group_test.go b/tests/integration/query/simple/with_group_test.go index e183566ccd..44f2c350a8 100644 --- a/tests/integration/query/simple/with_group_test.go +++ b/tests/integration/query/simple/with_group_test.go @@ -457,3 +457,89 @@ func TestQuerySimpleWithGroupByBooleanThenNumber(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimpleWithGroupByNumberOnUndefined(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with group by number, no children, undefined group value", + Query: `query { + users(groupBy: [Age]) { + Age + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "Age": 32 + }`, + `{ + "Name": "Bob" + }`, + `{ + "Name": "Alice" + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Age": nil, + }, + { + "Age": uint64(32), + }, + }, + } + + executeTestCase(t, test) +} + +func TestQuerySimpleWithGroupByNumberOnUndefinedWithChildren(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with group by number, with children, undefined group value", + Query: `query { + users(groupBy: [Age]) { + Age + _group { + Name + } + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John", + "Age": 32 + }`, + `{ + "Name": "Bob" + }`, + `{ + "Name": "Alice" + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Age": nil, + "_group": []map[string]interface{}{ + { + "Name": "Bob", + }, + { + "Name": "Alice", + }, + }, + }, + { + "Age": uint64(32), + "_group": []map[string]interface{}{ + { + "Name": "John", + }, + }, + }, + }, + } + + executeTestCase(t, test) +}