From 7853ade0fcb58a821c90632757e903b55f6774d3 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 5 Jan 2024 11:06:04 -0800 Subject: [PATCH] delete relation alias tests --- .../one_to_many/with_alias_test.go | 253 ------------ .../field_kinds/one_to_one/with_alias_test.go | 210 ---------- .../one_to_many/with_alias_test.go | 391 ------------------ .../field_kinds/one_to_one/with_alias_test.go | 245 ----------- 4 files changed, 1099 deletions(-) delete mode 100644 tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go delete mode 100644 tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go delete mode 100644 tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go delete mode 100644 tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go diff --git a/tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go b/tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go deleted file mode 100644 index 3b37756b6c..0000000000 --- a/tests/integration/mutation/create/field_kinds/one_to_many/with_alias_test.go +++ /dev/null @@ -1,253 +0,0 @@ -// 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 ( - "fmt" - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestMutationCreateOneToMany_AliasedRelationNameWithInvalidField_Error(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to many create mutation, with an invalid field, with alias.", - Actions: []any{ - testUtils.CreateDoc{ - Doc: `{ - "notName": "Painted House", - "author": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - ExpectedError: "The given field does not exist. Name: notName", - }, - }, - } - executeTestCase(t, test) -} - -func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationSingleSide_NoIDFieldError(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to many create mutation, non-existing id, from the single side, no id relation field, with alias.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "John Grisham", - "published": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - ExpectedError: "The given field does not exist. Name: published", - }, - }, - } - executeTestCase(t, test) -} - -// Note: This test should probably not pass, as it contains a -// reference to a document that doesnt exist. -func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationManySide_CreatedDoc(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to many create mutation, non-existing id, from the many side, with alias", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House", - "author": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - }, - testUtils.Request{ - Request: `query { - Book { - name - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - }, - }, - }, - }, - } - executeTestCase(t, test) -} -func TestMutationCreateOneToMany_AliasedRelationNameInvalidIDManySide_CreatedDoc(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to many create mutation, invalid id, from the many side, with alias", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House", - "author": "ValueDoesntMatter" - }`, - }, - testUtils.Request{ - Request: `query { - Book { - name - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - }, - }, - }, - }, - } - executeTestCase(t, test) -} - -func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testing.T) { - authorID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - - test := testUtils.TestCase{ - Description: "One to many create mutation using relation id from many side, with alias.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - authorID, - ), - }, - testUtils.Request{ - Request: `query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": []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", - }, - }, - }, - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDocID(t *testing.T) { - // These IDs MUST be shared by both tests below. - authorID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - bookID := "bae-22e0a1c2-d12b-5bfd-b039-0cf72f963991" - - nonAliasedTest := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from single side (wrong)", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author_id": "%s" - }`, - authorID, - ), - }, - testUtils.Request{ - Request: `query { - Book { - _docID - } - }`, - Results: []map[string]any{ - { - "_docID": bookID, // Must be same as below. - }, - }, - }, - }, - } - executeTestCase(t, nonAliasedTest) - - // Check that `bookID` is same in both above and the alised version below. - // Note: Everything should be same, only diff should be the use of alias. - - aliasedTest := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from single side (wrong)", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - authorID, - ), - }, - testUtils.Request{ - Request: `query { - Book { - _docID - } - }`, - Results: []map[string]any{ - { - "_docID": bookID, // Must be same as below. - }, - }, - }, - }, - } - executeTestCase(t, aliasedTest) -} diff --git a/tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go b/tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go deleted file mode 100644 index da8bd1b7b0..0000000000 --- a/tests/integration/mutation/create/field_kinds/one_to_one/with_alias_test.go +++ /dev/null @@ -1,210 +0,0 @@ -// 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 - -import ( - "fmt" - "testing" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestMutationCreateOneToOne_UseAliasWithInvalidField_Error(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one create mutation, alias relation, with an invalid field.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "notName": "John Grisham", - "published": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - ExpectedError: "The given field does not exist. Name: notName", - }, - }, - } - executeTestCase(t, test) -} - -// Note: This test should probably not pass, as it contains a -// reference to a document that doesnt exist. -func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationPrimarySide_CreatedDoc(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one create mutation, alias relation, from the wrong side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham", - "published": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - }, - testUtils.Request{ - Request: `query { - Author { - name - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - }, - }, - }, - }, - } - executeTestCase(t, test) -} - -func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Error(t *testing.T) { - test := testUtils.TestCase{ - Description: "One to one create mutation, alias relation, from the secondary side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House", - "author": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" - }`, - ExpectedError: "no document for the given ID exists", - }, - }, - } - executeTestCase(t, test) -} - -func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySide(t *testing.T) { - bookID := "bae-3d236f89-6a31-5add-a36a-27971a2eac76" - - test := testUtils.TestCase{ - Description: "One to one create mutation with an alias relation.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 0, - Doc: `{ - "name": "Painted House" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: fmt.Sprintf( - `{ - "name": "John Grisham", - "published": "%s" - }`, - bookID, - ), - }, - 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 TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondarySide(t *testing.T) { - authorID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - - test := testUtils.TestCase{ - Description: "One to one create mutation from secondary side with alias relation.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - authorID, - ), - }, - testUtils.Request{ - Request: `query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": 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", - }, - }, - }, - }, - }, - } - - executeTestCase(t, test) -} diff --git a/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go b/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go deleted file mode 100644 index 6f4373976f..0000000000 --- a/tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go +++ /dev/null @@ -1,391 +0,0 @@ -// 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 ( - "fmt" - "testing" - - "github.com/sourcenetwork/immutable" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_Collection(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - bookID := "bae-22e0a1c2-d12b-5bfd-b039-0cf72f963991" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from single side (wrong)", - // This restiction is temporary due to an inconsitent error message, see - // TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_GQL - // and https://github.com/sourcenetwork/defradb/issues/1854 for more info. - SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ - testUtils.CollectionNamedMutationType, - testUtils.CollectionSaveMutationType, - }), - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 1, - DocID: 1, - // NOTE: There is no `published` on book. - Doc: fmt.Sprintf( - `{ - "published": "%s" - }`, - bookID, - ), - ExpectedError: "The given field or alias to field does not exist. Name: published", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_GQL(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - bookID := "bae-22e0a1c2-d12b-5bfd-b039-0cf72f963991" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from single side (wrong)", - // This restiction is temporary due to an inconsitent error message, see - // TestMutationUpdateOneToMany_AliasRelationNameToLinkFromSingleSide_Collection - // and https://github.com/sourcenetwork/defradb/issues/1854 for more info. - SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ - testUtils.GQLRequestMutationType, - }), - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 1, - DocID: 1, - // NOTE: There is no `published` on book. - Doc: fmt.Sprintf( - `{ - "published": "%s" - }`, - bookID, - ), - ExpectedError: "The given field or alias to field does not exist. Name: published", - }, - }, - } - - executeTestCase(t, test) -} - -// Note: This test should probably not pass, as it contains a -// reference to a document that doesnt exist. -func TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_GQL(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - invalidAuthorID := "bae-35953ca-518d-9e6b-9ce6cd00eff5" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from many side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - invalidAuthorID, - ), - }, - testUtils.Request{ - Request: `query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": []map[string]any{}, - }, - }, - }, - testUtils.Request{ - Request: `query { - Book { - name - author { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - "author": nil, // Linked to incorrect id - }, - }, - }, - }, - } - - executeTestCase(t, test) -} - -// Note: This test should probably not pass, as it contains a -// reference to a document that doesnt exist. -func TestMutationUpdateOneToMany_InvalidAliasRelationNameToLinkFromManySide_Collection(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - invalidAuthorID := "bae-35953ca-518d-9e6b-9ce6cd00eff5" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from many side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - invalidAuthorID, - ), - }, - testUtils.Request{ - Request: `query { - Book { - name - author { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "Painted House", - "author": nil, - }, - }, - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySideWithWrongField_Error(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - author2ID := "bae-35953caf-4898-518d-9e6b-9ce6cd86ebe5" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from many side, with a wrong field.", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "notName": "Unpainted Condo", - "author": "%s" - }`, - author2ID, - ), - ExpectedError: "The given field does not exist. Name: notName", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToMany_AliasRelationNameToLinkFromManySide(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - author2ID := "bae-35953caf-4898-518d-9e6b-9ce6cd86ebe5" - - test := testUtils.TestCase{ - Description: "One to many update mutation using relation alias name from many side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - author2ID, - ), - }, - testUtils.Request{ - Request: `query { - Author { - name - published { - name - } - } - }`, - Results: []map[string]any{ - { - "name": "John Grisham", - "published": []map[string]any{}, - }, - { - "name": "New Shahzad", - "published": []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": "New Shahzad", - }, - }, - }, - }, - }, - } - - executeTestCase(t, test) -} diff --git a/tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go b/tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go deleted file mode 100644 index 67d5f0b38c..0000000000 --- a/tests/integration/mutation/update/field_kinds/one_to_one/with_alias_test.go +++ /dev/null @@ -1,245 +0,0 @@ -// 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 - -import ( - "fmt" - "testing" - - "github.com/sourcenetwork/immutable" - - testUtils "github.com/sourcenetwork/defradb/tests/integration" -) - -func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromPrimarySide(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - bookID := "bae-22e0a1c2-d12b-5bfd-b039-0cf72f963991" - - test := testUtils.TestCase{ - Description: "One to one update mutation using alias relation id from single side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 1, - DocID: 1, - Doc: fmt.Sprintf( - `{ - "published": "%s" - }`, - bookID, - ), - ExpectedError: "target document is already linked to another document.", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySide(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - author2ID := "bae-35953caf-4898-518d-9e6b-9ce6cd86ebe5" - - test := testUtils.TestCase{ - Description: "One to one update mutation using alias relation id from secondary side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - author2ID, - ), - ExpectedError: "target document is already linked to another document.", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToOne_AliasWithInvalidLengthRelationIDToLink_Error(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - invalidLenSubID := "35953ca-518d-9e6b-9ce6cd00eff5" - invalidAuthorID := "bae-" + invalidLenSubID - - test := testUtils.TestCase{ - Description: "One to one update mutation using invalid alias relation id", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - invalidAuthorID, - ), - ExpectedError: "uuid: incorrect UUID length 30 in string \"" + invalidLenSubID + "\"", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToOne_InvalidAliasRelationNameToLinkFromSecondarySide_Error(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - invalidAuthorID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ee" - - test := testUtils.TestCase{ - Description: "One to one update mutation using alias relation id from secondary side", - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "author": "%s" - }`, - invalidAuthorID, - ), - ExpectedError: "no document for the given ID exists", - }, - }, - } - - executeTestCase(t, test) -} - -func TestMutationUpdateOneToOne_AliasRelationNameToLinkFromSecondarySideWithWrongField_Error(t *testing.T) { - author1ID := "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" - author2ID := "bae-35953caf-4898-518d-9e6b-9ce6cd86ebe5" - - test := testUtils.TestCase{ - Description: "One to one update mutation using relation alias name from secondary side, with a wrong field.", - // This restiction is temporary due to a bug in the collection api, see - // https://github.com/sourcenetwork/defradb/issues/1703 for more info. - SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ - testUtils.GQLRequestMutationType, - }), - Actions: []any{ - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "John Grisham" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 1, - Doc: `{ - "name": "New Shahzad" - }`, - }, - testUtils.CreateDoc{ - CollectionID: 0, - Doc: fmt.Sprintf( - `{ - "name": "Painted House", - "author": "%s" - }`, - author1ID, - ), - }, - testUtils.UpdateDoc{ - CollectionID: 0, - DocID: 0, - Doc: fmt.Sprintf( - `{ - "notName": "Unpainted Condo", - "author": "%s" - }`, - author2ID, - ), - ExpectedError: "The given field does not exist. Name: notName", - }, - }, - } - - executeTestCase(t, test) -}