Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate mutation-relation tests to new framework #1109

Merged
merged 12 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 106 additions & 118 deletions tests/integration/mutation/relation/create/with_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -87,7 +78,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
}
}
}`,

Results: []map[string]any{
{
"_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4",
Expand All @@ -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
Expand All @@ -120,7 +108,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
}
}
}`,

Results: []map[string]any{
{
"_key": "bae-0e7c3bb5-4917-5d98-9fcf-b9db369ea6e4",
Expand All @@ -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
Expand All @@ -245,7 +230,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
}
}
}`,

Results: []map[string]any{
{
"_key": "bae-5b16ccd7-9cae-5145-a56c-03cfe7787722",
Expand All @@ -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
Expand All @@ -272,7 +254,6 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
}
}
}`,

Results: []map[string]any{
{
"_key": "bae-edf7f0fc-f0fd-57e2-b695-569d87e1b251",
Expand All @@ -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)
}
Loading