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

test: Expand commit query tests #541

Merged
merged 7 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
70 changes: 9 additions & 61 deletions tests/integration/query/all_commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,25 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQueryAllCommitsSingleDAG(t *testing.T) {
// This test is for documentation reasons only. This is not
// desired behaviour (should return all commits).
func TestQueryAllCommits(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple latest commits query",
Description: "Simple all commits query",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
allCommits {
cid
links {
cid
name
}
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Results: []map[string]interface{}{
{
"cid": "bafybeid57gpbwi4i6bg7g357vwwyzsmr4bjo22rmhoxrwqvdxlqxcgaqvu",
"links": []map[string]interface{}{
{
"cid": "bafybeidst2mzxhdoh4ayjdjoh4vibo7vwnuoxk3xgyk5mzmep55jklni2a",
"name": "Age",
},
{
"cid": "bafybeihhypcsqt7blkrqtcmpl43eo3yunrog5pchox5naji6hisdme4swm",
"name": "Name",
},
},
},
},
}

executeTestCase(t, test)
}

func TestQueryAllCommitsMultipleDAG(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple latest commits query",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
cid
height
}
`{
"Name": "John",
"Age": 21
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Updates: map[int][]string{
0: {
// update to change age to 22 on document 0
(`{"Age": 22}`),
},
},
Results: []map[string]interface{}{
{
"cid": "bafybeibrbfg35mwggcj4vnskak4qn45hp7fy5a4zp2n34sbq5vt5utr6pq",
"height": int64(2),
},
{
"cid": "bafybeid57gpbwi4i6bg7g357vwwyzsmr4bjo22rmhoxrwqvdxlqxcgaqvu",
"height": int64(1),
},
},
ExpectedError: "Field \"allCommits\" argument \"dockey\" of type \"ID!\" is required but not provided.",
}

executeTestCase(t, test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQueryAllCommitsSingleDAGWithLinkCount(t *testing.T) {
func TestQueryAllCommitsWithDockeyAndLinkCount(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple latest commits query",
Description: "Simple latest commits query with dockey and link count",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
cid
Expand All @@ -27,10 +27,11 @@ func TestQueryAllCommitsSingleDAGWithLinkCount(t *testing.T) {
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]interface{}{
{
Expand Down
113 changes: 113 additions & 0 deletions tests/integration/query/all_commits/with_dockey_field_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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 all_commits

import (
"testing"

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

func TestQueryAllCommitsWithDockeyAndUnknownField(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple all commits query with dockey and unknown field",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "not a field") {
cid
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]interface{}{},
}

executeTestCase(t, test)
}

func TestQueryAllCommitsWithDockeyAndUnknownFieldId(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple all commits query with dockey and unknown field id",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "999999") {
cid
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]interface{}{},
}

executeTestCase(t, test)
}

// This test is for documentation reasons only. This is not
// desired behaviour (should return all commits for dockey-field).
func TestQueryAllCommitsWithDockeyAndField(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple all commits query with dockey and field",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "Age") {
cid
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]interface{}{},
}

executeTestCase(t, test)
}

// This test is for documentation reasons only. This is not
// desired behaviour (users should not be specifying field ids).
func TestQueryAllCommitsWithDockeyAndFieldId(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple all commits query with dockey and field id",
Query: `query {
allCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f", field: "1") {
cid
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]interface{}{
{
"cid": "bafybeidst2mzxhdoh4ayjdjoh4vibo7vwnuoxk3xgyk5mzmep55jklni2a",
},
},
}

executeTestCase(t, test)
}
Loading