From 761ce7b213cac7930f34f0510e2d79cc36e91bf4 Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Thu, 22 Aug 2024 10:16:50 -0400 Subject: [PATCH] fix date filter with nil value --- internal/connor/ge.go | 2 + internal/connor/gt.go | 2 + internal/connor/le.go | 2 + internal/connor/lt.go | 2 + .../with_filter/with_eq_datetime_test.go | 50 ++++++++++++++++- .../with_filter/with_ge_datetime_test.go | 53 +++++++++++++++++++ .../with_filter/with_gt_datetime_test.go | 48 +++++++++++++++++ .../with_filter/with_le_datetime_test.go | 53 +++++++++++++++++++ .../with_filter/with_lt_datetime_test.go | 49 +++++++++++++++++ .../with_filter/with_ne_datetime_test.go | 53 +++++++++++++++++++ 10 files changed, 313 insertions(+), 1 deletion(-) diff --git a/internal/connor/ge.go b/internal/connor/ge.go index 851c59c53f..055a27b30a 100644 --- a/internal/connor/ge.go +++ b/internal/connor/ge.go @@ -26,6 +26,8 @@ func ge(condition, data any) (bool, error) { return false, err } return dt.After(c) || dt.Equal(c), nil + case nil: + return false, nil default: return false, client.NewErrUnhandledType("data", d) } diff --git a/internal/connor/gt.go b/internal/connor/gt.go index d5689ebd52..c6852a3db3 100644 --- a/internal/connor/gt.go +++ b/internal/connor/gt.go @@ -25,6 +25,8 @@ func gt(condition, data any) (bool, error) { return false, err } return dt.After(c), nil + case nil: + return false, nil default: return false, client.NewErrUnhandledType("data", d) } diff --git a/internal/connor/le.go b/internal/connor/le.go index 0c89c8ffbf..89eca1f3f9 100644 --- a/internal/connor/le.go +++ b/internal/connor/le.go @@ -26,6 +26,8 @@ func le(condition, data any) (bool, error) { return false, err } return dt.Before(c) || dt.Equal(c), nil + case nil: + return false, nil default: return false, client.NewErrUnhandledType("data", d) } diff --git a/internal/connor/lt.go b/internal/connor/lt.go index a7e5e7bb03..7255fc8810 100644 --- a/internal/connor/lt.go +++ b/internal/connor/lt.go @@ -26,6 +26,8 @@ func lt(condition, data any) (bool, error) { return false, err } return dt.Before(c), nil + case nil: + return false, nil default: return false, client.NewErrUnhandledType("data", d) } diff --git a/tests/integration/query/simple/with_filter/with_eq_datetime_test.go b/tests/integration/query/simple/with_filter/with_eq_datetime_test.go index dbf6152244..bdc2b4845f 100644 --- a/tests/integration/query/simple/with_filter/with_eq_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_eq_datetime_test.go @@ -60,7 +60,7 @@ func TestQuerySimpleWithDateTimeEqualsFilterBlock(t *testing.T) { func TestQuerySimpleWithDateTimeEqualsNilFilterBlock(t *testing.T) { test := testUtils.TestCase{ - Description: "Simple query with basic filter(age)", + Description: "Simple query with basic filter(CreatedAt)", Actions: []any{ testUtils.CreateDoc{ Doc: `{ @@ -105,3 +105,51 @@ func TestQuerySimpleWithDateTimeEqualsNilFilterBlock(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeEqualsAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_eq: "2016-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "Name": "Bob", + "Age": int64(32), + "CreatedAt": testUtils.MustParseTime("2016-07-23T03:46:56-05:00"), + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_ge_datetime_test.go b/tests/integration/query/simple/with_filter/with_ge_datetime_test.go index 5c2aacaa00..4ad799d0b0 100644 --- a/tests/integration/query/simple/with_filter/with_ge_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_ge_datetime_test.go @@ -163,3 +163,56 @@ func TestQuerySimpleWithDateTimeGEFilterBlockWithNilValue(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeGEAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_ge: "2016-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "Name": "Bob", + "Age": int64(32), + "CreatedAt": testUtils.MustParseTime("2016-07-23T03:46:56-05:00"), + }, + { + "Name": "John", + "Age": int64(21), + "CreatedAt": testUtils.MustParseTime("2017-07-23T03:46:56-05:00"), + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_gt_datetime_test.go b/tests/integration/query/simple/with_filter/with_gt_datetime_test.go index 67ee8a05a0..956e445573 100644 --- a/tests/integration/query/simple/with_filter/with_gt_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_gt_datetime_test.go @@ -160,3 +160,51 @@ func TestQuerySimpleWithDateTimeGTFilterBlockWithNilValue(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeGTAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_gt: "2016-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "Name": "John", + "Age": int64(21), + "CreatedAt": testUtils.MustParseTime("2017-07-23T03:46:56-05:00"), + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_le_datetime_test.go b/tests/integration/query/simple/with_filter/with_le_datetime_test.go index 6ffbbbac69..1cfe06ac89 100644 --- a/tests/integration/query/simple/with_filter/with_le_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_le_datetime_test.go @@ -128,3 +128,56 @@ func TestQuerySimpleWithDateTimeLEFilterBlockWithNullValue(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeLEAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_le: "2017-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "Name": "Bob", + "Age": int64(32), + "CreatedAt": testUtils.MustParseTime("2016-07-23T03:46:56-05:00"), + }, + { + "Name": "John", + "Age": int64(21), + "CreatedAt": testUtils.MustParseTime("2017-07-23T03:46:56-05:00"), + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_lt_datetime_test.go b/tests/integration/query/simple/with_filter/with_lt_datetime_test.go index a2230b3b20..8fbcf440a2 100644 --- a/tests/integration/query/simple/with_filter/with_lt_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_lt_datetime_test.go @@ -86,3 +86,52 @@ func TestQuerySimpleWithDateTimeLTFilterBlockWithNullValue(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeLTAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_lt: "2017-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + + { + "Name": "Bob", + "Age": int64(32), + "CreatedAt": testUtils.MustParseTime("2016-07-23T03:46:56-05:00"), + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_filter/with_ne_datetime_test.go b/tests/integration/query/simple/with_filter/with_ne_datetime_test.go index 5320a9c7eb..ecc40d3969 100644 --- a/tests/integration/query/simple/with_filter/with_ne_datetime_test.go +++ b/tests/integration/query/simple/with_filter/with_ne_datetime_test.go @@ -100,3 +100,56 @@ func TestQuerySimpleWithDateTimeNotEqualsNilFilterBlock(t *testing.T) { executeTestCase(t, test) } + +func TestQuerySimple_WithNilDateTimeNotEqualAndNonNilFilterBlock_ShouldSucceed(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple query with basic filter with nil value and non-nil filter", + Actions: []any{ + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "John", + "Age": int64(21), + "CreatedAt": "2017-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Bob", + "Age": int64(32), + "CreatedAt": "2016-07-23T03:46:56-05:00", + }, + }, + testUtils.CreateDoc{ + DocMap: map[string]any{ + "Name": "Fred", + "Age": 44, + }, + }, + testUtils.Request{ + Request: `query { + Users(filter: {CreatedAt: {_ne: "2016-07-23T03:46:56-05:00"}}) { + Name + Age + CreatedAt + } + }`, + Results: map[string]any{ + "Users": []map[string]any{ + { + "Name": "John", + "Age": int64(21), + "CreatedAt": testUtils.MustParseTime("2017-07-23T03:46:56-05:00"), + }, + { + "Name": "Fred", + "Age": int64(44), + "CreatedAt": nil, + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +}