From aad0efc5c41bbf260737472c96827932ae217050 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 8 Jul 2022 14:29:42 -0400 Subject: [PATCH] Add tests for default properties --- .../query/inline_array/simple_test.go | 22 +++++++ tests/integration/query/simple/simple_test.go | 58 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/tests/integration/query/inline_array/simple_test.go b/tests/integration/query/inline_array/simple_test.go index 69482603c9..a18fb2d38a 100644 --- a/tests/integration/query/inline_array/simple_test.go +++ b/tests/integration/query/inline_array/simple_test.go @@ -93,6 +93,28 @@ func TestQueryInlineArrayWithBooleans(t *testing.T) { func TestQueryInlineArrayWithIntegers(t *testing.T) { tests := []testUtils.QueryTestCase{ + { + Description: "Simple inline array with no filter, default integer array", + Query: `query { + users { + Name + FavouriteIntegers + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John" + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "FavouriteIntegers": nil, + }, + }, + }, { Description: "Simple inline array with no filter, nil integer array", Query: `query { diff --git a/tests/integration/query/simple/simple_test.go b/tests/integration/query/simple/simple_test.go index 904379be6d..ed2fc2a88d 100644 --- a/tests/integration/query/simple/simple_test.go +++ b/tests/integration/query/simple/simple_test.go @@ -121,3 +121,61 @@ func TestQuerySimpleWithUndefinedField(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimpleWithSomeDefaultValues(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with some default-value fields", + Query: `query { + users { + Name + Email + Age + HeightM + Verified + } + }`, + Docs: map[int][]string{ + 0: { + `{ + "Name": "John" + }`, + }, + }, + Results: []map[string]interface{}{ + { + "Name": "John", + "Email": nil, + "Age": nil, + "HeightM": nil, + "Verified": nil, + }, + }, + } + + executeTestCase(t, test) +} + +// This test documents undesirable behaviour and should be altered +// with https://github.com/sourcenetwork/defradb/issues/610. +// A document with nil fields should be returned. +func TestQuerySimpleWithDefaultValue(t *testing.T) { + test := testUtils.QueryTestCase{ + Description: "Simple query with default-value fields", + Query: `query { + users { + Name + Age + HeightM + Verified + } + }`, + Docs: map[int][]string{ + 0: { + `{ }`, + }, + }, + Results: []map[string]interface{}{}, + } + + executeTestCase(t, test) +}