diff --git a/tests/integration/mutation/one_to_many/utils.go b/tests/integration/mutation/create/field_kinds/one_to_many/utils.go similarity index 93% rename from tests/integration/mutation/one_to_many/utils.go rename to tests/integration/mutation/create/field_kinds/one_to_many/utils.go index 2b81a7321e..21b9524567 100644 --- a/tests/integration/mutation/one_to_many/utils.go +++ b/tests/integration/mutation/create/field_kinds/one_to_many/utils.go @@ -16,7 +16,7 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func ExecuteTestCase(t *testing.T, test testUtils.TestCase) { +func executeTestCase(t *testing.T, test testUtils.TestCase) { testUtils.ExecuteTestCase( t, testUtils.TestCase{ diff --git a/tests/integration/mutation/one_to_many/create/with_alias_test.go b/tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go similarity index 94% rename from tests/integration/mutation/one_to_many/create/with_alias_test.go rename to tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go index 990ae8f653..6949dfe88c 100644 --- a/tests/integration/mutation/one_to_many/create/with_alias_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package create +package one_to_many import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many" ) func TestMutationCreateOneToMany_AliasedRelationNameWithInvalidField_Error(t *testing.T) { @@ -32,7 +31,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameWithInvalidField_Error(t *te }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationSingleSide_NoIDFieldError(t *testing.T) { @@ -49,7 +48,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationSingleSid }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -72,7 +71,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationManySide_ }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_AliasedRelationNamToLinkFromSingleSide_NoIDFieldError(t *testing.T) { @@ -107,7 +106,7 @@ func TestMutationCreateOneToMany_AliasedRelationNamToLinkFromSingleSide_NoIDFiel }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testing.T) { @@ -184,7 +183,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testin }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDocID(t *testing.T) { @@ -226,7 +225,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDo }, }, } - fixture.ExecuteTestCase(t, nonAliasedTest) + executeTestCase(t, nonAliasedTest) // Check that `bookKey` is same in both above and the alised version below. // Note: Everything should be same, only diff should be the use of alias. @@ -265,5 +264,5 @@ func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDo }, }, } - fixture.ExecuteTestCase(t, aliasedTest) + executeTestCase(t, aliasedTest) } diff --git a/tests/integration/mutation/one_to_many/create/with_simple_test.go b/tests/integration/mutation/create/field_kinds/one_to_many/with_simple_test.go similarity index 94% rename from tests/integration/mutation/one_to_many/create/with_simple_test.go rename to tests/integration/mutation/create/field_kinds/one_to_many/with_simple_test.go index a2c3ad3545..34f22dd9b7 100644 --- a/tests/integration/mutation/one_to_many/create/with_simple_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_many/with_simple_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package create +package one_to_many import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many" ) func TestMutationCreateOneToMany_WithInvalidField_Error(t *testing.T) { @@ -32,7 +31,7 @@ func TestMutationCreateOneToMany_WithInvalidField_Error(t *testing.T) { }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_NonExistingRelationSingleSide_NoIDFieldError(t *testing.T) { @@ -49,7 +48,7 @@ func TestMutationCreateOneToMany_NonExistingRelationSingleSide_NoIDFieldError(t }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -72,7 +71,7 @@ func TestMutationCreateOneToMany_NonExistingRelationManySide_CreatedDoc(t *testi }, }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_RelationIDToLinkFromSingleSide_NoIDFieldError(t *testing.T) { @@ -107,7 +106,7 @@ func TestMutationCreateOneToMany_RelationIDToLinkFromSingleSide_NoIDFieldError(t }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToMany_RelationIDToLinkFromManySide(t *testing.T) { @@ -184,5 +183,5 @@ func TestMutationCreateOneToMany_RelationIDToLinkFromManySide(t *testing.T) { }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/one_to_one/utils.go b/tests/integration/mutation/create/field_kinds/one_to_one/utils.go similarity index 93% rename from tests/integration/mutation/one_to_one/utils.go rename to tests/integration/mutation/create/field_kinds/one_to_one/utils.go index f960b3ba2c..4b5d33f618 100644 --- a/tests/integration/mutation/one_to_one/utils.go +++ b/tests/integration/mutation/create/field_kinds/one_to_one/utils.go @@ -16,7 +16,7 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func ExecuteTestCase(t *testing.T, test testUtils.TestCase) { +func executeTestCase(t *testing.T, test testUtils.TestCase) { testUtils.ExecuteTestCase( t, testUtils.TestCase{ diff --git a/tests/integration/mutation/one_to_one/create/with_alias_test.go b/tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go similarity index 94% rename from tests/integration/mutation/one_to_one/create/with_alias_test.go rename to tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go index 9543795ead..9df8e98ccd 100644 --- a/tests/integration/mutation/one_to_one/create/with_alias_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package create +package one_to_one import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one" ) func TestMutationCreateOneToOne_UseAliasWithInvalidField_Error(t *testing.T) { @@ -32,7 +31,7 @@ func TestMutationCreateOneToOne_UseAliasWithInvalidField_Error(t *testing.T) { }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -55,7 +54,7 @@ func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationPrimarySide_Creat }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Error(t *testing.T) { @@ -72,7 +71,7 @@ func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Err }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySide(t *testing.T) { @@ -147,7 +146,7 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySid }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondarySide(t *testing.T) { @@ -222,5 +221,5 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondaryS }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/one_to_one/create/with_simple_test.go b/tests/integration/mutation/create/field_kinds/one_to_one/with_simple_test.go similarity index 94% rename from tests/integration/mutation/one_to_one/create/with_simple_test.go rename to tests/integration/mutation/create/field_kinds/one_to_one/with_simple_test.go index 39967ce496..a1154761ef 100644 --- a/tests/integration/mutation/one_to_one/create/with_simple_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_one/with_simple_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package create +package one_to_one import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one" ) func TestMutationCreateOneToOne_WithInvalidField_Error(t *testing.T) { @@ -32,7 +31,7 @@ func TestMutationCreateOneToOne_WithInvalidField_Error(t *testing.T) { }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -55,7 +54,7 @@ func TestMutationCreateOneToOneNoChild(t *testing.T) { }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_NonExistingRelationSecondarySide_Error(t *testing.T) { @@ -72,7 +71,7 @@ func TestMutationCreateOneToOne_NonExistingRelationSecondarySide_Error(t *testin }, }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne(t *testing.T) { @@ -149,7 +148,7 @@ func TestMutationCreateOneToOne(t *testing.T) { }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOneSecondarySide(t *testing.T) { @@ -226,7 +225,7 @@ func TestMutationCreateOneToOneSecondarySide(t *testing.T) { }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaPrimary(t *testing.T) { @@ -264,7 +263,7 @@ func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaPrimary( }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaSecondary(t *testing.T) { @@ -302,5 +301,5 @@ func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaSecondar }, } - simpleTests.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/create/field_kinds/one_to_one_to_one/utils.go b/tests/integration/mutation/create/field_kinds/one_to_one_to_one/utils.go new file mode 100644 index 0000000000..9fce31fdb2 --- /dev/null +++ b/tests/integration/mutation/create/field_kinds/one_to_one_to_one/utils.go @@ -0,0 +1,54 @@ +// Copyright 2023 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 one_to_one_to_one + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func execute(t *testing.T, test testUtils.TestCase) { + testUtils.ExecuteTestCase( + t, + testUtils.TestCase{ + Description: test.Description, + Actions: append( + []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author + publisher: Publisher + } + + type Author { + name: String + age: Int + verified: Boolean + wrote: Book @primary + } + + type Publisher { + name: String + address: String + published: Book + } + `, + }, + }, + test.Actions..., + ), + }, + ) +} diff --git a/tests/integration/mutation/relation/create/with_txn_test.go b/tests/integration/mutation/create/field_kinds/one_to_one_to_one/with_txn_test.go similarity index 97% rename from tests/integration/mutation/relation/create/with_txn_test.go rename to tests/integration/mutation/create/field_kinds/one_to_one_to_one/with_txn_test.go index d48df2dfd4..0cc3807ddc 100644 --- a/tests/integration/mutation/relation/create/with_txn_test.go +++ b/tests/integration/mutation/create/field_kinds/one_to_one_to_one/with_txn_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 Democratized Data Foundation +// Copyright 2023 Democratized Data Foundation // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package relation_create +package one_to_one_to_one import ( "testing" @@ -16,7 +16,6 @@ import ( "github.com/sourcenetwork/immutable" testUtils "github.com/sourcenetwork/defradb/tests/integration" - relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation" ) func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.T) { @@ -168,7 +167,7 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing. }, } - relationTests.Execute(t, test) + execute(t, test) } func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing.T) { @@ -308,5 +307,5 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing }, } - relationTests.Execute(t, test) + execute(t, test) } diff --git a/tests/integration/mutation/create/simple_test.go b/tests/integration/mutation/create/simple_test.go new file mode 100644 index 0000000000..dd2f9d509e --- /dev/null +++ b/tests/integration/mutation/create/simple_test.go @@ -0,0 +1,150 @@ +// Copyright 2023 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 create + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationCreate_GivenNonExistantField_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple create mutation with non existant field", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "fieldDoesNotExist": 27 + }`, + ExpectedError: "The given field does not exist. Name: fieldDoesNotExist", + }, + testUtils.Request{ + // Ensure that no documents have been written. + Request: ` + query { + Users { + name + } + } + `, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationCreate(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple create mutation", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + age: Int + } + `, + }, + testUtils.Request{ + Request: `mutation { + create_Users(data: "{\"name\": \"John\",\"age\": 27}") { + _key + name + age + } + }`, + Results: []map[string]any{ + { + "_key": "bae-88b63198-7d38-5714-a9ff-21ba46374fd1", + "name": "John", + "age": uint64(27), + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationCreate_GivenDuplicate_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple create mutation where document already exists.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + age: Int + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "age": 27 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "age": 27 + }`, + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + // Collection.Save would treat the second create as an update, and so + // is excluded from this test. + testUtils.CollectionNamedMutationType, + testUtils.GQLRequestMutationType, + }), + ExpectedError: "a document with the given dockey already exists.", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationCreate_GivenEmptyData_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple create mutation with empty data param.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + create_Users(data: "") { + _key + } + }`, + ExpectedError: "given data payload is empty", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/create/with_version_test.go b/tests/integration/mutation/create/with_version_test.go new file mode 100644 index 0000000000..6c28e898f7 --- /dev/null +++ b/tests/integration/mutation/create/with_version_test.go @@ -0,0 +1,52 @@ +// 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 create + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationCreate_ReturnsVersionCID(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple create mutation, with version cid", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + create_Users(data: "{\"name\": \"John\"}") { + _version { + cid + } + } + }`, + Results: []map[string]any{ + { + "_version": []map[string]any{ + { + "cid": "bafybeifugdzbm7y3eihxe7wbldyesxeh6s6m62ghvwipphtld547rfi4cu", + }, + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/one_to_many/delete/with_show_deleted_test.go b/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go similarity index 89% rename from tests/integration/mutation/one_to_many/delete/with_show_deleted_test.go rename to tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go index 9b97fb3a0f..6969ea3c6f 100644 --- a/tests/integration/mutation/one_to_many/delete/with_show_deleted_test.go +++ b/tests/integration/mutation/delete/field_kinds/one_to_many/with_show_deleted_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package delete +package one_to_many import ( "fmt" @@ -18,7 +18,6 @@ import ( "github.com/sourcenetwork/defradb/client" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many" ) func TestDeletionOfADocumentUsingSingleKeyWithShowDeletedDocumentQuery(t *testing.T) { @@ -48,6 +47,20 @@ func TestDeletionOfADocumentUsingSingleKeyWithShowDeletedDocumentQuery(t *testin test := testUtils.TestCase{ Description: "One to many delete document using single key show deleted.", Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author + } + type Author { + name: String + age: Int + published: [Book] + } + `, + }, testUtils.CreateDoc{ CollectionID: 1, Doc: jsonString1, @@ -108,5 +121,5 @@ func TestDeletionOfADocumentUsingSingleKeyWithShowDeletedDocumentQuery(t *testin }, } - fixture.ExecuteTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } diff --git a/tests/integration/mutation/relation/utils.go b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/utils.go similarity index 92% rename from tests/integration/mutation/relation/utils.go rename to tests/integration/mutation/delete/field_kinds/one_to_one_to_one/utils.go index 610124122c..89f0e497f4 100644 --- a/tests/integration/mutation/relation/utils.go +++ b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/utils.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package relation +package one_to_one_to_one import ( "testing" @@ -16,7 +16,7 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func Execute(t *testing.T, test testUtils.TestCase) { +func execute(t *testing.T, test testUtils.TestCase) { testUtils.ExecuteTestCase( t, testUtils.TestCase{ diff --git a/tests/integration/mutation/relation/delete/single_id_test.go b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_id_test.go similarity index 95% rename from tests/integration/mutation/relation/delete/single_id_test.go rename to tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_id_test.go index da33ca5a6e..851ec73da0 100644 --- a/tests/integration/mutation/relation/delete/single_id_test.go +++ b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_id_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 Democratized Data Foundation +// Copyright 2023 Democratized Data Foundation // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. @@ -8,13 +8,12 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package relation_delete +package one_to_one_to_one import ( "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation" ) func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) { @@ -182,6 +181,6 @@ func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) { } for _, test := range tests { - relationTests.Execute(t, test) + execute(t, test) } } diff --git a/tests/integration/mutation/relation/delete/with_txn_test.go b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_txn_test.go similarity index 96% rename from tests/integration/mutation/relation/delete/with_txn_test.go rename to tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_txn_test.go index aa5491417f..166642ae13 100644 --- a/tests/integration/mutation/relation/delete/with_txn_test.go +++ b/tests/integration/mutation/delete/field_kinds/one_to_one_to_one/with_txn_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 Democratized Data Foundation +// Copyright 2023 Democratized Data Foundation // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package relation_delete +package one_to_one_to_one import ( "testing" @@ -16,7 +16,6 @@ import ( "github.com/sourcenetwork/immutable" testUtils "github.com/sourcenetwork/defradb/tests/integration" - relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation" ) func TestTxnDeletionOfRelatedDocFromPrimarySideForwardDirection(t *testing.T) { @@ -82,7 +81,7 @@ func TestTxnDeletionOfRelatedDocFromPrimarySideForwardDirection(t *testing.T) { }, } - relationTests.Execute(t, test) + execute(t, test) } func TestTxnDeletionOfRelatedDocFromPrimarySideBackwardDirection(t *testing.T) { @@ -142,7 +141,7 @@ func TestTxnDeletionOfRelatedDocFromPrimarySideBackwardDirection(t *testing.T) { }, } - relationTests.Execute(t, test) + execute(t, test) } func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *testing.T) { @@ -232,7 +231,7 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *tes }, } - relationTests.Execute(t, test) + execute(t, test) } func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *testing.T) { @@ -316,7 +315,7 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *te }, } - relationTests.Execute(t, test) + execute(t, test) } func TestTxnDeletionOfRelatedDocFromNonPrimarySideForwardDirection(t *testing.T) { @@ -377,7 +376,7 @@ func TestTxnDeletionOfRelatedDocFromNonPrimarySideForwardDirection(t *testing.T) }, } - relationTests.Execute(t, test) + execute(t, test) } func TestTxnDeletionOfRelatedDocFromNonPrimarySideBackwardDirection(t *testing.T) { @@ -444,5 +443,5 @@ func TestTxnDeletionOfRelatedDocFromNonPrimarySideBackwardDirection(t *testing.T }, } - relationTests.Execute(t, test) + execute(t, test) } diff --git a/tests/integration/mutation/delete/simple_test.go b/tests/integration/mutation/delete/simple_test.go new file mode 100644 index 0000000000..5b28d100d3 --- /dev/null +++ b/tests/integration/mutation/delete/simple_test.go @@ -0,0 +1,65 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithoutSubSelection(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete multiple documents that exist without sub selection, should give error.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User + }`, + ExpectedError: "Field \"delete_User\" of type \"[User]\" must have a sub selection.", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithoutSubSelectionFields(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete multiple documents that exist without _key sub-selection.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User{ + + } + }`, + ExpectedError: "Syntax Error GraphQL request (2:17) Unexpected empty IN {}", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_deleted_field_test.go b/tests/integration/mutation/delete/with_deleted_field_test.go new file mode 100644 index 0000000000..25784b52d2 --- /dev/null +++ b/tests/integration/mutation/delete/with_deleted_field_test.go @@ -0,0 +1,56 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +// This test documents a bug, see: +// https://github.com/sourcenetwork/defradb/issues/1846 +func TestMutationDeletion_WithoDeletedField(t *testing.T) { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 0, + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(id: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad") { + _deleted + _key + } + }`, + Results: []map[string]any{ + { + // This should be true, as it has been deleted. + "_deleted": false, + "_key": "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_filter_test.go b/tests/integration/mutation/delete/with_filter_test.go new file mode 100644 index 0000000000..70d4550be9 --- /dev/null +++ b/tests/integration/mutation/delete/with_filter_test.go @@ -0,0 +1,207 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithFilter(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete using filter - One matching document, that exists.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(filter: {name: {_eq: "Shahzad"}}) { + name + } + }`, + Results: []map[string]any{ + { + "name": "Shahzad", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithFilterMatchingMultipleDocs(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete using filter - Multiple matching documents that exist.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + age: Int + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad", + "age": 1 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad", + "age": 2 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "age": 3 + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(filter: {name: {_eq: "Shahzad"}}) { + age + } + }`, + Results: []map[string]any{ + { + "age": uint64(2), + }, + { + "age": uint64(1), + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithEmptyFilter(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete using filter - Match everything in this collection.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Fred" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(filter: {}) { + name + } + }`, + Results: []map[string]any{ + { + "name": "Fred", + }, + { + "name": "Shahzad", + }, + { + "name": "John", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithFilterNoMatch(t *testing.T) { + test := testUtils.TestCase{ + Description: "No delete with filter: because no document matches filter.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(filter: {name: {_eq: "Lone"}}) { + name + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithFilterOnEmptyCollection(t *testing.T) { + test := testUtils.TestCase{ + Description: "No delete with filter: because the collection is empty.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User(filter: {name: {_eq: "Lone"}}) { + name + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_id_alias_test.go b/tests/integration/mutation/delete/with_id_alias_test.go new file mode 100644 index 0000000000..1890092b00 --- /dev/null +++ b/tests/integration/mutation/delete/with_id_alias_test.go @@ -0,0 +1,51 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDAndAlias(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple delete mutation with an aliased _key name.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5"]) { + fancyKey: _key + } + }`, + Results: []map[string]any{ + { + "fancyKey": "bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_id_test.go b/tests/integration/mutation/delete/with_id_test.go new file mode 100644 index 0000000000..68adcc7e6f --- /dev/null +++ b/tests/integration/mutation/delete/with_id_test.go @@ -0,0 +1,72 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDUnknownValue(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion using id that doesn't exist, where the collection is empty.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5"]) { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithIDUnknownValueAndUnrelatedRecordInCollection(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion using id that doesn't exist, where the collection is non-empty.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Not the id below" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5"]) { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_id_txn_test.go b/tests/integration/mutation/delete/with_id_txn_test.go new file mode 100644 index 0000000000..c4f2ad6bdc --- /dev/null +++ b/tests/integration/mutation/delete/with_id_txn_test.go @@ -0,0 +1,63 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDAndTxn(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple delete mutation where one element exists.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + TransactionID: immutable.Some(0), + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5"]) { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", + }, + }, + }, + testUtils.Request{ + TransactionID: immutable.Some(0), + Request: `query { + User { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_ids_alias_test.go b/tests/integration/mutation/delete/with_ids_alias_test.go new file mode 100644 index 0000000000..1c6be23278 --- /dev/null +++ b/tests/integration/mutation/delete/with_ids_alias_test.go @@ -0,0 +1,68 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDsAndSelectAlias(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete multiple documents that exist, when given multiple keys with alias.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + age: Int + points: Float + verified: Boolean + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad", + "age": 26, + "points": 48.48, + "verified": true + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "age": 26, + "points": 48.48, + "verified": true + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { + AliasKey: _key + } + }`, + Results: []map[string]any{ + { + "AliasKey": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", + }, + { + "AliasKey": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_ids_filter_test.go b/tests/integration/mutation/delete/with_ids_filter_test.go new file mode 100644 index 0000000000..8d93bdf9cf --- /dev/null +++ b/tests/integration/mutation/delete/with_ids_filter_test.go @@ -0,0 +1,51 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDsAndEmptyFilter(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion of using ids and filter, known id and empty filter.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5"], filter: {}) { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_ids_test.go b/tests/integration/mutation/delete/with_ids_test.go new file mode 100644 index 0000000000..48adcb2e48 --- /dev/null +++ b/tests/integration/mutation/delete/with_ids_test.go @@ -0,0 +1,194 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDs(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete multiple documents that exist, when given multiple keys.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad"]) { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", + }, + { + "_key": "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithEmptyIDs(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion of using ids, empty ids set.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: []) { + _key + } + }`, + Results: []map[string]any{}, + }, + testUtils.Request{ + // Make sure no documents have been deleted + Request: `query { + User { + name + } + }`, + Results: []map[string]any{ + { + "name": "Shahzad", + }, + { + "name": "John", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithIDsSingleUnknownID(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion of using ids, single unknown item.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507e"]) { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithIDsMultipleUnknownID(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion of using ids, single unknown item.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-028383cc-d6ba-5df7-959f-2bdce3536a05", "bae-028383cc-d6ba-5df7-959f-2bdce3536a03"]) { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationDeletion_WithIDsKnownAndUnknown(t *testing.T) { + test := testUtils.TestCase{ + Description: "Deletion of using ids, known and unknown items.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad" + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad"]) { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-d7546ac1-c133-5853-b866-9b9f926fe7e5", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_ids_txn_test.go b/tests/integration/mutation/delete/with_ids_txn_test.go new file mode 100644 index 0000000000..ab3ed174f1 --- /dev/null +++ b/tests/integration/mutation/delete/with_ids_txn_test.go @@ -0,0 +1,69 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithIDsAndTxn(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple multi-key delete mutation with one key that exists and txn.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + age: Int + points: Float + verified: Boolean + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad", + "age": 26, + "points": 48.48, + "verified": true + }`, + }, + testUtils.Request{ + TransactionID: immutable.Some(0), + Request: `mutation { + delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", + }, + }, + }, + testUtils.Request{ + TransactionID: immutable.Some(0), + Request: `query { + User(dockeys: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) { + _key + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/delete/with_ids_update_alias_test.go b/tests/integration/mutation/delete/with_ids_update_alias_test.go new file mode 100644 index 0000000000..a76dccffe2 --- /dev/null +++ b/tests/integration/mutation/delete/with_ids_update_alias_test.go @@ -0,0 +1,76 @@ +// Copyright 2023 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 delete + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationDeletion_WithUpdateAndIDsAndSelectAlias(t *testing.T) { + test := testUtils.TestCase{ + Description: "Delete multiple documents that exist, when given multiple keys with alias after update.", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + age: Int + points: Float + verified: Boolean + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Shahzad", + "age": 26, + "points": 48.48, + "verified": true + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "age": 26, + "points": 48.48, + "verified": true + }`, + }, + testUtils.UpdateDoc{ + DocID: 0, + Doc: `{ + "age": 27, + "points": 48.2, + "verified": false + }`, + }, + testUtils.Request{ + Request: `mutation { + delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { + AliasKey: _key + } + }`, + Results: []map[string]any{ + { + "AliasKey": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", + }, + { + "AliasKey": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/inline_array/update/simple_test.go b/tests/integration/mutation/inline_array/update/simple_test.go deleted file mode 100644 index f89d74c734..0000000000 --- a/tests/integration/mutation/inline_array/update/simple_test.go +++ /dev/null @@ -1,682 +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 update - -import ( - "testing" - - "github.com/sourcenetwork/immutable" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - inlineArray "github.com/sourcenetwork/defradb/tests/integration/mutation/inline_array" -) - -func TestMutationInlineArrayUpdateWithBooleans(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple update mutation with boolean array, replace with nil", - Request: `mutation { - update_Users(data: "{\"likedIndexes\": null}") { - name - likedIndexes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "likedIndexes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "likedIndexes": nil, - }, - }, - }, - { - Description: "Simple update mutation with boolean array, replace with empty", - Request: `mutation { - update_Users(data: "{\"likedIndexes\": []}") { - name - likedIndexes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "likedIndexes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "likedIndexes": []bool{}, - }, - }, - }, - { - Description: "Simple update mutation with boolean array, replace with same size", - Request: `mutation { - update_Users(data: "{\"likedIndexes\": [true, false, true, false]}") { - name - likedIndexes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "likedIndexes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "likedIndexes": []bool{true, false, true, false}, - }, - }, - }, - { - Description: "Simple update mutation with boolean array, replace with smaller size", - Request: `mutation { - update_Users(data: "{\"likedIndexes\": [false, true]}") { - name - likedIndexes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "likedIndexes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "likedIndexes": []bool{false, true}, - }, - }, - }, - { - Description: "Simple update mutation with boolean array, replace with larger size", - Request: `mutation { - update_Users(data: "{\"likedIndexes\": [true, false, true, false, true, true]}") { - name - likedIndexes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "likedIndexes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "likedIndexes": []bool{true, false, true, false, true, true}, - }, - }, - }, - } - - for _, test := range tests { - inlineArray.ExecuteTestCase(t, test) - } -} - -func TestMutationInlineArrayWithNillableBooleans(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple inline array with no filter, booleans", - Request: `mutation { - update_Users(data: "{\"indexLikesDislikes\": [true, true, false, true, null]}") { - name - indexLikesDislikes - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "indexLikesDislikes": [true, true, false, true] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "indexLikesDislikes": []immutable.Option[bool]{ - immutable.Some(true), - immutable.Some(true), - immutable.Some(false), - immutable.Some(true), - immutable.None[bool](), - }, - }, - }, - } - - inlineArray.ExecuteTestCase(t, test) -} - -func TestMutationInlineArrayUpdateWithIntegers(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple update mutation with integer array, replace with nil", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": null}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": nil, - }, - }, - }, - { - Description: "Simple update mutation with integer array, replace with empty", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": []}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": []int64{}, - }, - }, - }, - { - Description: "Simple update mutation with integer array, replace with same size, positive values", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": [8, 5, 3, 2, 1]}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": []int64{8, 5, 3, 2, 1}, - }, - }, - }, - { - Description: "Simple update mutation with integer array, replace with same size, positive to mixed values", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": [-1, 2, -3, 5, -8]}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": []int64{-1, 2, -3, 5, -8}, - }, - }, - }, - { - Description: "Simple update mutation with integer array, replace with smaller size, positive values", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": [1, 2, 3]}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": []int64{1, 2, 3}, - }, - }, - }, - { - Description: "Simple update mutation with integer array, replace with larger size, positive values", - Request: `mutation { - update_Users(data: "{\"favouriteIntegers\": [1, 2, 3, 5, 8, 13, 21]}") { - name - favouriteIntegers - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteIntegers": [1, 2, 3, 5, 8] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteIntegers": []int64{1, 2, 3, 5, 8, 13, 21}, - }, - }, - }, - } - - for _, test := range tests { - inlineArray.ExecuteTestCase(t, test) - } -} - -func TestMutationInlineArrayWithNillableInts(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple inline array with no filter, nillable ints", - Request: `mutation { - update_Users(data: "{\"testScores\": [null, 2, 3, null, 8]}") { - name - testScores - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "testScores": [1, null, 3] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "testScores": []immutable.Option[int64]{ - immutable.None[int64](), - immutable.Some[int64](2), - immutable.Some[int64](3), - immutable.None[int64](), - immutable.Some[int64](8), - }, - }, - }, - } - - inlineArray.ExecuteTestCase(t, test) -} - -func TestMutationInlineArrayUpdateWithFloats(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple update mutation with float array, replace with nil", - Request: `mutation { - update_Users(data: "{\"favouriteFloats\": null}") { - name - favouriteFloats - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteFloats": [3.1425, 0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteFloats": nil, - }, - }, - }, - { - Description: "Simple update mutation with float array, replace with empty", - Request: `mutation { - update_Users(data: "{\"favouriteFloats\": []}") { - name - favouriteFloats - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteFloats": [3.1425, 0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteFloats": []float64{}, - }, - }, - }, - { - Description: "Simple update mutation with float array, replace with same size", - Request: `mutation { - update_Users(data: "{\"favouriteFloats\": [3.1425, -0.00000000001, 1000000]}") { - name - favouriteFloats - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteFloats": [3.1425, 0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteFloats": []float64{3.1425, -0.00000000001, 1000000}, - }, - }, - }, - { - Description: "Simple update mutation with float array, replace with smaller size", - Request: `mutation { - update_Users(data: "{\"favouriteFloats\": [3.14]}") { - name - favouriteFloats - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteFloats": [3.1425, 0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteFloats": []float64{3.14}, - }, - }, - }, - { - Description: "Simple update mutation with float array, replace with larger size", - Request: `mutation { - update_Users(data: "{\"favouriteFloats\": [3.1425, 0.00000000001, -10, 6.626070]}") { - name - favouriteFloats - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "favouriteFloats": [3.1425, 0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "favouriteFloats": []float64{3.1425, 0.00000000001, -10, 6.626070}, - }, - }, - }, - } - - for _, test := range tests { - inlineArray.ExecuteTestCase(t, test) - } -} - -func TestMutationInlineArrayWithNillableFloats(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple inline array with no filter, nillable floats", - Request: `mutation { - update_Users(data: "{\"pageRatings\": [3.1425, -0.00000000001, null, 10]}") { - name - pageRatings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "pageRatings": [3.1425, null, -0.00000000001, 10] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "pageRatings": []immutable.Option[float64]{ - immutable.Some(3.1425), - immutable.Some(-0.00000000001), - immutable.None[float64](), - immutable.Some[float64](10), - }, - }, - }, - } - - inlineArray.ExecuteTestCase(t, test) -} - -func TestMutationInlineArrayUpdateWithStrings(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple update mutation with string array, replace with nil", - Request: `mutation { - update_Users(data: "{\"preferredStrings\": null}") { - name - preferredStrings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "preferredStrings": ["", "the previous", "the first", "empty string"] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "preferredStrings": nil, - }, - }, - }, - { - Description: "Simple update mutation with string array, replace with empty", - Request: `mutation { - update_Users(data: "{\"preferredStrings\": []}") { - name - preferredStrings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "preferredStrings": ["", "the previous", "the first", "empty string"] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "preferredStrings": []string{}, - }, - }, - }, - { - Description: "Simple update mutation with string array, replace with same size", - Request: `mutation { - update_Users(data: "{\"preferredStrings\": [null, \"the previous\", \"the first\", \"null string\"]}") { - name - preferredStrings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "preferredStrings": ["", "the previous", "the first", "empty string"] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "preferredStrings": []string{"", "the previous", "the first", "null string"}, - }, - }, - }, - { - Description: "Simple update mutation with string array, replace with smaller size", - Request: `mutation { - update_Users(data: "{\"preferredStrings\": [\"\", \"the first\"]}") { - name - preferredStrings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "preferredStrings": ["", "the previous", "the first", "empty string"] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "preferredStrings": []string{"", "the first"}, - }, - }, - }, - { - Description: "Simple update mutation with string array, replace with larger size", - Request: `mutation { - update_Users(data: "{\"preferredStrings\": [\"\", \"the previous\", \"the first\", \"empty string\", \"blank string\", \"hitchi\"]}") { - name - preferredStrings - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "preferredStrings": ["", "the previous", "the first", "empty string"] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "preferredStrings": []string{ - "", - "the previous", - "the first", - "empty string", - "blank string", - "hitchi", - }, - }, - }, - }, - } - - for _, test := range tests { - inlineArray.ExecuteTestCase(t, test) - } -} - -func TestMutationInlineArrayWithNillableStrings(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple inline array with no filter, nillable strings", - Request: `mutation { - update_Users(data: "{\"pageHeaders\": [\"\", \"the previous\", null, \"empty string\", \"blank string\", \"hitchi\"]}") { - name - pageHeaders - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "pageHeaders": ["", "the previous", "the first", "empty string", null] - }`, - }, - }, - Results: []map[string]any{ - { - "name": "John", - "pageHeaders": []immutable.Option[string]{ - immutable.Some(""), - immutable.Some("the previous"), - immutable.None[string](), - immutable.Some("empty string"), - immutable.Some("blank string"), - immutable.Some("hitchi"), - }, - }, - }, - } - - inlineArray.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/inline_array/utils.go b/tests/integration/mutation/inline_array/utils.go deleted file mode 100644 index c866711614..0000000000 --- a/tests/integration/mutation/inline_array/utils.go +++ /dev/null @@ -1,35 +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 inline_array - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -var userCollectionGQLSchema = (` - type Users { - name: String - likedIndexes: [Boolean!] - indexLikesDislikes: [Boolean] - favouriteIntegers: [Int!] - testScores: [Int] - favouriteFloats: [Float!] - pageRatings: [Float] - preferredStrings: [String!] - pageHeaders: [String] - } -`) - -func ExecuteTestCase(t *testing.T, test testUtils.RequestTestCase) { - testUtils.ExecuteRequestTestCase(t, userCollectionGQLSchema, []string{"Users"}, test) -} diff --git a/tests/integration/mutation/simple/mix/with_txn_test.go b/tests/integration/mutation/mix/with_txn_test.go similarity index 97% rename from tests/integration/mutation/simple/mix/with_txn_test.go rename to tests/integration/mutation/mix/with_txn_test.go index a2d1e9b08e..3b12513a23 100644 --- a/tests/integration/mutation/simple/mix/with_txn_test.go +++ b/tests/integration/mutation/mix/with_txn_test.go @@ -16,7 +16,6 @@ import ( "github.com/sourcenetwork/immutable" testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" ) func TestMutationWithTxnDeletesUserGivenSameTransaction(t *testing.T) { @@ -247,6 +246,14 @@ func TestMutationWithTxnDoesNotAllowUpdateInSecondTransactionUser(t *testing.T) test := testUtils.TestCase{ Description: "Update by two different transactions", Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + age: Int + } + `, + }, testUtils.CreateDoc{ CollectionID: 0, Doc: `{ @@ -315,5 +322,5 @@ func TestMutationWithTxnDoesNotAllowUpdateInSecondTransactionUser(t *testing.T) }, } - simpleTests.Execute(t, test) + testUtils.ExecuteTestCase(t, test) } diff --git a/tests/integration/mutation/one_to_one/update/with_simple_test.go b/tests/integration/mutation/one_to_one/update/with_simple_test.go deleted file mode 100644 index e01a6253fa..0000000000 --- a/tests/integration/mutation/one_to_one/update/with_simple_test.go +++ /dev/null @@ -1,192 +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 update - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one" -) - -// Note: This test should probably not pass, as it contains a -// reference to a document that doesnt exist. -func TestMutationUpdateOneToOneNoChild(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one create mutation, from the wrong side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John" - }`, - }, - testUtils.Request{ - Request: `mutation { - update_Author(data: "{\"name\": \"John Grisham\",\"published_id\": \"bae-fd541c25-229e-5280-b44b-e5c2af3e374d\"}") { - name - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - }, - }, - }, - }, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestMutationUpdateOneToOne(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one update mutation", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.Request{ - Request: ` - mutation { - update_Author(data: "{\"name\": \"John Grisham\",\"published_id\": \"bae-3d236f89-6a31-5add-a36a-27971a2eac76\"}") { - name - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - }, - }, - }, - testUtils.Request{ - Request: ` - query { - Book { - name - author { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - "author": map[string]any{ - "name": "John Grisham", - }, - }, - }, - }, - testUtils.Request{ - Request: ` - query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": map[string]any{ - "name": "Painted House", - }, - }, - }, - }, - }, - } - - simpleTests.ExecuteTestCase(t, test) -} - -func TestMutationUpdateOneToOneSecondarySide(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one create mutation, from the secondary side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.Request{ - Request: ` - mutation { - update_Book(data: "{\"name\": \"Painted House\",\"author_id\": \"bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed\"}") { - name - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - }, - }, - }, - testUtils.Request{ - Request: ` - query { - Book { - name - author { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - "author": map[string]any{ - "name": "John Grisham", - }, - }, - }, - }, - testUtils.Request{ - Request: ` - query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": map[string]any{ - "name": "Painted House", - }, - }, - }, - }, - }, - } - simpleTests.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/create/simple_test.go b/tests/integration/mutation/simple/create/simple_test.go deleted file mode 100644 index b173611f7f..0000000000 --- a/tests/integration/mutation/simple/create/simple_test.go +++ /dev/null @@ -1,124 +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 create - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" -) - -func TestMutationCreateSimpleErrorsGivenNonExistantField(t *testing.T) { - test := testUtils.TestCase{ - Description: "Simple create mutation with non existant field", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type Users { - name: String - } - `, - }, - testUtils.Request{ - Request: `mutation { - create_Users(data: "{\"name\": \"John\",\"fieldDoesNotExist\": 27}") { - _key - } - }`, - ExpectedError: "The given field does not exist. Name: fieldDoesNotExist", - }, - testUtils.Request{ - // Ensure that no documents have been written. - Request: ` - query { - Users { - name - } - } - `, - Results: []map[string]any{}, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestMutationCreateSimple(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple create mutation", - Request: `mutation { - create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") { - _key - name - age - } - }`, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "age": uint64(27), - "name": "John", - }, - }, - } - - simpleTests.ExecuteTestCase(t, test) -} - -func TestMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple create mutation where document already exists.", - Request: `mutation { - create_User(data: "{\"name\": \"John\",\"age\": 27}") { - _key - name - age - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27 - }`, - }, - }, - ExpectedError: "a document with the given dockey already exists. DocKey: ", - } - - simpleTests.ExecuteTestCase(t, test) -} - -func TestMutationCreateSimpleDoesNotCreateDocEmptyData(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple create mutation with empty data param.", - Request: `mutation { - create_User(data: "") { - _key - name - age - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27 - }`, - }, - }, - ExpectedError: "given data payload is empty", - } - - simpleTests.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/create/with_version_test.go b/tests/integration/mutation/simple/create/with_version_test.go deleted file mode 100644 index 8a9abcaaf2..0000000000 --- a/tests/integration/mutation/simple/create/with_version_test.go +++ /dev/null @@ -1,42 +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 create - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" -) - -func TestMutationCreateSimpleReturnVersionCID(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple create mutation", - Request: `mutation { - create_User(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") { - _version { - cid - } - } - }`, - Results: []map[string]any{ - { - "_version": []map[string]any{ - { - "cid": "bafybeif5xonyzwmg5y5ocebvjkb4vs3i3qmrnuwwtf4yshvabqcqcxnwky", - }, - }, - }, - }, - } - - simpleTests.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/delete/multi_ids_test.go b/tests/integration/mutation/simple/delete/multi_ids_test.go deleted file mode 100644 index 80585d5d79..0000000000 --- a/tests/integration/mutation/simple/delete/multi_ids_test.go +++ /dev/null @@ -1,478 +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 delete - -import ( - "testing" - - "github.com/sourcenetwork/immutable" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" -) - -func TestDeletionOfMultipleDocumentUsingMultipleKeysWhereOneExists(t *testing.T) { - test := testUtils.TestCase{ - Description: "Simple multi-key delete mutation with one key that exists.", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - points: Float - verified: Boolean - } - `, - }, - testUtils.CreateDoc{ - Doc: `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - testUtils.Request{ - TransactionID: immutable.Some(0), - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) { - _key - } - }`, - Results: []map[string]any{ - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - }, - testUtils.Request{ - TransactionID: immutable.Some(0), - Request: `query { - User(dockeys: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) { - _key - } - }`, - Results: []map[string]any{}, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestDeletionOfMultipleDocumentUsingMultipleKeys_Success(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Delete multiple documents that exist, when given multiple keys.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { - _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", - }, - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - ExpectedError: "", - }, - - { - Description: "Delete multiple documents that exist, when given multiple keys with alias.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { - AliasKey: _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{ - { - "AliasKey": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", - }, - { - "AliasKey": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - ExpectedError: "", - }, - - { - Description: "Delete multiple documents that exist, where an update happens too.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { - AliasKey: _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - `{ - "age": 27, - "points": 48.2, - "verified": false - }`, - }, - }, - }, - Results: []map[string]any{ - { - "AliasKey": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", - }, - { - "AliasKey": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - ExpectedError: "", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeleteWithEmptyIdsSet(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion of using ids, empty ids set.", - Request: `mutation { - delete_User(ids: []) { - _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeleteWithSingleUnknownIds(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion of using ids, single unknown item.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507e"]) { - _key - } - }`, - Results: []map[string]any{}, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeleteWithMultipleUnknownIds(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion of using ids, multiple unknown items.", - Request: `mutation { - delete_User(ids: ["bae-028383cc-d6ba-5df7-959f-2bdce3536a05", "bae-028383cc-d6ba-5df7-959f-2bdce3536a03"]) { - _key - } - }`, - Results: []map[string]any{}, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeleteWithUnknownAndKnownIds(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion of using ids, known and unknown items.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-028383cc-d6ba-5df7-959f-2bdce3536a03"]) { - _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeleteWithKnownIdsAndEmptyFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion of using ids and filter, known id and empty filter.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"], filter: {}) { - _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeletionOfMultipleDocumentUsingMultipleKeys_Failure(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Delete multiple documents that exist without sub selection, should give error.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - ExpectedError: "Field \"delete_User\" of type \"[User]\" must have a sub selection.", - }, - - { - Description: "Delete multiple documents that exist without _key sub-selection.", - Request: `mutation { - delete_User(ids: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d", "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e"]) { - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - ExpectedError: "Syntax Error GraphQL request (2:114) Unexpected empty IN {}\n\n1: mutation {\n2: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009delete_User(ids: [\"bae-6a6482a8-24e1-5c73-a237-ca569e41507d\", \"bae-3a1a496e-24eb-5ae3-9c17-524c146a393e\"]) {\n ^\n3: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009}\n", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeletionOfMultipleDocumentsUsingSingleKeyWithShowDeletedDocumentQuery_Success(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - } - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John", - "age": 43 - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Andy", - "age": 74 - }`, - }, - testUtils.Request{ - Request: `mutation { - delete_User(ids: ["bae-05de0e64-f300-55b3-8973-5fa79045a083", "bae-07e5c44c-ee88-5c92-85ad-fb3148c48bef"]){ - _key - } - }`, - Results: []map[string]any{ - { - "_key": "bae-05de0e64-f300-55b3-8973-5fa79045a083", - }, - { - "_key": "bae-07e5c44c-ee88-5c92-85ad-fb3148c48bef", - }, - }, - }, - testUtils.Request{ - Request: `query { - User(showDeleted: true) { - _deleted - name - age - } - }`, - Results: []map[string]any{ - { - "_deleted": true, - "name": "Andy", - "age": uint64(74), - }, - { - "_deleted": true, - "name": "John", - "age": uint64(43), - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestDeletionOfMultipleDocumentsUsingEmptySet(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - } - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John", - "age": 43 - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Andy", - "age": 74 - }`, - }, - testUtils.Request{ - Request: `mutation { - delete_User(ids: []){ - _key - } - }`, - Results: []map[string]any{}, - }, - testUtils.Request{ - // Make sure no documents have been deleted - Request: `query { - User { - name - age - } - }`, - Results: []map[string]any{ - { - "name": "Andy", - "age": uint64(74), - }, - { - "name": "John", - "age": uint64(43), - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/delete/single_id_test.go b/tests/integration/mutation/simple/delete/single_id_test.go deleted file mode 100644 index a3ec777233..0000000000 --- a/tests/integration/mutation/simple/delete/single_id_test.go +++ /dev/null @@ -1,282 +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 delete - -import ( - "testing" - - "github.com/sourcenetwork/immutable" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" -) - -func TestDeletionOfADocumentUsingSingleKeyWhereDocExists(t *testing.T) { - test := testUtils.TestCase{ - Description: "Simple delete mutation where one element exists.", - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - points: Float - verified: Boolean - } - `, - }, - testUtils.CreateDoc{ - Doc: `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - testUtils.Request{ - TransactionID: immutable.Some(0), - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") { - _key - } - }`, - Results: []map[string]any{ - { - "_key": "bae-8ca944fd-260e-5a44-b88f-326d9faca810", - }, - }, - }, - testUtils.Request{ - TransactionID: immutable.Some(0), - Request: `query { - User(dockey: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") { - _key - } - }`, - - // explicitly empty - Results: []map[string]any{}, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} - -func TestDeletionOfADocumentUsingSingleKey_Success(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple delete mutation with an aliased _key name.", - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - }, - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") { - fancyKey: _key - } - }`, - - Results: []map[string]any{ - { - "fancyKey": "bae-8ca944fd-260e-5a44-b88f-326d9faca810", - }, - }, - ExpectedError: "", - }, - { - Description: "Delete an updated document and return an aliased _key name.", - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") { - myTestKey: _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - `{ - "age": 27, - "points": 48.2, - "verified": false - }`, - }, - }, - }, - Results: []map[string]any{ - { - "myTestKey": "bae-8ca944fd-260e-5a44-b88f-326d9faca810", - }, - }, - ExpectedError: "", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeleteWithUnknownIdEmptyCollection(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion using id that doesn't exist, where the collection is empty.", - Request: `mutation { - delete_User(id: "bae-028383cc-d6ba-5df7-959f-2bdce3536a05") { - _key - } - }`, - Docs: map[int][]string{}, - Results: []map[string]any{}, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeleteWithUnknownId(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Deletion using id that doesn't exist, where the collection is non-empty.", - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca811") { - _key - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - } - simpleTests.ExecuteTestCase(t, test) -} - -func TestDeletionOfADocumentUsingSingleKey_Failure(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Deletion of a document without sub selection, should give error.", - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - ExpectedError: "Field \"delete_User\" of type \"[User]\" must have a sub selection.", - }, - - { - Description: "Deletion of a document without _key sub-selection.", - Request: `mutation { - delete_User(id: "bae-8ca944fd-260e-5a44-b88f-326d9faca810") { - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.5, - "verified": true - }`, - }, - }, - Results: []map[string]any{}, - ExpectedError: "Syntax Error GraphQL request (2:67) Unexpected empty IN {}\n\n1: mutation {\n2: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009delete_User(id: \"bae-8ca944fd-260e-5a44-b88f-326d9faca810\") {\n ^\n3: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009}\n", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeletionOfADocumentUsingSingleKeyWithShowDeletedDocumentQuery_Success(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - } - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John", - "age": 43 - }`, - }, - testUtils.Request{ - Request: `mutation { - delete_User(id: "bae-07e5c44c-ee88-5c92-85ad-fb3148c48bef") { - _deleted - _key - } - }`, - Results: []map[string]any{ - { - // Note: This should show a `Deleted` status but the order of the planNodes - // makes it so the status is requested prior to deleting. If the planNode ordering - // can be altered, this can change in the future. - "_deleted": false, - "_key": "bae-07e5c44c-ee88-5c92-85ad-fb3148c48bef", - }, - }, - }, - testUtils.Request{ - Request: `query { - User(showDeleted: true) { - _deleted - name - age - } - }`, - Results: []map[string]any{ - { - "_deleted": true, - "name": "John", - "age": uint64(43), - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/delete/with_filter_test.go b/tests/integration/mutation/simple/delete/with_filter_test.go deleted file mode 100644 index 6c934bfd5f..0000000000 --- a/tests/integration/mutation/simple/delete/with_filter_test.go +++ /dev/null @@ -1,418 +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 delete - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" -) - -func TestDeletionOfDocumentsWithFilter_Success(t *testing.T) { - tests := []testUtils.RequestTestCase{ - - { - Description: "Delete using filter - One matching document, that exists.", - - Request: `mutation { - delete_User(filter: {name: {_eq: "Shahzad"}}) { - _key - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{ - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - }, - - ExpectedError: "", - }, - - { - Description: "Delete using filter - Multiple matching documents that exist.", - Request: `mutation { - delete_User(filter: {name: {_eq: "Shahzad"}}) { - _key - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 25, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 6, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 1, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{ - { - "_key": "bae-4b5b1765-560c-5843-9abc-24d21d8aa598", - }, - { - "_key": "bae-5a8530c0-c521-5e83-8243-4ce267bc76fa", - }, - { - "_key": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - { - "_key": "bae-ca88bc10-1415-59b1-a72c-d19ed44d4e15", - }, - }, - - ExpectedError: "", - }, - - { - Description: "Delete using filter - Multiple matching documents that exist with alias.", - - Request: `mutation { - delete_User(filter: { - _and: [ - {age: {_lt: 26}}, - {verified: {_eq: true}}, - ] - }) { - DeletedKeyByFilter: _key - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 25, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 6, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 1, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{ - { - "DeletedKeyByFilter": "bae-4b5b1765-560c-5843-9abc-24d21d8aa598", - }, - { - "DeletedKeyByFilter": "bae-5a8530c0-c521-5e83-8243-4ce267bc76fa", - }, - { - "DeletedKeyByFilter": "bae-ca88bc10-1415-59b1-a72c-d19ed44d4e15", - }, - }, - - ExpectedError: "", - }, - - { - Description: "Delete using filter - Match everything in this collection.", - - Request: `mutation { - delete_User(filter: {}) { - DeletedKeyByFilter: _key - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 25, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 6, - "points": 48.48, - "verified": true - }`, - `{ - "name": "Shahzad", - "age": 1, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{ - { - "DeletedKeyByFilter": "bae-3a1a496e-24eb-5ae3-9c17-524c146a393e", - }, - { - "DeletedKeyByFilter": "bae-4b5b1765-560c-5843-9abc-24d21d8aa598", - }, - { - "DeletedKeyByFilter": "bae-5a8530c0-c521-5e83-8243-4ce267bc76fa", - }, - { - "DeletedKeyByFilter": "bae-6a6482a8-24e1-5c73-a237-ca569e41507d", - }, - { - "DeletedKeyByFilter": "bae-ca88bc10-1415-59b1-a72c-d19ed44d4e15", - }, - }, - - ExpectedError: "", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeletionOfDocumentsWithFilter_Failure(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "No delete with filter: because no document matches filter.", - - Request: `mutation { - delete_User(filter: {name: {_eq: "Lone"}}) { - _key - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{}, - - ExpectedError: "", - }, - - { - Description: "No delete with filter: because the collection is empty.", - - Request: `mutation { - delete_User(filter: {name: {_eq: "Shahzad"}}) { - _key - } - }`, - - Docs: map[int][]string{}, - - Results: []map[string]any{}, - - ExpectedError: "", - }, - - { - Description: "No delete with filter: because has no sub-selection.", - - Request: `mutation { - delete_User(filter: {name: {_eq: "Shahzad"}}) - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{}, - - ExpectedError: "Field \"delete_User\" of type \"[User]\" must have a sub selection.", - }, - - { - Description: "No delete with filter: because has no _key in sub-selection.", - - Request: `mutation { - delete_User(filter: {name: {_eq: "Shahzad"}}) { - } - }`, - - Docs: map[int][]string{ - 0: { - `{ - "name": "Shahzad", - "age": 26, - "points": 48.48, - "verified": true - }`, - `{ - "name": "John", - "age": 26, - "points": 48.48, - "verified": true - }`, - }, - }, - - Results: []map[string]any{}, - - ExpectedError: "Syntax Error GraphQL request (2:53) Unexpected empty IN {}\n\n1: mutation {\n2: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009delete_User(filter: {name: {_eq: \"Shahzad\"}}) {\n ^\n3: \\u0009\\u0009\\u0009\\u0009\\u0009\\u0009}\n", - }, - } - - for _, test := range tests { - simpleTests.ExecuteTestCase(t, test) - } -} - -func TestDeletionOfDocumentsWithFilterWithShowDeletedDocumentQuery_Success(t *testing.T) { - test := testUtils.TestCase{ - Actions: []any{ - testUtils.SchemaUpdate{ - Schema: ` - type User { - name: String - age: Int - } - `, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John", - "age": 43 - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Andy", - "age": 74 - }`, - }, - testUtils.Request{ - Request: `mutation { - delete_User(filter: {name: {_eq: "John"}}) { - _key - } - }`, - Results: []map[string]any{ - { - "_key": "bae-07e5c44c-ee88-5c92-85ad-fb3148c48bef", - }, - }, - }, - testUtils.Request{ - Request: `query { - User(showDeleted: true) { - _deleted - name - age - } - }`, - Results: []map[string]any{ - { - "_deleted": false, - "name": "Andy", - "age": uint64(74), - }, - { - "_deleted": true, - "name": "John", - "age": uint64(43), - }, - }, - }, - }, - } - - testUtils.ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/update/utils.go b/tests/integration/mutation/simple/update/utils.go deleted file mode 100644 index 920282bdea..0000000000 --- a/tests/integration/mutation/simple/update/utils.go +++ /dev/null @@ -1,31 +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 update - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -var userSchema = (` - type User { - name: String - age: Int - points: Float - verified: Boolean - created_at: DateTime - } -`) - -func ExecuteTestCase(t *testing.T, test testUtils.RequestTestCase) { - testUtils.ExecuteRequestTestCase(t, userSchema, []string{"User"}, test) -} diff --git a/tests/integration/mutation/simple/update/with_datetime_test.go b/tests/integration/mutation/simple/update/with_datetime_test.go deleted file mode 100644 index e7a93605d6..0000000000 --- a/tests/integration/mutation/simple/update/with_datetime_test.go +++ /dev/null @@ -1,174 +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 update - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestSimpleDateTimeMutationUpdateWithBooleanFilter(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple DateTime update mutation with boolean equals filter", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"created_at\": \"2021-07-23T03:46:56.647Z\"}") { - _key - name - created_at - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1, - "created_at": "2011-07-23T03:46:56.647Z" - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-e0374cf9-4e46-5494-bb8a-6dea31912d6b", - "name": "John", - "created_at": "2021-07-23T03:46:56.647Z", - }, - }, - }, - { - Description: "Simple DateTime update mutation with boolean equals filter, multiple rows but single match", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"created_at\": \"2021-07-23T03:46:56.647Z\"}") { - _key - name - created_at - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1, - "created_at": "2011-07-23T03:46:56.647Z" - }`, - `{ - "name": "Bob", - "age": 39, - "verified": false, - "points": 66.6, - "created_at": "2041-07-23T03:46:56.647Z" - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-e0374cf9-4e46-5494-bb8a-6dea31912d6b", - "name": "John", - "created_at": "2021-07-23T03:46:56.647Z", - }, - }, - }, - { - Description: "Simple DateTime update mutation with boolean equals filter, multiple rows", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"created_at\": \"2021-07-23T03:46:56.647Z\"}") { - _key - name - created_at - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1, - "created_at": "2011-07-23T03:46:56.647Z" - }`, - `{ - "name": "Bob", - "age": 39, - "verified": true, - "points": 66.6, - "created_at": "2001-07-23T03:46:56.647Z" - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-b2f6bd19-56bb-5717-8367-a638e3ca52e0", - "name": "Bob", - "created_at": "2021-07-23T03:46:56.647Z", - }, - { - "_key": "bae-e0374cf9-4e46-5494-bb8a-6dea31912d6b", - "name": "John", - "created_at": "2021-07-23T03:46:56.647Z", - }, - }, - }, - } - - for _, test := range tests { - ExecuteTestCase(t, test) - } -} - -func TestSimpleDateTimeMutationUpdateWithIdInFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple DateTime update mutation with id in filter, multiple rows", - Request: `mutation { - update_User(ids: ["bae-e0374cf9-4e46-5494-bb8a-6dea31912d6b", "bae-b2f6bd19-56bb-5717-8367-a638e3ca52e0"], data: "{\"created_at\": \"2021-07-23T03:46:56.647Z\"}") { - _key - name - created_at - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1, - "created_at": "2011-07-23T03:46:56.647Z" - }`, - `{ - "name": "Bob", - "age": 39, - "verified": true, - "points": 66.6, - "created_at": "2001-07-23T03:46:56.647Z" - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-b2f6bd19-56bb-5717-8367-a638e3ca52e0", - "name": "Bob", - "created_at": "2021-07-23T03:46:56.647Z", - }, - { - "_key": "bae-e0374cf9-4e46-5494-bb8a-6dea31912d6b", - "name": "John", - "created_at": "2021-07-23T03:46:56.647Z", - }, - }, - } - - ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/update/with_filter_test.go b/tests/integration/mutation/simple/update/with_filter_test.go deleted file mode 100644 index 86ef991567..0000000000 --- a/tests/integration/mutation/simple/update/with_filter_test.go +++ /dev/null @@ -1,259 +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 update - -import ( - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestSimpleMutationUpdateWithBooleanFilterWhereResultFilteredOut(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple update mutation with boolean equals filter", - // The update will result in a record that no longer matches the filter - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"verified\":false}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - }, - }, - // As the record no longer matches the filter it is not returned - Results: []map[string]any{}, - } - - ExecuteTestCase(t, test) -} - -func TestSimpleMutationUpdateWithBooleanFilter(t *testing.T) { - tests := []testUtils.RequestTestCase{ - { - Description: "Simple update mutation with boolean equals filter", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "name": "John", - "points": float64(59), - }, - }, - }, - { - Description: "Simple update mutation with boolean equals filter, multiple rows but single match", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - `{ - "name": "Bob", - "age": 39, - "verified": false, - "points": 66.6 - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "name": "John", - "points": float64(59), - }, - }, - }, - { - Description: "Simple update mutation with boolean equals filter, multiple rows", - Request: `mutation { - update_User(filter: {verified: {_eq: true}}, data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - `{ - "name": "Bob", - "age": 39, - "verified": true, - "points": 66.6 - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "name": "John", - "points": float64(59), - }, - { - "_key": "bae-455b5896-6203-582f-b46e-729c53a2d14b", - "name": "Bob", - "points": float64(59), - }, - }, - }, - } - - for _, test := range tests { - ExecuteTestCase(t, test) - } -} - -func TestSimpleMutationUpdateWithIdInFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple update mutation with id in filter, multiple rows", - Request: `mutation { - update_User(ids: ["bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", "bae-958c9334-73cf-5695-bf06-cf06826babfa"], data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - `{ - "name": "Bob", - "age": 39, - "verified": false, - "points": 66.6 - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "name": "John", - "points": float64(59), - }, - { - "_key": "bae-958c9334-73cf-5695-bf06-cf06826babfa", - "name": "Bob", - "points": float64(59), - }, - }, - } - - ExecuteTestCase(t, test) -} - -func TestSimpleMutationUpdateWithIdEqualsFilter(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple update mutation with id equals filter, multiple rows but single match", - Request: `mutation { - update_User(id: "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - `{ - "name": "Bob", - "age": 39, - "verified": false, - "points": 66.6 - }`, - }, - }, - Results: []map[string]any{ - { - "_key": "bae-0a24cf29-b2c2-5861-9d00-abd6250c475d", - "name": "John", - "points": float64(59), - }, - }, - } - - ExecuteTestCase(t, test) -} - -func TestSimpleMutationUpdateWithNonExistantId(t *testing.T) { - test := testUtils.RequestTestCase{ - Description: "Simple update mutation with non existant id", - Request: `mutation { - update_User(id: "bae-does-not-exist", data: "{\"points\": 59}") { - _key - name - points - } - }`, - Docs: map[int][]string{ - 0: { - `{ - "name": "John", - "age": 27, - "verified": true, - "points": 42.1 - }`, - }, - }, - Results: []map[string]any{}, - } - - ExecuteTestCase(t, test) -} diff --git a/tests/integration/mutation/simple/special/invalid_operation_test.go b/tests/integration/mutation/special/invalid_operation_test.go similarity index 60% rename from tests/integration/mutation/simple/special/invalid_operation_test.go rename to tests/integration/mutation/special/invalid_operation_test.go index 7a6f660481..4a8ae2f4c9 100644 --- a/tests/integration/mutation/simple/special/invalid_operation_test.go +++ b/tests/integration/mutation/special/invalid_operation_test.go @@ -14,19 +14,29 @@ import ( "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple" ) func TestMutationInvalidMutation(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple invalid mutation", - Request: `mutation { - dostuff_User(data: "") { - _key - } - }`, - ExpectedError: "Cannot query field \"dostuff_User\" on type \"Mutation\".", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.Request{ + Request: `mutation { + dostuff_User(data: "") { + _key + } + }`, + ExpectedError: "Cannot query field \"dostuff_User\" on type \"Mutation\".", + }, + }, } - simpleTests.ExecuteTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } diff --git a/tests/integration/mutation/update/field_kinds/array_bool_test.go b/tests/integration/mutation/update/field_kinds/array_bool_test.go new file mode 100644 index 0000000000..bbc6938c28 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_bool_test.go @@ -0,0 +1,284 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfBooleansToNil(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": null + }`, + // This restriction should be removed when we can, it is here because of + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.GQLRequestMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": nil, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfBooleansToNil_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": null + }`, + // This is a bug, this test should be removed in + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.CollectionNamedMutationType, + testUtils.CollectionSaveMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + ExpectedError: "EOF", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfBooleansToEmpty(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with empty", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": [] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": []bool{}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfBooleansToSameSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with same size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": [true, false, true, false] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": []bool{true, false, true, false}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfBooleansToSmallerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with smaller size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": [false, true] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": []bool{false, true}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfBooleansToLargerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with larger size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": [true, false, true, false, true, true] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": []bool{true, false, true, false, true, true}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_float_test.go b/tests/integration/mutation/update/field_kinds/array_float_test.go new file mode 100644 index 0000000000..0889c12be9 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_float_test.go @@ -0,0 +1,284 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfFloatsToNil(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": null + }`, + // This restriction should be removed when we can, it is here because of + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.GQLRequestMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": nil, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfFloatsToNil_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": null + }`, + // This is a bug, this test should be removed in + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.CollectionNamedMutationType, + testUtils.CollectionSaveMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + ExpectedError: "EOF", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfFloatsToEmpty(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with empty", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": [] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": []float64{}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfFloatsToSameSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with same size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": [3.1425, -0.00000000001, 1000000] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": []float64{3.1425, -0.00000000001, 1000000}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfFloatsToSmallerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with smaller size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": [3.14] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": []float64{3.14}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfFloatsToLargerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with float array, replace with larger size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, 0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": [3.1425, 0.00000000001, -10, 6.626070] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": []float64{3.1425, 0.00000000001, -10, 6.626070}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_int_test.go b/tests/integration/mutation/update/field_kinds/array_int_test.go new file mode 100644 index 0000000000..0ce79d44dc --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_int_test.go @@ -0,0 +1,327 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfIntsToNil(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": null + }`, + // This restriction should be removed when we can, it is here because of + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.GQLRequestMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": nil, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToNil_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": null + }`, + // This is a bug, this test should be removed in + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.CollectionNamedMutationType, + testUtils.CollectionSaveMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + ExpectedError: "EOF", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToEmpty(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with empty", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []int64{}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToSameSizePositiveValues(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with same size, positive values", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [8, 5, 3, 2, 1] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []int64{8, 5, 3, 2, 1}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToSameSizeMixedValues(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with same size, positive to mixed values", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [-1, 2, -3, 5, -8] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []int64{-1, 2, -3, 5, -8}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToSmallerSizePositiveValues(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with smaller size, positive values", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [1, 2, 3] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []int64{1, 2, 3}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfIntsToLargerSizePositiveValues(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with integer array, replace with larger size, positive values", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, 2, 3, 5, 8] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [1, 2, 3, 5, 8, 13, 21] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []int64{1, 2, 3, 5, 8, 13, 21}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_nillable_bool_test.go b/tests/integration/mutation/update/field_kinds/array_nillable_bool_test.go new file mode 100644 index 0000000000..d069927d5e --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_nillable_bool_test.go @@ -0,0 +1,68 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfNillableBooleans(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + likedIndexes: [Boolean] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "likedIndexes": [true, true, false, true] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "likedIndexes": [true, true, false, true, null] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + likedIndexes + } + } + `, + Results: []map[string]any{ + { + "likedIndexes": []immutable.Option[bool]{ + immutable.Some(true), + immutable.Some(true), + immutable.Some(false), + immutable.Some(true), + immutable.None[bool](), + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_nillable_float_test.go b/tests/integration/mutation/update/field_kinds/array_nillable_float_test.go new file mode 100644 index 0000000000..825461cd4c --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_nillable_float_test.go @@ -0,0 +1,67 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfNillableFloats(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple inline array with no filter, nillable floats", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteFloats: [Float] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteFloats": [3.1425, null, -0.00000000001, 10] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteFloats": [3.1425, -0.00000000001, null, 10] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteFloats + } + } + `, + Results: []map[string]any{ + { + "favouriteFloats": []immutable.Option[float64]{ + immutable.Some(3.1425), + immutable.Some(-0.00000000001), + immutable.None[float64](), + immutable.Some[float64](10), + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_nillable_int_test.go b/tests/integration/mutation/update/field_kinds/array_nillable_int_test.go new file mode 100644 index 0000000000..99e28d2520 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_nillable_int_test.go @@ -0,0 +1,68 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfNillableInts(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple inline array with no filter, nillable ints", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + favouriteIntegers: [Int] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "favouriteIntegers": [1, null, 3] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "favouriteIntegers": [null, 2, 3, null, 8] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + favouriteIntegers + } + } + `, + Results: []map[string]any{ + { + "favouriteIntegers": []immutable.Option[int64]{ + immutable.None[int64](), + immutable.Some[int64](2), + immutable.Some[int64](3), + immutable.None[int64](), + immutable.Some[int64](8), + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_nillable_string_test.go b/tests/integration/mutation/update/field_kinds/array_nillable_string_test.go new file mode 100644 index 0000000000..eea09e0157 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_nillable_string_test.go @@ -0,0 +1,69 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfStringsInts(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple inline array with no filter, nillable string", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string", null] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": ["", "the previous", null, "empty string", "blank string", "hitchi"] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": []immutable.Option[string]{ + immutable.Some(""), + immutable.Some("the previous"), + immutable.None[string](), + immutable.Some("empty string"), + immutable.Some("blank string"), + immutable.Some("hitchi"), + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/array_string_test.go b/tests/integration/mutation/update/field_kinds/array_string_test.go new file mode 100644 index 0000000000..74c9055ff2 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/array_string_test.go @@ -0,0 +1,291 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + "github.com/sourcenetwork/immutable" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithArrayOfStringsToNil(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": null + }`, + // This restriction should be removed when we can, it is here because of + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.GQLRequestMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": nil, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfStringsToNil_Errors(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with nil", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": null + }`, + // This is a bug, this test should be removed in + // https://github.com/sourcenetwork/defradb/issues/1842 + SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ + testUtils.CollectionNamedMutationType, + testUtils.CollectionSaveMutationType, + }), + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + ExpectedError: "EOF", + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfStringsToEmpty(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with empty", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": [] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": []string{}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfStringsToSameSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with same size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": ["zeroth", "the previous", "the first", "null string"] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": []string{"zeroth", "the previous", "the first", "null string"}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfStringsToSmallerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with smaller size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": ["", "the first"] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": []string{"", "the first"}, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithArrayOfStringsToLargerSize(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with string array, replace with larger size", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + preferredStrings: [String!] + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "preferredStrings": ["", "the previous", "the first", "empty string"] + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "preferredStrings": ["", "the previous", "the first", "empty string", "blank string", "hitchi"] + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + preferredStrings + } + } + `, + Results: []map[string]any{ + { + "preferredStrings": []string{ + "", + "the previous", + "the first", + "empty string", + "blank string", + "hitchi", + }, + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/field_kinds/date_time_test.go b/tests/integration/mutation/update/field_kinds/date_time_test.go new file mode 100644 index 0000000000..3a79a2c1e0 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/date_time_test.go @@ -0,0 +1,108 @@ +// Copyright 2023 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 field_kinds + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithDateTimeField(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update of date time field", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + created_at: DateTime + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "created_at": "2011-07-23T01:11:11.111Z" + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "created_at": "2021-07-23T02:22:22.222Z" + }`, + }, + testUtils.Request{ + Request: ` + query { + Users { + created_at + } + } + `, + Results: []map[string]any{ + { + "created_at": "2021-07-23T02:22:22.222Z", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithDateTimeField_MultipleDocs(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update of date time field, multiple docs", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + created_at: DateTime + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "created_at": "2011-07-23T01:11:11.111Z" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Fred", + "created_at": "2021-07-23T02:22:22.222Z" + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Users(data: "{\"created_at\": \"2031-07-23T03:23:23.333Z\"}") { + name + created_at + } + }`, + Results: []map[string]any{ + { + "name": "John", + "created_at": "2031-07-23T03:23:23.333Z", + }, + { + "name": "Fred", + "created_at": "2031-07-23T03:23:23.333Z", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/one_to_many/update/related_object_link_test.go b/tests/integration/mutation/update/field_kinds/one_to_many/simple_test.go similarity index 96% rename from tests/integration/mutation/one_to_many/update/related_object_link_test.go rename to tests/integration/mutation/update/field_kinds/one_to_many/simple_test.go index 5c9f235b1a..ef02f249d8 100644 --- a/tests/integration/mutation/one_to_many/update/related_object_link_test.go +++ b/tests/integration/mutation/update/field_kinds/one_to_many/simple_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package update +package one_to_many import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many" ) func TestMutationUpdateOneToMany_RelationIDToLinkFromSingleSide_Error(t *testing.T) { @@ -82,7 +81,7 @@ func TestMutationUpdateOneToMany_RelationIDToLinkFromSingleSide_Error(t *testing }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -175,7 +174,7 @@ func TestMutationUpdateOneToMany_InvalidRelationIDToLinkFromManySide(t *testing. }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToMany_RelationIDToLinkFromManySideWithWrongField_Error(t *testing.T) { @@ -242,7 +241,7 @@ func TestMutationUpdateOneToMany_RelationIDToLinkFromManySideWithWrongField_Erro }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToMany_RelationIDToLinkFromManySide(t *testing.T) { @@ -355,5 +354,5 @@ func TestMutationUpdateOneToMany_RelationIDToLinkFromManySide(t *testing.T) { }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/update/field_kinds/one_to_many/utils.go b/tests/integration/mutation/update/field_kinds/one_to_many/utils.go new file mode 100644 index 0000000000..21b9524567 --- /dev/null +++ b/tests/integration/mutation/update/field_kinds/one_to_many/utils.go @@ -0,0 +1,46 @@ +// Copyright 2023 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 one_to_many + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func executeTestCase(t *testing.T, test testUtils.TestCase) { + testUtils.ExecuteTestCase( + t, + testUtils.TestCase{ + Description: test.Description, + Actions: append( + []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author + } + + type Author { + name: String + age: Int + published: [Book] + } + `, + }, + }, + test.Actions..., + ), + }, + ) +} diff --git a/tests/integration/mutation/one_to_many/update/related_object_link_with_alias_test.go b/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go similarity index 97% rename from tests/integration/mutation/one_to_many/update/related_object_link_with_alias_test.go rename to tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go index f579796e96..a1f6c71ae7 100644 --- a/tests/integration/mutation/one_to_many/update/related_object_link_with_alias_test.go +++ b/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package update +package one_to_many import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many" ) func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_Error(t *testing.T) { @@ -82,7 +81,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_Error(t * }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } // Note: This test should probably not pass, as it contains a @@ -175,7 +174,7 @@ func TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide(t *t }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySideWithWrongField_Error(t *testing.T) { @@ -242,7 +241,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySideWithWrongFie }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySide(t *testing.T) { @@ -355,5 +354,5 @@ func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySide(t *testing. }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/simple/utils.go b/tests/integration/mutation/update/field_kinds/one_to_one/utils.go similarity index 66% rename from tests/integration/mutation/simple/utils.go rename to tests/integration/mutation/update/field_kinds/one_to_one/utils.go index c45c7340be..4b5d33f618 100644 --- a/tests/integration/mutation/simple/utils.go +++ b/tests/integration/mutation/update/field_kinds/one_to_one/utils.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package simple +package one_to_one import ( "testing" @@ -16,20 +16,7 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -var userSchema = (` - type User { - name: String - age: Int - points: Float - verified: Boolean - } -`) - -func ExecuteTestCase(t *testing.T, test testUtils.RequestTestCase) { - testUtils.ExecuteRequestTestCase(t, userSchema, []string{"User"}, test) -} - -func Execute(t *testing.T, test testUtils.TestCase) { +func executeTestCase(t *testing.T, test testUtils.TestCase) { testUtils.ExecuteTestCase( t, testUtils.TestCase{ @@ -37,7 +24,20 @@ func Execute(t *testing.T, test testUtils.TestCase) { Actions: append( []any{ testUtils.SchemaUpdate{ - Schema: userSchema, + Schema: ` + type Book { + name: String + rating: Float + author: Author + } + + type Author { + name: String + age: Int + verified: Boolean + published: Book @primary + } + `, }, }, test.Actions..., diff --git a/tests/integration/mutation/one_to_one/update/related_object_link_with_alias_test.go b/tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go similarity index 96% rename from tests/integration/mutation/one_to_one/update/related_object_link_with_alias_test.go rename to tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go index bb0a0cf776..26dad3912e 100644 --- a/tests/integration/mutation/one_to_one/update/related_object_link_with_alias_test.go +++ b/tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package update +package one_to_one import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one" ) func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromPrimarySide(t *testing.T) { @@ -82,7 +81,7 @@ func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromPrimarySide(t *testin }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySide(t *testing.T) { @@ -149,7 +148,7 @@ func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySide(t *test }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_AliasWithInvalidLengthRelationIDToLink_Error(t *testing.T) { @@ -205,7 +204,7 @@ func TestMutationUpdateOneToOne_AliasWithInvalidLengthRelationIDToLink_Error(t * }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_InvalidAliasRelationNameToLinkFromSecondarySide_Error(t *testing.T) { @@ -260,7 +259,7 @@ func TestMutationUpdateOneToOne_InvalidAliasRelationNameToLinkFromSecondarySide_ }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySideWithWrongField_Error(t *testing.T) { @@ -327,5 +326,5 @@ func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySideWithWron }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/one_to_one/update/related_object_link_test.go b/tests/integration/mutation/update/field_kinds/one_to_one/with_simple_test.go similarity index 68% rename from tests/integration/mutation/one_to_one/update/related_object_link_test.go rename to tests/integration/mutation/update/field_kinds/one_to_one/with_simple_test.go index 0fa361380f..7ad489c346 100644 --- a/tests/integration/mutation/one_to_one/update/related_object_link_test.go +++ b/tests/integration/mutation/update/field_kinds/one_to_one/with_simple_test.go @@ -8,26 +8,189 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Copyright 2023 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 update +package one_to_one import ( "fmt" "testing" testUtils "github.com/sourcenetwork/defradb/tests/integration" - fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one" ) +// Note: This test should probably not pass, as it contains a +// reference to a document that doesnt exist. +func TestMutationUpdateOneToOneNoChild(t *testing.T) { + test := testUtils.TestCase{ + Description: "One to one create mutation, from the wrong side", + Actions: []any{ + testUtils.CreateDoc{ + CollectionID: 1, + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Author(data: "{\"name\": \"John Grisham\",\"published_id\": \"bae-fd541c25-229e-5280-b44b-e5c2af3e374d\"}") { + name + } + }`, + Results: []map[string]any{ + { + "name": "John Grisham", + }, + }, + }, + }, + } + executeTestCase(t, test) +} + +func TestMutationUpdateOneToOne(t *testing.T) { + test := testUtils.TestCase{ + Description: "One to one update mutation", + Actions: []any{ + testUtils.CreateDoc{ + CollectionID: 0, + Doc: `{ + "name": "Painted House" + }`, + }, + testUtils.CreateDoc{ + CollectionID: 1, + Doc: `{ + "name": "John Grisham" + }`, + }, + testUtils.Request{ + Request: ` + mutation { + update_Author(data: "{\"name\": \"John Grisham\",\"published_id\": \"bae-3d236f89-6a31-5add-a36a-27971a2eac76\"}") { + name + } + }`, + Results: []map[string]any{ + { + "name": "John Grisham", + }, + }, + }, + testUtils.Request{ + Request: ` + query { + Book { + name + author { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "author": map[string]any{ + "name": "John Grisham", + }, + }, + }, + }, + testUtils.Request{ + Request: ` + query { + Author { + name + published { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "John Grisham", + "published": map[string]any{ + "name": "Painted House", + }, + }, + }, + }, + }, + } + + executeTestCase(t, test) +} + +func TestMutationUpdateOneToOneSecondarySide(t *testing.T) { + test := testUtils.TestCase{ + Description: "One to one create mutation, from the secondary side", + Actions: []any{ + testUtils.CreateDoc{ + CollectionID: 0, + Doc: `{ + "name": "Painted House" + }`, + }, + testUtils.CreateDoc{ + CollectionID: 1, + Doc: `{ + "name": "John Grisham" + }`, + }, + testUtils.Request{ + Request: ` + mutation { + update_Book(data: "{\"name\": \"Painted House\",\"author_id\": \"bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed\"}") { + name + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + }, + }, + }, + testUtils.Request{ + Request: ` + query { + Book { + name + author { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "author": map[string]any{ + "name": "John Grisham", + }, + }, + }, + }, + testUtils.Request{ + Request: ` + query { + Author { + name + published { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "John Grisham", + "published": map[string]any{ + "name": "Painted House", + }, + }, + }, + }, + }, + } + executeTestCase(t, test) +} + func TestMutationUpdateOneToOne_RelationIDToLinkFromPrimarySide(t *testing.T) { author1Key := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" author2Key := "bae-35953caf-4898-518d-9e6b-9ce6cd86ebe5" @@ -92,7 +255,7 @@ func TestMutationUpdateOneToOne_RelationIDToLinkFromPrimarySide(t *testing.T) { }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_RelationIDToLinkFromSecondarySide(t *testing.T) { @@ -159,7 +322,7 @@ func TestMutationUpdateOneToOne_RelationIDToLinkFromSecondarySide(t *testing.T) }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_InvalidLengthRelationIDToLink_Error(t *testing.T) { @@ -215,7 +378,7 @@ func TestMutationUpdateOneToOne_InvalidLengthRelationIDToLink_Error(t *testing.T }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_InvalidRelationIDToLinkFromSecondarySide_Error(t *testing.T) { @@ -270,7 +433,7 @@ func TestMutationUpdateOneToOne_InvalidRelationIDToLinkFromSecondarySide_Error(t }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } func TestMutationUpdateOneToOne_RelationIDToLinkFromSecondarySideWithWrongField_Error(t *testing.T) { @@ -337,5 +500,5 @@ func TestMutationUpdateOneToOne_RelationIDToLinkFromSecondarySideWithWrongField_ }, } - fixture.ExecuteTestCase(t, test) + executeTestCase(t, test) } diff --git a/tests/integration/mutation/simple/update/special/underscored_schema_test.go b/tests/integration/mutation/update/underscored_schema_test.go similarity index 54% rename from tests/integration/mutation/simple/update/special/underscored_schema_test.go rename to tests/integration/mutation/update/underscored_schema_test.go index ac137ea40d..7639458ae5 100644 --- a/tests/integration/mutation/simple/update/special/underscored_schema_test.go +++ b/tests/integration/mutation/update/underscored_schema_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package special +package update import ( "testing" @@ -16,39 +16,43 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -var myUserSchema = (` - type My_User { - name: String - } -`) - -func executeTestCase(t *testing.T, test testUtils.RequestTestCase) { - testUtils.ExecuteRequestTestCase(t, myUserSchema, []string{"My_User"}, test) -} - func TestMutationUpdateUnderscoredSchema(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple update of schema with underscored name", - Request: `mutation { - update_My_User(data: "{\"name\": \"Fred\"}") { - _key - name - } - }`, - Docs: map[int][]string{ - 0: { - `{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type My_User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ "name": "John" }`, }, - }, - Results: []map[string]any{ - { - "_key": "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad", - "name": "Fred", + testUtils.UpdateDoc{ + Doc: `{ + "name": "Fred" + }`, + }, + testUtils.Request{ + Request: ` + query { + My_User { + name + } + } + `, + Results: []map[string]any{ + { + "name": "Fred", + }, + }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } diff --git a/tests/integration/mutation/update/with_filter_test.go b/tests/integration/mutation/update/with_filter_test.go new file mode 100644 index 0000000000..1b47ee6840 --- /dev/null +++ b/tests/integration/mutation/update/with_filter_test.go @@ -0,0 +1,111 @@ +// Copyright 2023 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 update + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithBooleanFilter_ResultFilteredOut(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean equals filter", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + verified: Boolean + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "verified": true + }`, + }, + testUtils.Request{ + // The update will result in a record that no longer matches the filter + Request: `mutation { + update_Users(filter: {verified: {_eq: true}}, data: "{\"verified\":false}") { + _key + name + verified + } + }`, + // As the record no longer matches the filter it is not returned + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithBooleanFilter(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with boolean filter", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + verified: Boolean + points: Float + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "verified": true, + "points": 42.1 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Bob", + "verified": false, + "points": 66.6 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Fred", + "verified": true, + "points": 33 + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Users(filter: {verified: {_eq: true}}, data: "{\"points\": 59}") { + name + points + } + }`, + Results: []map[string]any{ + { + "name": "Fred", + "points": float64(59), + }, + { + "name": "John", + "points": float64(59), + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/with_id_test.go b/tests/integration/mutation/update/with_id_test.go new file mode 100644 index 0000000000..59b47bc234 --- /dev/null +++ b/tests/integration/mutation/update/with_id_test.go @@ -0,0 +1,97 @@ +// Copyright 2023 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 update + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithId(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with id", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + points: Float + } + `, + }, + testUtils.CreateDoc{ + // bae-cc36febf-4029-52b3-a876-c99c6293f588 + Doc: `{ + "name": "John", + "points": 42.1 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Bob", + "points": 66.6 + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Users(id: "bae-cc36febf-4029-52b3-a876-c99c6293f588", data: "{\"points\": 59}") { + name + points + } + }`, + Results: []map[string]any{ + { + "name": "John", + "points": float64(59), + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} + +func TestMutationUpdate_WithNonExistantId(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with non existant id", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + points: Float + } + `, + }, + testUtils.CreateDoc{ + // bae-cc36febf-4029-52b3-a876-c99c6293f588 + Doc: `{ + "name": "John", + "points": 42.1 + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Users(id: "bae-does-not-exist", data: "{\"points\": 59}") { + _key + name + points + } + }`, + Results: []map[string]any{}, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/mutation/update/with_ids_test.go b/tests/integration/mutation/update/with_ids_test.go new file mode 100644 index 0000000000..6e8ff33dab --- /dev/null +++ b/tests/integration/mutation/update/with_ids_test.go @@ -0,0 +1,76 @@ +// Copyright 2023 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 update + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestMutationUpdate_WithIds(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple update mutation with ids", + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + points: Float + } + `, + }, + testUtils.CreateDoc{ + // bae-cc36febf-4029-52b3-a876-c99c6293f588 + Doc: `{ + "name": "John", + "points": 42.1 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Bob", + "points": 66.6 + }`, + }, + testUtils.CreateDoc{ + // bae-4a99afc4-a70b-5702-9642-fc1eb9ffe901 + Doc: `{ + "name": "Fred", + "points": 33 + }`, + }, + testUtils.Request{ + Request: `mutation { + update_Users( + ids: ["bae-cc36febf-4029-52b3-a876-c99c6293f588", "bae-4a99afc4-a70b-5702-9642-fc1eb9ffe901"], + data: "{\"points\": 59}" + ) { + name + points + } + }`, + Results: []map[string]any{ + { + "name": "Fred", + "points": float64(59), + }, + { + "name": "John", + "points": float64(59), + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +} diff --git a/tests/integration/query/simple/with_deleted_field_test.go b/tests/integration/query/simple/with_deleted_field_test.go new file mode 100644 index 0000000000..182cce3280 --- /dev/null +++ b/tests/integration/query/simple/with_deleted_field_test.go @@ -0,0 +1,67 @@ +// 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 simple + +import ( + "testing" + + testUtils "github.com/sourcenetwork/defradb/tests/integration" +) + +func TestQuerySimple_WithDeletedField(t *testing.T) { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type User { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Andy" + }`, + }, + testUtils.DeleteDoc{ + DocID: 0, + }, + testUtils.DeleteDoc{ + DocID: 1, + }, + testUtils.Request{ + Request: `query { + User(showDeleted: true) { + _deleted + name + } + }`, + Results: []map[string]any{ + { + "_deleted": true, + "name": "Andy", + }, + { + "_deleted": true, + "name": "John", + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +}