Skip to content

Commit

Permalink
Extract update action
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Mar 22, 2023
1 parent ed8d81e commit 5e2696e
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 275 deletions.
14 changes: 4 additions & 10 deletions tests/integration/query/commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestQueryCommits(t *testing.T) {
Description: "Simple all commits query",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits {
Expand Down Expand Up @@ -51,14 +51,8 @@ func TestQueryCommitsMultipleDocs(t *testing.T) {
Description: "Simple all commits query, multiple docs",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"Name": "Shahzad",
"Age": 28
}`,
},
createDoc("John", 21),
createDoc("Shahzad", 28),
testUtils.Request{
Request: `query {
commits {
Expand Down Expand Up @@ -97,7 +91,7 @@ func TestQueryCommitsWithSchemaVersionIdField(t *testing.T) {
Description: "Simple commits query yielding schemaVersionId",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits {
Expand Down
20 changes: 16 additions & 4 deletions tests/integration/query/commits/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package commits

import (
"strconv"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand All @@ -28,12 +30,22 @@ func updateUserCollectionSchema() testUtils.SchemaUpdate {
}
}

func createJohnDoc() testUtils.CreateDoc {
func createDoc(name string, age int) testUtils.CreateDoc {
return testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"Name": "John",
"Age": 21
}`,
"Name": "` + name + `",
"Age": ` + strconv.Itoa(age) + `
}`,
}
}

func updateAge(DocID int, age int) testUtils.UpdateDoc {
return testUtils.UpdateDoc{
CollectionID: 0,
DocID: DocID,
Doc: `{
"Age": ` + strconv.Itoa(age) + `
}`,
}
}
18 changes: 6 additions & 12 deletions tests/integration/query/commits/with_cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ func TestQueryCommitsWithCid(t *testing.T) {
Description: "Simple all commits query with cid",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
createDoc("John", 21),
updateAge(0, 22),
testUtils.Request{
Request: `query {
commits(
Expand All @@ -55,7 +49,7 @@ func TestQueryCommitsWithCidForFieldCommit(t *testing.T) {
Description: "Simple all commits query with cid",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(
Expand All @@ -81,7 +75,7 @@ func TestQueryCommitsWithInvalidCid(t *testing.T) {
Description: "query for a single block by invalid CID",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(cid: "fhbnjfahfhfhanfhga") {
Expand All @@ -103,7 +97,7 @@ func TestQueryCommitsWithInvalidShortCid(t *testing.T) {
Description: "query for a single block by invalid, short CID",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(cid: "bafybeidfhbnjfahfhfhanfhga") {
Expand All @@ -125,7 +119,7 @@ func TestQueryCommitsWithUnknownCid(t *testing.T) {
Description: "query for a single block by unknown CID",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(cid: "bafybeid57gpbwi4i6bg7g35hhhhhhhhhhhhhhhhhhhhhhhdoesnotexist") {
Expand Down
40 changes: 8 additions & 32 deletions tests/integration/query/commits/with_depth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestQueryCommitsWithDepth1(t *testing.T) {
Description: "Simple all commits query with depth 1",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(depth: 1) {
Expand Down Expand Up @@ -51,14 +51,8 @@ func TestQueryCommitsWithDepth1WithUpdate(t *testing.T) {
Description: "Simple all commits query with depth 1, and doc updates",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
createDoc("John", 21),
updateAge(0, 22),
testUtils.Request{
Request: `query {
commits(depth: 1) {
Expand Down Expand Up @@ -94,21 +88,9 @@ func TestQueryCommitsWithDepth2WithUpdate(t *testing.T) {
Description: "Simple all commits query with depth 2, and doc updates",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 23
}`,
},
createDoc("John", 21),
updateAge(0, 22),
updateAge(0, 23),
testUtils.Request{
Request: `query {
commits(depth: 2) {
Expand Down Expand Up @@ -155,14 +137,8 @@ func TestQueryCommitsWithDepth1AndMultipleDocs(t *testing.T) {
Description: "Simple all commits query with depth 1",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"Name": "Fred",
"Age": 25
}`,
},
createDoc("John", 21),
createDoc("Fred", 25),
testUtils.Request{
Request: `query {
commits(depth: 1) {
Expand Down
22 changes: 5 additions & 17 deletions tests/integration/query/commits/with_dockey_cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestQueryCommitsWithDockeyAndCidForDifferentDoc(t *testing.T) {
Description: "Simple all commits query with dockey and cid",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: ` {
commits(
Expand All @@ -44,14 +44,8 @@ func TestQueryCommitsWithDockeyAndCidForDifferentDocWithUpdate(t *testing.T) {
Description: "Simple all commits query with dockey and cid",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
createDoc("John", 21),
updateAge(0, 22),
testUtils.Request{
Request: ` {
commits(
Expand All @@ -74,14 +68,8 @@ func TestQueryCommitsWithDockeyAndCid(t *testing.T) {
Description: "Simple all commits query with dockey and cid",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
createDoc("John", 21),
updateAge(0, 22),
testUtils.Request{
Request: ` {
commits(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/query/commits/with_dockey_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestQueryCommitsWithDockeyAndLinkCount(t *testing.T) {
Description: "Simple latest commits query with dockey and link count",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/query/commits/with_dockey_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestQueryCommitsWithDockeyAndUnknownField(t *testing.T) {
Description: "Simple all commits query with dockey and unknown field",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "not a field") {
Expand All @@ -41,7 +41,7 @@ func TestQueryCommitsWithDockeyAndUnknownFieldId(t *testing.T) {
Description: "Simple all commits query with dockey and unknown field id",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "999999") {
Expand All @@ -63,7 +63,7 @@ func TestQueryCommitsWithDockeyAndField(t *testing.T) {
Description: "Simple all commits query with dockey and field",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "Age") {
Expand All @@ -85,7 +85,7 @@ func TestQueryCommitsWithDockeyAndFieldId(t *testing.T) {
Description: "Simple all commits query with dockey and field id",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "1") {
Expand All @@ -111,7 +111,7 @@ func TestQueryCommitsWithDockeyAndCompositeFieldId(t *testing.T) {
Description: "Simple all commits query with dockey and field id",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
createDoc("John", 21),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "C") {
Expand Down
26 changes: 4 additions & 22 deletions tests/integration/query/commits/with_dockey_limit_offset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@ func TestQueryCommitsWithDockeyAndLimitAndOffset(t *testing.T) {
Description: "Simple all commits query with dockey, limit and offset",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 23
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 24
}`,
},
createDoc("John", 21),
updateAge(0, 22),
updateAge(0, 23),
updateAge(0, 24),
testUtils.Request{
Request: ` {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", limit: 2, offset: 1) {
Expand Down
18 changes: 3 additions & 15 deletions tests/integration/query/commits/with_dockey_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,9 @@ func TestQueryCommitsWithDockeyAndLimit(t *testing.T) {
Description: "Simple all commits query with dockey and limit",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 23
}`,
},
createDoc("John", 21),
updateAge(0, 22),
updateAge(0, 23),
testUtils.Request{
Request: ` {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", limit: 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@ func TestQueryCommitsWithDockeyAndOrderAndLimitAndOffset(t *testing.T) {
Description: "Simple all commits query with dockey, order, limit and offset",
Actions: []any{
updateUserCollectionSchema(),
createJohnDoc(),
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 22
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 23
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"Age": 24
}`,
},
createDoc("John", 21),
updateAge(0, 22),
updateAge(0, 23),
updateAge(0, 24),
testUtils.Request{
Request: `query {
commits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", order: {height: ASC}, limit: 2, offset: 4) {
Expand Down
Loading

0 comments on commit 5e2696e

Please sign in to comment.