From 60e8f90a32c09f92e9ee2d6d90898466a81c24dd Mon Sep 17 00:00:00 2001 From: AndrewSisley Date: Tue, 21 Mar 2023 17:43:59 -0400 Subject: [PATCH] refactor: Migrate gql introspection tests to new framework (#1211) * Use reflect for action bundling The code is shorter but more complex. Importantly it means that we do not need to remember to add new action types to 3 code locations (len calc, flatten, main-loop) within the framework, something that is error prone and a bit of a hassle. * Add gql introspection support to test framework Code is copy-pasted from existing schema/utils.go file, plus a couple of compilation tweaks and var renames. * Migrate client_test.go to new framework No changes to test content * Migrate filter_test.go to new framework No changes to test contents * Migrate input_type_test.go to new framework No changes to test contents * Migrate simple_test.go to new framework Due to differences in error handling some of these tests have changed slightly. In the old introspection tests, `ExpectedErrrors` would be compared against errrors generated during schema update, and during introspection - the new framework ties an expected error to a specific action. For these tests it is now clear that the errors occur on schema update, and not during introspection. This means that in the original, the introspection query was declared but never actually run (test would exist early on expected error), as such this commit also removes the declaration of these never-executed introspection queries. * Migrate with_inline_array_test.go to new framework No changes to test contents * Migrate inline_array_test.go to new framework No changes to test contents * Migrate simple_test.go to new framework No changes to test contents * Migrate top_level_test.go to new framework No changes to test contents * Remove old test utils --- .../schema/aggregates/inline_array_test.go | 2178 +++++++++-------- .../schema/aggregates/simple_test.go | 424 ++-- .../schema/aggregates/top_level_test.go | 396 +-- tests/integration/schema/client_test.go | 44 +- tests/integration/schema/filter_test.go | 336 +-- tests/integration/schema/input_type_test.go | 190 +- tests/integration/schema/simple_test.go | 280 ++- tests/integration/schema/utils.go | 181 -- .../schema/with_inline_array_test.go | 98 +- tests/integration/test_case.go | 27 + tests/integration/utils2.go | 136 +- 11 files changed, 2141 insertions(+), 2149 deletions(-) delete mode 100644 tests/integration/schema/utils.go diff --git a/tests/integration/schema/aggregates/inline_array_test.go b/tests/integration/schema/aggregates/inline_array_test.go index b84ad7d62d..ab947b5ed7 100644 --- a/tests/integration/schema/aggregates/inline_array_test.go +++ b/tests/integration/schema/aggregates/inline_array_test.go @@ -13,114 +13,118 @@ package aggregates import ( "testing" - testUtils "github.com/sourcenetwork/defradb/tests/integration/schema" + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestSchemaAggregateInlineArrayCreatesUsersCount(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - FavouriteIntegers: [Int!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + FavouriteIntegers: [Int!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name + inputFields { + name + type { + name + } + } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "FavouriteIntegers", - "type": map[string]any{ - "name": "users__FavouriteIntegers__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullIntFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "FavouriteIntegers", + "type": map[string]any{ + "name": "users__FavouriteIntegers__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullIntFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, - }, - }, - map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, - }, - }, - map[string]any{ - "name": "_version", - "type": map[string]any{ - "name": "users___version__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + map[string]any{ + "name": "_version", + "type": map[string]any{ + "name": "users___version__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, @@ -133,112 +137,116 @@ func TestSchemaAggregateInlineArrayCreatesUsersCount(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersSum(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - FavouriteFloats: [Float!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + FavouriteFloats: [Float!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name + inputFields { + name + type { + name + } + } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_sum", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "FavouriteFloats", - "type": map[string]any{ - "name": "users__FavouriteFloats__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullFloatFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "Ordering", + "name": "_sum", + "args": []any{ + map[string]any{ + "name": "FavouriteFloats", + "type": map[string]any{ + "name": "users__FavouriteFloats__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullFloatFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "Ordering", + }, + }, }, }, }, - }, - }, - map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + }, + }, }, }, }, @@ -251,112 +259,116 @@ func TestSchemaAggregateInlineArrayCreatesUsersSum(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersAverage(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - FavouriteIntegers: [Int!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + FavouriteIntegers: [Int!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name + inputFields { + name + type { + name + } + } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_avg", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "FavouriteIntegers", - "type": map[string]any{ - "name": "users__FavouriteIntegers__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullIntFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "Ordering", + "name": "_avg", + "args": []any{ + map[string]any{ + "name": "FavouriteIntegers", + "type": map[string]any{ + "name": "users__FavouriteIntegers__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullIntFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "Ordering", + }, + }, }, }, }, - }, - }, - map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + }, + }, }, }, }, @@ -369,7 +381,7 @@ func TestSchemaAggregateInlineArrayCreatesUsersAverage(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } var aggregateGroupArg = map[string]any{ @@ -451,25 +463,23 @@ var aggregateVersionArg = map[string]any{ } func TestSchemaAggregateInlineArrayCreatesUsersNillableBooleanCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Boolean] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Boolean] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -477,6 +487,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableBooleanCountFilter(t *tes name type { name + inputFields { + name + type { + name + } + } } } } @@ -484,84 +500,84 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableBooleanCountFilter(t *tes } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "BooleanFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Boolean", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "BooleanFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Boolean", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Boolean", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Boolean", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -569,29 +585,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableBooleanCountFilter(t *tes }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersBooleanCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Boolean!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Boolean!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -599,6 +613,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersBooleanCountFilter(t *testing.T) name type { name + inputFields { + name + type { + name + } + } } } } @@ -606,84 +626,84 @@ func TestSchemaAggregateInlineArrayCreatesUsersBooleanCountFilter(t *testing.T) } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullBooleanFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Boolean", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullBooleanFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Boolean", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Boolean", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Boolean", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -691,29 +711,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersBooleanCountFilter(t *testing.T) }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersNillableIntegerCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Int] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Int] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -721,6 +739,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableIntegerCountFilter(t *tes name type { name + inputFields { + name + type { + name + } + } } } } @@ -728,108 +752,108 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableIntegerCountFilter(t *tes } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "IntFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_ge", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_gt", - "type": map[string]any{ - "name": "Int", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "IntFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_ge", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_gt", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_le", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_lt", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_le", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_lt", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -837,29 +861,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableIntegerCountFilter(t *tes }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersIntegerCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Int!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Int!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -867,6 +889,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersIntegerCountFilter(t *testing.T) name type { name + inputFields { + name + type { + name + } + } } } } @@ -874,108 +902,108 @@ func TestSchemaAggregateInlineArrayCreatesUsersIntegerCountFilter(t *testing.T) } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullIntFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullIntFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_ge", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_gt", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_le", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_lt", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_ge", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_gt", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_le", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_lt", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -983,29 +1011,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersIntegerCountFilter(t *testing.T) }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersNillableFloatCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Float] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Float] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -1013,6 +1039,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableFloatCountFilter(t *testi name type { name + inputFields { + name + type { + name + } + } } } } @@ -1020,108 +1052,108 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableFloatCountFilter(t *testi } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "FloatFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_ge", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_gt", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_le", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_lt", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Float", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "FloatFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_ge", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_gt", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_le", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_lt", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -1129,29 +1161,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableFloatCountFilter(t *testi }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersFloatCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [Float!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [Float!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -1159,6 +1189,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersFloatCountFilter(t *testing.T) { name type { name + inputFields { + name + type { + name + } + } } } } @@ -1166,108 +1202,108 @@ func TestSchemaAggregateInlineArrayCreatesUsersFloatCountFilter(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullFloatFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_ge", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_gt", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_le", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_lt", - "type": map[string]any{ - "name": "Float", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullFloatFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_ge", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_gt", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_le", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_lt", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "Float", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "Float", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -1275,29 +1311,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersFloatCountFilter(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersNillableStringCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [String] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [String] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -1305,6 +1339,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableStringCountFilter(t *test name type { name + inputFields { + name + type { + name + } + } } } } @@ -1312,96 +1352,96 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableStringCountFilter(t *test } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "StringFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "String", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_like", - "type": map[string]any{ - "name": "String", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "StringFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_like", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_nlike", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "String", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_nlike", - "type": map[string]any{ - "name": "String", - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -1409,29 +1449,27 @@ func TestSchemaAggregateInlineArrayCreatesUsersNillableStringCountFilter(t *test }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateInlineArrayCreatesUsersStringCountFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users { - Favourites: [String!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Favourites: [String!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name @@ -1439,6 +1477,12 @@ func TestSchemaAggregateInlineArrayCreatesUsersStringCountFilter(t *testing.T) { name type { name + inputFields { + name + type { + name + } + } } } } @@ -1446,96 +1490,96 @@ func TestSchemaAggregateInlineArrayCreatesUsersStringCountFilter(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "Favourites", - "type": map[string]any{ - "name": "users__Favourites__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "NotNullStringFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_eq", - "type": map[string]any{ - "name": "String", - }, - }, - map[string]any{ - "name": "_in", - "type": map[string]any{ - "name": nil, + "name": "_count", + "args": []any{ + map[string]any{ + "name": "Favourites", + "type": map[string]any{ + "name": "users__Favourites__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "NotNullStringFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_eq", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_in", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_like", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_ne", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_nin", + "type": map[string]any{ + "name": nil, + }, + }, + map[string]any{ + "name": "_nlike", + "type": map[string]any{ + "name": "String", + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + }, + }, }, }, - map[string]any{ - "name": "_like", - "type": map[string]any{ - "name": "String", - }, - }, - map[string]any{ - "name": "_ne", - "type": map[string]any{ - "name": "String", - }, - }, - map[string]any{ - "name": "_nin", - "type": map[string]any{ - "name": nil, - }, - }, - map[string]any{ - "name": "_nlike", - "type": map[string]any{ - "name": "String", - }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "inputFields": nil, }, }, }, }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "inputFields": nil, - }, - }, }, + aggregateGroupArg, + aggregateVersionArg, }, }, - aggregateGroupArg, - aggregateVersionArg, }, }, }, @@ -1543,5 +1587,5 @@ func TestSchemaAggregateInlineArrayCreatesUsersStringCountFilter(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } diff --git a/tests/integration/schema/aggregates/simple_test.go b/tests/integration/schema/aggregates/simple_test.go index bef1dad174..d7ed341a72 100644 --- a/tests/integration/schema/aggregates/simple_test.go +++ b/tests/integration/schema/aggregates/simple_test.go @@ -13,86 +13,90 @@ package aggregates import ( "testing" - testUtils "github.com/sourcenetwork/defradb/tests/integration/schema" + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestSchemaAggregateSimpleCreatesUsersCount(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name + inputFields { + name + type { + name + } + } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, - }, - }, - map[string]any{ - "name": "_version", - "type": map[string]any{ - "name": "users___version__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + map[string]any{ + "name": "_version", + "type": map[string]any{ + "name": "users___version__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, @@ -105,94 +109,98 @@ func TestSchemaAggregateSimpleCreatesUsersCount(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateSimpleCreatesUsersSum(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name - kind - ofType { + inputFields { name + type { + name + kind + ofType { + name + } + } } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_sum", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - "kind": "NON_NULL", - "ofType": map[string]any{ - "name": "usersNumericFieldsArg", + "name": "_sum", + "args": []any{ + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + "kind": "NON_NULL", + "ofType": map[string]any{ + "name": "usersNumericFieldsArg", + }, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - "kind": "INPUT_OBJECT", - "ofType": nil, - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", - "kind": "INPUT_OBJECT", - "ofType": nil, }, }, }, @@ -205,94 +213,98 @@ func TestSchemaAggregateSimpleCreatesUsersSum(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateSimpleCreatesUsersAverage(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - args { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { name - type { + fields { name - inputFields { + args { name type { name - kind - ofType { + inputFields { name + type { + name + kind + ofType { + name + } + } } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": []any{ - map[string]any{ - "name": "_avg", - "args": []any{ + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": []any{ map[string]any{ - "name": "_group", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - "kind": "NON_NULL", - "ofType": map[string]any{ - "name": "usersNumericFieldsArg", + "name": "_avg", + "args": []any{ + map[string]any{ + "name": "_group", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + "kind": "NON_NULL", + "ofType": map[string]any{ + "name": "usersNumericFieldsArg", + }, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - "kind": "INPUT_OBJECT", - "ofType": nil, - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", - "kind": "INPUT_OBJECT", - "ofType": nil, }, }, }, @@ -305,5 +317,5 @@ func TestSchemaAggregateSimpleCreatesUsersAverage(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } diff --git a/tests/integration/schema/aggregates/top_level_test.go b/tests/integration/schema/aggregates/top_level_test.go index 05a9a25625..f6c6f35a3d 100644 --- a/tests/integration/schema/aggregates/top_level_test.go +++ b/tests/integration/schema/aggregates/top_level_test.go @@ -13,67 +13,71 @@ package aggregates import ( "testing" - testUtils "github.com/sourcenetwork/defradb/tests/integration/schema" + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestSchemaAggregateTopLevelCreatesCountGivenSchema(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - queryType { - fields { - name - args { - name - type { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + queryType { + fields { name - inputFields { + args { name type { name + inputFields { + name + type { + name + } + } } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "queryType": map[string]any{ - "fields": []any{ - map[string]any{ - "name": "_count", - "args": []any{ + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "queryType": map[string]any{ + "fields": []any{ map[string]any{ - "name": "users", - "type": map[string]any{ - "name": "users__CountSelector", - "inputFields": []any{ - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", + "name": "_count", + "args": []any{ + map[string]any{ + "name": "users", + "type": map[string]any{ + "name": "users__CountSelector", + "inputFields": []any{ + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + }, + }, }, }, }, @@ -87,33 +91,37 @@ func TestSchemaAggregateTopLevelCreatesCountGivenSchema(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateTopLevelCreatesSumGivenSchema(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - queryType { - fields { - name - args { - name - type { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + queryType { + fields { name - inputFields { + args { name type { name - kind - ofType { + inputFields { name + type { + name + kind + ofType { + name + } + } } } } @@ -121,61 +129,61 @@ func TestSchemaAggregateTopLevelCreatesSumGivenSchema(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "queryType": map[string]any{ - "fields": []any{ - map[string]any{ - "name": "_sum", - "args": []any{ + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "queryType": map[string]any{ + "fields": []any{ map[string]any{ - "name": "users", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - "kind": "NON_NULL", - "ofType": map[string]any{ - "name": "usersNumericFieldsArg", + "name": "_sum", + "args": []any{ + map[string]any{ + "name": "users", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + "kind": "NON_NULL", + "ofType": map[string]any{ + "name": "usersNumericFieldsArg", + }, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - "kind": "INPUT_OBJECT", - "ofType": nil, - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", - "kind": "INPUT_OBJECT", - "ofType": nil, }, }, }, @@ -189,33 +197,37 @@ func TestSchemaAggregateTopLevelCreatesSumGivenSchema(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaAggregateTopLevelCreatesAverageGivenSchema(t *testing.T) { - test := testUtils.RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - queryType { - fields { - name - args { - name - type { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + queryType { + fields { name - inputFields { + args { name type { name - kind - ofType { + inputFields { name + type { + name + kind + ofType { + name + } + } } } } @@ -223,61 +235,61 @@ func TestSchemaAggregateTopLevelCreatesAverageGivenSchema(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "queryType": map[string]any{ - "fields": []any{ - map[string]any{ - "name": "_avg", - "args": []any{ + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "queryType": map[string]any{ + "fields": []any{ map[string]any{ - "name": "users", - "type": map[string]any{ - "name": "users__NumericSelector", - "inputFields": []any{ - map[string]any{ - "name": "field", - "type": map[string]any{ - "name": nil, - "kind": "NON_NULL", - "ofType": map[string]any{ - "name": "usersNumericFieldsArg", + "name": "_avg", + "args": []any{ + map[string]any{ + "name": "users", + "type": map[string]any{ + "name": "users__NumericSelector", + "inputFields": []any{ + map[string]any{ + "name": "field", + "type": map[string]any{ + "name": nil, + "kind": "NON_NULL", + "ofType": map[string]any{ + "name": "usersNumericFieldsArg", + }, + }, + }, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, + }, + map[string]any{ + "name": "limit", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "offset", + "type": map[string]any{ + "name": "Int", + "kind": "SCALAR", + "ofType": nil, + }, + }, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "usersOrderArg", + "kind": "INPUT_OBJECT", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - "kind": "INPUT_OBJECT", - "ofType": nil, - }, - }, - map[string]any{ - "name": "limit", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "offset", - "type": map[string]any{ - "name": "Int", - "kind": "SCALAR", - "ofType": nil, - }, - }, - map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "usersOrderArg", - "kind": "INPUT_OBJECT", - "ofType": nil, }, }, }, @@ -291,5 +303,5 @@ func TestSchemaAggregateTopLevelCreatesAverageGivenSchema(t *testing.T) { }, } - testUtils.ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } diff --git a/tests/integration/schema/client_test.go b/tests/integration/schema/client_test.go index 850234d40c..6a7239db05 100644 --- a/tests/integration/schema/client_test.go +++ b/tests/integration/schema/client_test.go @@ -14,36 +14,40 @@ import ( "testing" schemaTypes "github.com/sourcenetwork/defradb/request/graphql/schema/types" + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) // TestIntrospectionExplainTypeDefined tests that the introspection query returns a schema that // defines the ExplainType enum. func TestIntrospectionExplainTypeDefined(t *testing.T) { - test := RequestTestCase{ - Schema: []string{}, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - types { - kind - name - description + test := testUtils.TestCase{ + Actions: []any{ + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + types { + kind + name + description + } + } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "types": []any{ - map[string]any{ - "description": schemaTypes.ExplainEnum.Description(), - "kind": "ENUM", - "name": "ExplainType", + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "types": []any{ + map[string]any{ + "description": schemaTypes.ExplainEnum.Description(), + "kind": "ENUM", + "name": "ExplainType", + }, + }, }, }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{}, test) } diff --git a/tests/integration/schema/filter_test.go b/tests/integration/schema/filter_test.go index d0f3a6aeeb..3b4a1bd66e 100644 --- a/tests/integration/schema/filter_test.go +++ b/tests/integration/schema/filter_test.go @@ -12,33 +12,39 @@ package schema import ( "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestFilterForSimpleSchema(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users { - name: String - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - queryType { - fields { - name - args { - name - type { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + name: String + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + queryType { + fields { name - inputFields { + args { name type { name - ofType { + inputFields { name + type { + name + ofType { + name + } + } } } } @@ -46,65 +52,65 @@ func TestFilterForSimpleSchema(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "queryType": map[string]any{ - "fields": []any{ - map[string]any{ - "name": "users", - "args": append( - defaultUserArgsWithoutFilter, + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "queryType": map[string]any{ + "fields": []any{ map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "usersFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - "ofType": map[string]any{ - "name": "usersFilterArg", + "name": "users", + "args": append( + defaultUserArgsWithoutFilter, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "usersFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + "ofType": map[string]any{ + "name": "usersFilterArg", + }, + }, }, - }, - }, - map[string]any{ - "name": "_key", - "type": map[string]any{ - "name": "IDOperatorBlock", - "ofType": nil, - }, - }, - map[string]any{ - "name": "_not", - "type": map[string]any{ - "name": "usersFilterArg", - "ofType": nil, - }, - }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - "ofType": map[string]any{ - "name": "usersFilterArg", + map[string]any{ + "name": "_key", + "type": map[string]any{ + "name": "IDOperatorBlock", + "ofType": nil, + }, + }, + map[string]any{ + "name": "_not", + "type": map[string]any{ + "name": "usersFilterArg", + "ofType": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + "ofType": map[string]any{ + "name": "usersFilterArg", + }, + }, + }, + map[string]any{ + "name": "name", + "type": map[string]any{ + "name": "StringOperatorBlock", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "name", - "type": map[string]any{ - "name": "StringOperatorBlock", - "ofType": nil, }, }, }, - }, + ).tidy(), }, - ).tidy(), + }, }, }, }, @@ -112,7 +118,7 @@ func TestFilterForSimpleSchema(t *testing.T) { }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } var testFilterForSimpleSchemaArgProps = map[string]any{ @@ -142,36 +148,40 @@ var defaultUserArgsWithoutFilter = trimFields( ) func TestFilterForOneToOneSchema(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type book { - name: String - author: author - } + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type book { + name: String + author: author + } - type author { - age: Int - wrote: book @primary - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __schema { - queryType { - fields { - name - args { - name - type { + type author { + age: Int + wrote: book @primary + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __schema { + queryType { + fields { name - inputFields { + args { name type { name - ofType { + inputFields { name + type { + name + ofType { + name + } + } } } } @@ -179,79 +189,79 @@ func TestFilterForOneToOneSchema(t *testing.T) { } } } - } - } - `, - ContainsData: map[string]any{ - "__schema": map[string]any{ - "queryType": map[string]any{ - "fields": []any{ - map[string]any{ - "name": "book", - "args": append( - defaultBookArgsWithoutFilter, + `, + ContainsData: map[string]any{ + "__schema": map[string]any{ + "queryType": map[string]any{ + "fields": []any{ map[string]any{ - "name": "filter", - "type": map[string]any{ - "name": "bookFilterArg", - "inputFields": []any{ - map[string]any{ - "name": "_and", - "type": map[string]any{ - "name": nil, - "ofType": map[string]any{ - "name": "bookFilterArg", + "name": "book", + "args": append( + defaultBookArgsWithoutFilter, + map[string]any{ + "name": "filter", + "type": map[string]any{ + "name": "bookFilterArg", + "inputFields": []any{ + map[string]any{ + "name": "_and", + "type": map[string]any{ + "name": nil, + "ofType": map[string]any{ + "name": "bookFilterArg", + }, + }, }, - }, - }, - map[string]any{ - "name": "_key", - "type": map[string]any{ - "name": "IDOperatorBlock", - "ofType": nil, - }, - }, - map[string]any{ - "name": "_not", - "type": map[string]any{ - "name": "bookFilterArg", - "ofType": nil, - }, - }, - map[string]any{ - "name": "_or", - "type": map[string]any{ - "name": nil, - "ofType": map[string]any{ - "name": "bookFilterArg", + map[string]any{ + "name": "_key", + "type": map[string]any{ + "name": "IDOperatorBlock", + "ofType": nil, + }, + }, + map[string]any{ + "name": "_not", + "type": map[string]any{ + "name": "bookFilterArg", + "ofType": nil, + }, + }, + map[string]any{ + "name": "_or", + "type": map[string]any{ + "name": nil, + "ofType": map[string]any{ + "name": "bookFilterArg", + }, + }, + }, + map[string]any{ + "name": "author", + "type": map[string]any{ + "name": "authorFilterArg", + "ofType": nil, + }, + }, + map[string]any{ + "name": "author_id", + "type": map[string]any{ + "name": "IDOperatorBlock", + "ofType": nil, + }, + }, + map[string]any{ + "name": "name", + "type": map[string]any{ + "name": "StringOperatorBlock", + "ofType": nil, + }, }, - }, - }, - map[string]any{ - "name": "author", - "type": map[string]any{ - "name": "authorFilterArg", - "ofType": nil, - }, - }, - map[string]any{ - "name": "author_id", - "type": map[string]any{ - "name": "IDOperatorBlock", - "ofType": nil, - }, - }, - map[string]any{ - "name": "name", - "type": map[string]any{ - "name": "StringOperatorBlock", - "ofType": nil, }, }, }, - }, + ).tidy(), }, - ).tidy(), + }, }, }, }, @@ -259,7 +269,7 @@ func TestFilterForOneToOneSchema(t *testing.T) { }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"book", "author"}, test) } var testFilterForOneToOneSchemaArgProps = map[string]any{ diff --git a/tests/integration/schema/input_type_test.go b/tests/integration/schema/input_type_test.go index e1f67de733..efc83b9b7e 100644 --- a/tests/integration/schema/input_type_test.go +++ b/tests/integration/schema/input_type_test.go @@ -12,41 +12,37 @@ package schema import ( "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestInputTypeOfOrderFieldWhereSchemaHasRelationType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type book { - name: String - rating: Float - author: author - } + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type book { + name: String + rating: Float + author: author + } - type author { - name: String - age: Int - verified: Boolean - wrote: book @primary - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "author") { - name - fields { - name - args { + type author { + name: String + age: Int + verified: Boolean + wrote: book @primary + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "author") { name - type { + fields { name - ofType { - name - kind - } - inputFields { + args { name type { name @@ -54,85 +50,95 @@ func TestInputTypeOfOrderFieldWhereSchemaHasRelationType(t *testing.T) { name kind } + inputFields { + name + type { + name + ofType { + name + kind + } + } + } } } } } } - } - } - `, - ContainsData: map[string]any{ - "__type": map[string]any{ - "name": "author", - "fields": []any{ - map[string]any{ - // Asserting only on group, because it is the field that contains `order` info we are - // looking for, additionally wanted to reduce the noise of other elements that were getting - // dumped out which made the entire output horrible. - "name": "_group", - "args": append( - defaultGroupArgsWithoutOrder, + `, + ContainsData: map[string]any{ + "__type": map[string]any{ + "name": "author", + "fields": []any{ map[string]any{ - "name": "order", - "type": map[string]any{ - "name": "authorOrderArg", - "ofType": nil, - "inputFields": []any{ - map[string]any{ - "name": "_key", - "type": map[string]any{ - "name": "Ordering", - "ofType": nil, - }, - }, - map[string]any{ - "name": "age", - "type": map[string]any{ - "name": "Ordering", - "ofType": nil, - }, - }, - map[string]any{ - "name": "name", - "type": map[string]any{ - "name": "Ordering", - "ofType": nil, - }, - }, - map[string]any{ - "name": "verified", - "type": map[string]any{ - "name": "Ordering", - "ofType": nil, - }, - }, - // Without the relation type we won't have the following ordering type(s). - map[string]any{ - "name": "wrote", - "type": map[string]any{ - "name": "bookOrderArg", - "ofType": nil, - }, - }, - map[string]any{ - "name": "wrote_id", - "type": map[string]any{ - "name": "Ordering", - "ofType": nil, + // Asserting only on group, because it is the field that contains `order` info we are + // looking for, additionally wanted to reduce the noise of other elements that were getting + // dumped out which made the entire output horrible. + "name": "_group", + "args": append( + defaultGroupArgsWithoutOrder, + map[string]any{ + "name": "order", + "type": map[string]any{ + "name": "authorOrderArg", + "ofType": nil, + "inputFields": []any{ + map[string]any{ + "name": "_key", + "type": map[string]any{ + "name": "Ordering", + "ofType": nil, + }, + }, + map[string]any{ + "name": "age", + "type": map[string]any{ + "name": "Ordering", + "ofType": nil, + }, + }, + map[string]any{ + "name": "name", + "type": map[string]any{ + "name": "Ordering", + "ofType": nil, + }, + }, + map[string]any{ + "name": "verified", + "type": map[string]any{ + "name": "Ordering", + "ofType": nil, + }, + }, + // Without the relation type we won't have the following ordering type(s). + map[string]any{ + "name": "wrote", + "type": map[string]any{ + "name": "bookOrderArg", + "ofType": nil, + }, + }, + map[string]any{ + "name": "wrote_id", + "type": map[string]any{ + "name": "Ordering", + "ofType": nil, + }, + }, }, }, }, - }, + ).tidy(), }, - ).tidy(), + }, }, }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"book", "author"}, test) } var testInputTypeOfOrderFieldWhereSchemaHasRelationTypeArgProps = map[string]any{ diff --git a/tests/integration/schema/simple_test.go b/tests/integration/schema/simple_test.go index e67cfd5719..a451eb5e3f 100644 --- a/tests/integration/schema/simple_test.go +++ b/tests/integration/schema/simple_test.go @@ -12,188 +12,202 @@ package schema import ( "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestSchemaSimpleCreatesSchemaGivenEmptyType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "users", + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { + name + } + } + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "users", + }, + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaSimpleErrorsGivenDuplicateSchema(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - ` - type users {} - `, + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + ExpectedError: "schema type already exists", + }, }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - } - } - `, - ExpectedError: "schema type already exists", } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaSimpleErrorsGivenDuplicateSchemaInSameSDL(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users {} - type users {} - `, + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + type users {} + `, + ExpectedError: "schema type already exists", + }, }, - ExpectedError: "schema type already exists", } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaSimpleCreatesSchemaGivenNewTypes(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - ` - type books {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "books") { - name - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "books", + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.SchemaUpdate{ + Schema: ` + type books {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "books") { + name + } + } + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "books", + }, + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users", "books"}, test) } func TestSchemaSimpleCreatesSchemaWithDefaultFieldsGivenEmptyType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users {} - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - type { - name - kind + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users {} + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { + name + fields { + name + type { + name + kind + } + } } } - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": defaultFields.tidy(), + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": defaultFields.tidy(), + }, + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaSimpleErrorsGivenTypeWithInvalidFieldType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users { - Name: NotAType - } - `, + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Name: NotAType + } + `, + ExpectedError: "no type found for given name", + }, }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - } - } - `, - ExpectedError: "no type found for given name", } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaSimpleCreatesSchemaGivenTypeWithStringField(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users { - Name: String - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - fields { - name - type { - name - kind + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + Name: String + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { + name + fields { + name + type { + name + kind + } + } } } - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "users", - "fields": defaultFields.append( - field{ - "name": "Name", - "type": map[string]any{ - "kind": "SCALAR", - "name": "String", - }, + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "users", + "fields": defaultFields.append( + field{ + "name": "Name", + "type": map[string]any{ + "kind": "SCALAR", + "name": "String", + }, + }, + ).tidy(), }, - ).tidy(), + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } diff --git a/tests/integration/schema/utils.go b/tests/integration/schema/utils.go deleted file mode 100644 index 5a3a48c269..0000000000 --- a/tests/integration/schema/utils.go +++ /dev/null @@ -1,181 +0,0 @@ -// 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 schema - -import ( - "context" - "strings" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/sourcenetwork/defradb/client" - "github.com/sourcenetwork/defradb/errors" - testutils "github.com/sourcenetwork/defradb/tests/integration" -) - -type RequestTestCase struct { - // The set of schema to add to the database. - // - // Each string may contain multiple schema - one string = one db.AddSchema call. - Schema []string - - // The introspection request to use when fetching schema state. - // - // Available properties can be found in the GQL spec: - // https://spec.graphql.org/October2021/#sec-Introspection - IntrospectionRequest string - - // The data expected to be returned from the introspection request. - ExpectedData map[string]any - - // If [ExpectedData] is nil and this is populated, the test framework will assert - // that the value given exists in the actual results. - // - // If this contains nested maps it only requires the last (i.e. non-map) value to - // be present along the given path. If an array/slice is present in this chain, - // it will assert that the items in the expected-array have exact matches in the - // corresponding result-array (inner maps are not traversed beyond the array, - // the full array-item must match exactly). - ContainsData map[string]any - - // Any error expected to be returned by database calls. - // - // This includes AddSchema and Introspection calls. - ExpectedError string -} - -func ExecuteRequestTestCase( - t *testing.T, - testCase RequestTestCase, -) { - ctx := context.Background() - - db, err := testutils.NewBadgerMemoryDB(ctx) - if err != nil { - t.Fatal(err) - } - - for _, schema := range testCase.Schema { - err = db.AddSchema(ctx, schema) - if assertError(t, err, testCase.ExpectedError) { - return - } - } - - result := db.ExecRequest(ctx, testCase.IntrospectionRequest) - - assertSchemaResults(ctx, t, result, testCase) - - if testCase.ExpectedError != "" { - assert.Fail(t, "Expected an error however none was raised.") - } -} - -func assertSchemaResults( - ctx context.Context, - t *testing.T, - result *client.RequestResult, - testCase RequestTestCase, -) bool { - if assertErrors(t, result.GQL.Errors, testCase.ExpectedError) { - return true - } - resultantData := result.GQL.Data.(map[string]any) - - if len(testCase.ExpectedData) == 0 && len(testCase.ContainsData) == 0 { - assert.Equal(t, testCase.ExpectedData, resultantData) - } - - if len(testCase.ExpectedData) == 0 && len(testCase.ContainsData) > 0 { - assertContains(t, testCase.ContainsData, resultantData) - } else { - assert.Equal(t, len(testCase.ExpectedData), len(resultantData)) - - for k, result := range resultantData { - assert.Equal(t, testCase.ExpectedData[k], result) - } - } - - return false -} - -// Asserts that the `actual` contains the given `contains` value according to the logic -// described on the [RequestTestCase.ContainsData] property. -func assertContains(t *testing.T, contains map[string]any, actual map[string]any) { - for k, expected := range contains { - innerActual := actual[k] - if innerExpected, innerIsMap := expected.(map[string]any); innerIsMap { - if innerActual == nil { - assert.Equal(t, innerExpected, innerActual) - } else if innerActualMap, isMap := innerActual.(map[string]any); isMap { - // If the inner is another map then we continue down the chain - assertContains(t, innerExpected, innerActualMap) - } else { - // If the types don't match then we use assert.Equal for a clean failure message - assert.Equal(t, innerExpected, innerActual) - } - } else if innerExpected, innerIsArray := expected.([]any); innerIsArray { - if actualArray, isActualArray := innerActual.([]any); isActualArray { - // If the inner is an array/slice, then assert that each expected item is present - // in the actual. Note how the actual may contain additional items - this should - // not result in a test failure. - for _, innerExpectedItem := range innerExpected { - assert.Contains(t, actualArray, innerExpectedItem) - } - } else { - // If the types don't match then we use assert.Equal for a clean failure message - assert.Equal(t, expected, innerActual) - } - } else { - assert.Equal(t, expected, innerActual) - } - } -} - -func assertError(t *testing.T, err error, expectedError string) bool { - if err == nil { - return false - } - - if expectedError == "" { - assert.NoError(t, err) - return false - } else { - if !strings.Contains(err.Error(), expectedError) { - assert.ErrorIs(t, err, errors.New(expectedError)) - return false - } - return true - } -} - -func assertErrors( - t *testing.T, - errs []any, - expectedError string, -) bool { - if expectedError == "" { - assert.Empty(t, errs) - } else { - for _, e := range errs { - // This is always a string at the moment, add support for other types as and when needed - errorString := e.(string) - if !strings.Contains(errorString, expectedError) { - // We use ErrorIs for clearer failures (is a error comparision even if it is just a string) - assert.ErrorIs(t, errors.New(errorString), errors.New(expectedError)) - continue - } - return true - } - } - return false -} diff --git a/tests/integration/schema/with_inline_array_test.go b/tests/integration/schema/with_inline_array_test.go index e51b659609..6eb7588bc1 100644 --- a/tests/integration/schema/with_inline_array_test.go +++ b/tests/integration/schema/with_inline_array_test.go @@ -12,61 +12,73 @@ package schema import ( "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) func TestSchemaInlineArrayCreatesSchemaGivenSingleType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users { - FavouriteIntegers: [Int!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "users") { - name - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "users", + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + FavouriteIntegers: [Int!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "users") { + name + } + } + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "users", + }, + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users"}, test) } func TestSchemaInlineArrayCreatesSchemaGivenSecondType(t *testing.T) { - test := RequestTestCase{ - Schema: []string{ - ` - type users { - FavouriteIntegers: [Int!] - } - `, - ` - type books { - PageNumbers: [Int!] - } - `, - }, - IntrospectionRequest: ` - query IntrospectionQuery { - __type (name: "books") { - name - } - } - `, - ExpectedData: map[string]any{ - "__type": map[string]any{ - "name": "books", + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type users { + FavouriteIntegers: [Int!] + } + `, + }, + testUtils.SchemaUpdate{ + Schema: ` + type books { + PageNumbers: [Int!] + } + `, + }, + testUtils.IntrospectionRequest{ + Request: ` + query IntrospectionQuery { + __type (name: "books") { + name + } + } + `, + ExpectedData: map[string]any{ + "__type": map[string]any{ + "name": "books", + }, + }, }, }, } - ExecuteRequestTestCase(t, test) + testUtils.ExecuteTestCase(t, []string{"users", "books"}, test) } diff --git a/tests/integration/test_case.go b/tests/integration/test_case.go index 36fa3a0f1c..f019a06141 100644 --- a/tests/integration/test_case.go +++ b/tests/integration/test_case.go @@ -195,3 +195,30 @@ type SubscriptionRequest struct { // contains this string. ExpectedError string } + +type IntrospectionRequest struct { + // The introspection request to use when fetching schema state. + // + // Available properties can be found in the GQL spec: + // https://spec.graphql.org/October2021/#sec-Introspection + Request string + + // The full data expected to be returned from the introspection request. + ExpectedData map[string]any + + // If [ExpectedData] is nil and this is populated, the test framework will assert + // that the value given exists in the actual results. + // + // If this contains nested maps it only requires the last (i.e. non-map) value to + // be present along the given path. If an array/slice is present in this chain, + // it will assert that the items in the expected-array have exact matches in the + // corresponding result-array (inner maps are not traversed beyond the array, + // the full array-item must match exactly). + ContainsData map[string]any + + // Any error expected from the action. Optional. + // + // String can be a partial, and the test will pass if an error is returned that + // contains this string. + ExpectedError string +} diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index 256bb0451a..bf54d0be42 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -14,6 +14,7 @@ import ( "context" "fmt" "os" + "reflect" "strings" "syscall" "testing" @@ -379,6 +380,9 @@ func executeTestCase( case Request: executeRequest(ctx, t, nodes, testCase, action) + case IntrospectionRequest: + assertIntrospectionResults(ctx, t, testCase.Description, db, action) + case WaitForSync: waitForSync(t, testCase, action, syncChans) @@ -446,24 +450,11 @@ func getNodeCollections(nodeID immutable.Option[int], collections [][]client.Col func calculateLenForFlattenedActions(testCase *TestCase) int { newLen := 0 - for i := range testCase.Actions { - switch action := testCase.Actions[i].(type) { - case []SchemaUpdate: - newLen += len(action) - case []SchemaPatch: - newLen += len(action) - case []CreateDoc: - newLen += len(action) - case []UpdateDoc: - newLen += len(action) - case []Request: - newLen += len(action) - case []TransactionRequest: - newLen += len(action) - case []TransactionRequest2: - newLen += len(action) - case []TransactionCommit: - newLen += len(action) + for _, a := range testCase.Actions { + actionGroup := reflect.ValueOf(a) + switch actionGroup.Kind() { + case reflect.Array, reflect.Slice: + newLen += actionGroup.Len() default: newLen++ } @@ -477,42 +468,19 @@ func flattenActions(testCase *TestCase) { return } newActions := make([]any, 0, newLen) - for i := range testCase.Actions { - switch action := testCase.Actions[i].(type) { - case []SchemaUpdate: - for j := range action { - newActions = append(newActions, action[j]) - } - case []SchemaPatch: - for j := range action { - newActions = append(newActions, action[j]) - } - case []CreateDoc: - for j := range action { - newActions = append(newActions, action[j]) - } - case []UpdateDoc: - for j := range action { - newActions = append(newActions, action[j]) - } - case []Request: - for j := range action { - newActions = append(newActions, action[j]) - } - case []TransactionRequest: - for j := range action { - newActions = append(newActions, action[j]) - } - case []TransactionRequest2: - for j := range action { - newActions = append(newActions, action[j]) - } - case []TransactionCommit: - for j := range action { - newActions = append(newActions, action[j]) + + for _, a := range testCase.Actions { + actionGroup := reflect.ValueOf(a) + switch actionGroup.Kind() { + case reflect.Array, reflect.Slice: + for i := 0; i < actionGroup.Len(); i++ { + newActions = append( + newActions, + actionGroup.Index(i).Interface(), + ) } default: - newActions = append(newActions, action) + newActions = append(newActions, a) } } testCase.Actions = newActions @@ -1131,3 +1099,67 @@ func assertExpectedErrorRaised(t *testing.T, description string, expectedError s assert.Fail(t, "Expected an error however none was raised.", description) } } + +func assertIntrospectionResults( + ctx context.Context, + t *testing.T, + description string, + db client.DB, + action IntrospectionRequest, +) bool { + result := db.ExecRequest(ctx, action.Request) + + if AssertErrors(t, description, result.GQL.Errors, action.ExpectedError) { + return true + } + resultantData := result.GQL.Data.(map[string]any) + + if len(action.ExpectedData) == 0 && len(action.ContainsData) == 0 { + require.Equal(t, action.ExpectedData, resultantData) + } + + if len(action.ExpectedData) == 0 && len(action.ContainsData) > 0 { + assertContains(t, action.ContainsData, resultantData) + } else { + require.Equal(t, len(action.ExpectedData), len(resultantData)) + + for k, result := range resultantData { + assert.Equal(t, action.ExpectedData[k], result) + } + } + + return false +} + +// Asserts that the `actual` contains the given `contains` value according to the logic +// described on the [RequestTestCase.ContainsData] property. +func assertContains(t *testing.T, contains map[string]any, actual map[string]any) { + for k, expected := range contains { + innerActual := actual[k] + if innerExpected, innerIsMap := expected.(map[string]any); innerIsMap { + if innerActual == nil { + assert.Equal(t, innerExpected, innerActual) + } else if innerActualMap, isMap := innerActual.(map[string]any); isMap { + // If the inner is another map then we continue down the chain + assertContains(t, innerExpected, innerActualMap) + } else { + // If the types don't match then we use assert.Equal for a clean failure message + assert.Equal(t, innerExpected, innerActual) + } + } else if innerExpected, innerIsArray := expected.([]any); innerIsArray { + if actualArray, isActualArray := innerActual.([]any); isActualArray { + // If the inner is an array/slice, then assert that each expected item is present + // in the actual. Note how the actual may contain additional items - this should + // not result in a test failure. + for _, innerExpectedItem := range innerExpected { + assert.Contains(t, actualArray, innerExpectedItem) + } + } else { + // If the types don't match then we use assert.Equal for a clean failure message + assert.Equal(t, expected, innerActual) + } + } else { + assert.Equal(t, expected, innerActual) + } + } +}