From b92b6bc45c0aa597796be26ba2271c086d3d7852 Mon Sep 17 00:00:00 2001 From: AndrewSisley Date: Thu, 16 Feb 2023 12:46:09 -0500 Subject: [PATCH] refactor: Migrate mutation-relation tests to new framework (#1109) * Add mutation/relation wrapper * Migrate TestTransactionalCreationAndLinkingOfRelationalDocumentsForward * Migrate TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward * Migrate TestRelationalDeletionOfADocumentUsingSingleKey_Success * Migrate TestTxnDeletionOfRelatedDocFromPrimarySideForwardDirection * Migrate TestTxnDeletionOfRelatedDocFromPrimarySideBackwardDirection * Migrate TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection * Migrate TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection * Migrate TestTxnDeletionOfRelatedDocFromNonPrimarySideForwardDirection * Migrate TestTxnDeletionOfRelatedDocFromNonPrimarySideBackwardDirection * Remove legacy framework wrapper --- .../mutation/relation/create/with_txn_test.go | 224 ++++----- .../relation/delete/single_id_test.go | 171 +++---- .../mutation/relation/delete/with_txn_test.go | 456 +++++++++--------- tests/integration/mutation/relation/utils.go | 59 ++- 4 files changed, 448 insertions(+), 462 deletions(-) diff --git a/tests/integration/mutation/relation/create/with_txn_test.go b/tests/integration/mutation/relation/create/with_txn_test.go index 28396e586e..0df209301e 100644 --- a/tests/integration/mutation/relation/create/with_txn_test.go +++ b/tests/integration/mutation/relation/create/with_txn_test.go @@ -19,64 +19,55 @@ import ( ) func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Create relational documents, and check the links in forward direction.", - - Docs: map[int][]string{ - // publishers - 2: { + Actions: []any{ + testUtils.CreateDoc{ + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, - + }, + testUtils.CreateDoc{ + CollectionID: 2, // "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - `{ + Doc: `{ "name": "Online", "address": "Manning Early Access Program (MEAP)" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ // Create books related to publishers, and ensure they are correctly linked (in and out of transactions). - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + TransactionID: 0, Request: `mutation { create_book(data: "{\"name\": \"Book By Website\",\"rating\": 4.0, \"publisher_id\": \"bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4\"}") { _key } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, - - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + TransactionID: 1, Request: `mutation { create_book(data: "{\"name\": \"Book By Online\",\"rating\": 4.0, \"publisher_id\": \"bae-8a381044-9206-51e7-8bc8-dc683d5f2523\"}") { _key } }`, - Results: []map[string]any{ { "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", }, }, }, - // Assert publisher -> books direction within transaction 0. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + TransactionID: 0, Request: `query { publisher { _key @@ -87,7 +78,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing. } } }`, - Results: []map[string]any{ { "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", @@ -105,11 +95,9 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing. }, }, }, - // Assert publisher -> books direction within transaction 1. - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + TransactionID: 1, Request: `query { publisher { _key @@ -120,7 +108,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing. } } }`, - Results: []map[string]any{ { "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", @@ -138,103 +125,101 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing. }, }, }, - }, - - // Assert books -> publisher direction outside the transactions. - Request: `query { - book { - _key - name - publisher { - _key - name - } - } - }`, - - Results: []map[string]any{ - { - "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - "name": "Book By Website", - "publisher": map[string]any{ - "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - "name": "Website", - }, + // Commit the transactions before querying the end result + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.TransactionCommit{ + TransactionID: 1, }, + testUtils.Request{ + // Assert books -> publisher direction outside the transactions. + Request: `query { + book { + _key + name + publisher { + _key + name + } + } + }`, + Results: []map[string]any{ + { + "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", + "name": "Book By Website", + "publisher": map[string]any{ + "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", + "name": "Website", + }, + }, - { - "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", - "name": "Book By Online", - "publisher": map[string]any{ - "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - "name": "Online", + { + "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", + "name": "Book By Online", + "publisher": map[string]any{ + "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", + "name": "Online", + }, + }, }, }, }, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Create relational documents, and check the links in backward direction.", - - Docs: map[int][]string{ - // publishers - 2: { + Actions: []any{ + testUtils.CreateDoc{ + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, - + }, + testUtils.CreateDoc{ + CollectionID: 2, // "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - `{ + Doc: `{ "name": "Online", "address": "Manning Early Access Program (MEAP)" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ // Create books related to publishers, and ensure they are correctly linked (in and out of transactions). - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + TransactionID: 0, Request: `mutation { create_book(data: "{\"name\": \"Book By Website\",\"rating\": 4.0, \"publisher_id\": \"bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4\"}") { _key } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, - - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + TransactionID: 1, Request: `mutation { create_book(data: "{\"name\": \"Book By Online\",\"rating\": 4.0, \"publisher_id\": \"bae-8a381044-9206-51e7-8bc8-dc683d5f2523\"}") { _key } }`, - Results: []map[string]any{ { "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", }, }, }, - // Assert publisher -> books direction within transaction 0. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + TransactionID: 0, Request: `query { book { _key @@ -245,7 +230,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing } } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", @@ -257,11 +241,9 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing }, }, }, - // Assert publisher -> books direction within transaction 1. - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + TransactionID: 1, Request: `query { book { _key @@ -272,7 +254,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing } } }`, - Results: []map[string]any{ { "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", @@ -284,40 +265,47 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing }, }, }, - }, - - // Assert publishers -> books direction outside the transactions. - Request: `query { - publisher { - _key - name - published { - _key - name - } - } - }`, - - Results: []map[string]any{ - { - "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - "name": "Website", - "published": map[string]any{ - "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - "name": "Book By Website", - }, + // Commit the transactions before querying the end result + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.TransactionCommit{ + TransactionID: 1, }, + testUtils.Request{ + // Assert publishers -> books direction outside the transactions. + Request: `query { + publisher { + _key + name + published { + _key + name + } + } + }`, + Results: []map[string]any{ + { + "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", + "name": "Website", + "published": map[string]any{ + "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", + "name": "Book By Website", + }, + }, - { - "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - "name": "Online", - "published": map[string]any{ - "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", - "name": "Book By Online", + { + "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", + "name": "Online", + "published": map[string]any{ + "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", + "name": "Book By Online", + }, + }, }, }, }, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } diff --git a/tests/integration/mutation/relation/delete/single_id_test.go b/tests/integration/mutation/relation/delete/single_id_test.go index 8a4224194e..3806785b60 100644 --- a/tests/integration/mutation/relation/delete/single_id_test.go +++ b/tests/integration/mutation/relation/delete/single_id_test.go @@ -18,161 +18,170 @@ import ( ) func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) { - tests := []testUtils.RequestTestCase{ - + tests := []testUtils.TestCase{ { Description: "Relational delete mutation where one element exists.", - Request: `mutation { - delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { - _key - } - }`, - Docs: map[int][]string{ - // Books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // Books + CollectionID: 0, // bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 - `{ + Doc: `{ "name": "100 Go Mistakes to Avoid.", "rating": 4.8, "publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" }`, }, - // Authors - 1: { + testUtils.CreateDoc{ + // Authors + CollectionID: 1, // bae-2f80f359-535d-508e-ba58-088a309ce3c3 - `{ + Doc: `{ "name": "Teiva Harsanyi", "age": 48, "verified": true, "wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" }`, }, - // Publishers - 2: { + testUtils.CreateDoc{ + // Publishers + CollectionID: 2, // bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 - `{ + Doc: `{ "name": "Manning Early Access Program (MEAP)", "address": "Online" }`, }, - }, - Results: []map[string]any{ - { - "_key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + testUtils.Request{ + Request: `mutation { + delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + }, + }, }, }, - ExpectedError: "", }, { Description: "Relational delete mutation with an aliased _key name.", - Request: `mutation { - delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { - AliasOfKey: _key - } - }`, - Docs: map[int][]string{ - // Books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // Books + CollectionID: 0, // bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 - `{ + Doc: `{ "name": "100 Go Mistakes to Avoid.", "rating": 4.8, "publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" }`, }, - // Authors - 1: { + testUtils.CreateDoc{ + // Authors + CollectionID: 1, // bae-2f80f359-535d-508e-ba58-088a309ce3c3 - `{ + Doc: `{ "name": "Teiva Harsanyi", "age": 48, "verified": true, "wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" }`, }, - // Publishers - 2: { + testUtils.CreateDoc{ + // Publishers + CollectionID: 2, // bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 - `{ + Doc: `{ "name": "Manning Early Access Program (MEAP)", "address": "Online" }`, }, - }, - Results: []map[string]any{ - { - "AliasOfKey": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + testUtils.Request{ + Request: `mutation { + delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { + AliasOfKey: _key + } + }`, + Results: []map[string]any{ + { + "AliasOfKey": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + }, + }, }, }, - ExpectedError: "", }, { Description: "Relational Delete of an updated document and an aliased _key name.", - Request: `mutation { - delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { - Key: _key - } - }`, - - Docs: map[int][]string{ - // Books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // Books + CollectionID: 0, // bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 - `{ + Doc: `{ "name": "100 Go Mistakes to Avoid.", "rating": 4.8, "publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" }`, }, - - // Authors - 1: { + testUtils.CreateDoc{ + // Authors + CollectionID: 1, // bae-2f80f359-535d-508e-ba58-088a309ce3c3 - `{ - "name": "Teiva Harsanyi", - "age": 48, - "verified": true, - "wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" + Doc: `{ + "name": "Teiva Harsanyi", + "age": 48, + "verified": true, + "wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" }`, }, - - // Publishers - 2: { + testUtils.CreateDoc{ + // Publishers + CollectionID: 2, // bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 - `{ + Doc: `{ "name": "Manning Early Access Program (MEAP)", "address": "Online" }`, - + }, + testUtils.CreateDoc{ + // Publishers + CollectionID: 2, // bae-5c599633-d6d2-56ae-b3f0-1b65b4cee9fe - `{ + Doc: `{ "name": "Manning Publications", "address": "Website" }`, }, - }, - Updates: map[int]map[int][]string{ - 1: { - 0: { - `{ - "name": "Teiva Harsanyiiiiiiiiii", - "age": 49 - }`, - }, + testUtils.UpdateDoc{ + CollectionID: 1, + DocID: 0, + Doc: `{ + "name": "Teiva Harsanyiiiiiiiiii", + "age": 49 + }`, }, - }, - Results: []map[string]any{ - { - "Key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + testUtils.Request{ + Request: `mutation { + delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { + Key: _key + } + }`, + Results: []map[string]any{ + { + "Key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", + }, + }, }, }, - ExpectedError: "", }, } for _, test := range tests { - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } } diff --git a/tests/integration/mutation/relation/delete/with_txn_test.go b/tests/integration/mutation/relation/delete/with_txn_test.go index 76fa954337..07091e6197 100644 --- a/tests/integration/mutation/relation/delete/with_txn_test.go +++ b/tests/integration/mutation/relation/delete/with_txn_test.go @@ -19,182 +19,171 @@ import ( ) func TestTxnDeletionOfRelatedDocFromPrimarySideForwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Delete related doc with transaction from primary side (forward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - `{ + Doc: `{ "name": "Book By Website", "rating": 4.0, "publisher_id": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a liniked book that exists. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a linked book that exists. + TransactionID: 0, Request: `mutation { delete_book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") { _key } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, - }, - - // Assert after transaction(s) have been commited, to ensure the book was deleted. - Request: `query { - publisher { - _key - name - published { - _key - name - } - } - }`, - - Results: []map[string]any{ - { - "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - "name": "Website", - "published": nil, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited, to ensure the book was deleted. + Request: `query { + publisher { + _key + name + published { + _key + name + } + } + }`, + Results: []map[string]any{ + { + "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", + "name": "Website", + "published": nil, + }, + }, }, }, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestTxnDeletionOfRelatedDocFromPrimarySideBackwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Delete related doc with transaction from primary side (backward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - `{ + Doc: `{ "name": "Book By Website", "rating": 4.0, "publisher_id": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a liniked book that exists. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a linked book that exists. + TransactionID: 0, Request: `mutation { delete_book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") { _key } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited, to ensure the book was deleted. + Request: `query { + book { + _key + name + publisher { + _key + name + } + } + }`, + Results: []map[string]any{}, + }, }, - - // Assert after transaction(s) have been commited, to ensure the book was deleted. - Request: `query { - book { - _key - name - publisher { - _key - name - } - } - }`, - - Results: []map[string]any{}, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Transaction can read a record that was deleted in a non-commited transaction (forward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - `{ + Doc: `{ "name": "Book By Website", "rating": 4.0, "publisher_id": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a liniked book that exists in transaction 0. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a linked book that exists. + TransactionID: 0, Request: `mutation { delete_book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") { _key } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, - - // Read the book (forward) that was deleted (in the non-commited transaction) in another transaction. - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + // Read the book (forward) that was deleted (in the non-commited transaction) in another transaction. + TransactionID: 1, Request: `query { publisher { _key @@ -205,7 +194,6 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *tes } } }`, - Results: []map[string]any{ { "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", @@ -217,79 +205,75 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnForwardDirection(t *tes }, }, }, - }, - - // Assert after transaction(s) have been commited, to ensure the book was deleted. - Request: `query { - publisher { - _key - name - published { - _key - name - } - } - }`, - - Results: []map[string]any{ - { - "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - "name": "Website", - "published": nil, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited, to ensure the book was deleted. + Request: `query { + publisher { + _key + name + published { + _key + name + } + } + }`, + Results: []map[string]any{ + { + "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", + "name": "Website", + "published": nil, + }, + }, }, }, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Transaction can read a record that was deleted in a non-commited transaction (backward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", - `{ + Doc: `{ "name": "Book By Website", "rating": 4.0, "publisher_id": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4", - `{ + Doc: `{ "name": "Website", "address": "Manning Publications" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a liniked book that exists in transaction 0. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a linked book that exists in transaction 0. + TransactionID: 0, Request: `mutation { - delete_book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") { - _key - } + delete_book(id: "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722") { + _key + } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", }, }, }, - - // Read the book (backwards) that was deleted (in the non-commited transaction) in another transaction. - { - TransactionId: 1, - + testUtils.TransactionRequest2{ + // Read the book (backwards) that was deleted (in the non-commited transaction) in another transaction. + TransactionID: 1, Request: `query { book { _key @@ -300,7 +284,6 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *te } } }`, - Results: []map[string]any{ { "_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722", @@ -312,154 +295,153 @@ func TestATxnCanReadARecordThatIsDeletedInANonCommitedTxnBackwardDirection(t *te }, }, }, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited, to ensure the book was deleted. + Request: `query { + book { + _key + name + publisher { + _key + name + } + } + }`, + Results: []map[string]any{}, + }, }, - - // Assert after transaction(s) have been commited, to ensure the book was deleted. - Request: `query { - book { - _key - name - publisher { - _key - name - } - } - }`, - - Results: []map[string]any{}, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestTxnDeletionOfRelatedDocFromNonPrimarySideForwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Delete related doc with transaction from non-primary side (forward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", - `{ + Doc: `{ "name": "Book By Online", "rating": 4.0, "publisher_id": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - `{ + Doc: `{ "name": "Online", "address": "Manning Early Access Program (MEAP)" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a publisher and outside the transaction ensure it's linked - // book gets correctly unlinked too. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a publisher and outside the transaction ensure it's linked + // book gets correctly unlinked too. + TransactionID: 0, Request: `mutation { - delete_publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") { - _key - } - }`, - + delete_publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") { + _key + } + }`, Results: []map[string]any{ { "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", }, }, }, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited. + Request: `query { + publisher { + _key + name + published { + _key + name + } + } + }`, + Results: []map[string]any{}, + }, }, - - // Assert after transaction(s) have been commited. - Request: `query { - publisher { - _key - name - published { - _key - name - } - } - }`, - - Results: []map[string]any{}, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } func TestTxnDeletionOfRelatedDocFromNonPrimarySideBackwardDirection(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Delete related doc with transaction from non-primary side (backward).", - - Docs: map[int][]string{ - // books - 0: { + Actions: []any{ + testUtils.CreateDoc{ + // books + CollectionID: 0, // "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", - `{ + Doc: `{ "name": "Book By Online", "rating": 4.0, "publisher_id": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523" }`, }, - - // publishers - 2: { + testUtils.CreateDoc{ + // publishers + CollectionID: 2, // "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", - `{ + Doc: `{ "name": "Online", "address": "Manning Early Access Program (MEAP)" }`, }, - }, - - TransactionalRequests: []testUtils.TransactionRequest{ - // Delete a publisher and outside the transaction ensure it's linked - // book gets correctly unlinked too. - { - TransactionId: 0, - + testUtils.TransactionRequest2{ + // Delete a publisher and outside the transaction ensure it's linked + // book gets correctly unlinked too. + TransactionID: 0, Request: `mutation { - delete_publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") { + delete_publisher(id: "bae-8a381044-9206-51e7-8bc8-dc683d5f2523") { + _key + } + }`, + Results: []map[string]any{ + { + "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", + }, + }, + }, + testUtils.TransactionCommit{ + TransactionID: 0, + }, + testUtils.Request{ + // Assert after transaction(s) have been commited. + Request: `query { + book { _key + name + publisher { + _key + name + } } }`, - Results: []map[string]any{ { - "_key": "bae-8a381044-9206-51e7-8bc8-dc683d5f2523", + "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", + "name": "Book By Online", + "publisher": nil, }, }, }, }, - - // Assert after transaction(s) have been commited. - Request: `query { - book { - _key - name - publisher { - _key - name - } - } - }`, - - Results: []map[string]any{ - { - "_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251", - "name": "Book By Online", - "publisher": nil, - }, - }, } - relationTests.ExecuteTestCase(t, test) + relationTests.Execute(t, test) } diff --git a/tests/integration/mutation/relation/utils.go b/tests/integration/mutation/relation/utils.go index a7d4749eb1..0961b3be71 100644 --- a/tests/integration/mutation/relation/utils.go +++ b/tests/integration/mutation/relation/utils.go @@ -16,33 +16,40 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -var bookAuthorPublisherGQLSchema = (` - 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 - } -`) - -func ExecuteTestCase(t *testing.T, test testUtils.RequestTestCase) { - testUtils.ExecuteRequestTestCase( +func Execute(t *testing.T, test testUtils.TestCase) { + testUtils.ExecuteTestCase( t, - bookAuthorPublisherGQLSchema, []string{"book", "author", "publisher"}, - test, + 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..., + ), + }, ) }