Skip to content

Commit

Permalink
Add bug bash tests for gql fragments
Browse files Browse the repository at this point in the history
This was the only way I could think of that might break the feature that wasn't already covered, and it worked fine :)
  • Loading branch information
AndrewSisley committed Oct 15, 2024
1 parent 4990ff5 commit a013bc7
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions tests/integration/query/one_to_one/with_fragments_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright 2024 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 (
"testing"

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

func TestQueryOneToOne_WithFragment(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Book {
name: String
author: Author
}
type Author {
name: String
age: Int
}
`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "John Grisham",
"age": 65
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
DocMap: map[string]any{
"name": "Painted House",
"author": testUtils.NewDocIndex(1, 0),
},
},
testUtils.Request{
Request: `query {
Book {
name
...BookAuthorInfo
}
}
fragment BookAuthorInfo on Book {
author {
name
age
}
}`,
Results: map[string]any{
"Book": []map[string]any{
{
"name": "Painted House",
"author": map[string]any{
"name": "John Grisham",
"age": int64(65),
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestQueryOneToOne_WithFragmentWithObjectWithFragment(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Book {
name: String
author: Author
}
type Author {
name: String
age: Int
}
`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "John Grisham",
"age": 65
}`,
},
testUtils.CreateDoc{
CollectionID: 0,
DocMap: map[string]any{
"name": "Painted House",
"author": testUtils.NewDocIndex(1, 0),
},
},
testUtils.Request{
Request: `query {
Book {
name
...BookAuthorInfo
}
}
fragment BookAuthorInfo on Book {
author {
...BookInfo
}
}
fragment BookInfo on Author {
name
age
}`,
Results: map[string]any{
"Book": []map[string]any{
{
"name": "Painted House",
"author": map[string]any{
"name": "John Grisham",
"age": int64(65),
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

0 comments on commit a013bc7

Please sign in to comment.