Skip to content

Commit

Permalink
test(i): Add view of view tests (sourcenetwork#2220)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves sourcenetwork#2218

## Description

This works, but was previously untested.
  • Loading branch information
AndrewSisley authored and shahzadlone committed Jan 20, 2024
1 parent e5ae553 commit bc045fc
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/integration/view/one_to_many/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,100 @@ func TestView_OneToManyMultipleViewsWithEmbeddedSchema(t *testing.T) {
func TestView_OneToManyWithDoubleSidedRelation_Errors(t *testing.T) {
test := testUtils.TestCase{
Description: "One to many view",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Author {
name: String
books: [Book]
}
type Book {
name: String
author: Author
}
`,
},
testUtils.CreateView{
Query: `
Author {
name
books {
name
}
}
`,
SDL: `
type AuthorView {
name: String
books: [BookView]
}
interface BookView {
name: String
}
`,
},
testUtils.CreateView{
Query: `
AuthorView {
name
books {
name
}
}
`,
SDL: `
type AuthorViewView {
name: String
books: [BookViewView]
}
interface BookViewView {
name: String
}
`,
},
// bae-ef9cd756-08e1-5f23-abeb-7b3e6351a68d
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "Harper Lee"
}`,
},
testUtils.CreateDoc{
CollectionID: 1,
Doc: `{
"name": "To Kill a Mockingbird",
"author_id": "bae-ef9cd756-08e1-5f23-abeb-7b3e6351a68d"
}`,
},
testUtils.Request{
Request: `query {
AuthorViewView {
name
books {
name
}
}
}`,
Results: []map[string]any{
{
"name": "Harper Lee",
"books": []map[string]any{
{
"name": "To Kill a Mockingbird",
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestView_OneToManyViewOfView(t *testing.T) {
test := testUtils.TestCase{
Description: "One to many view of view",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
Expand Down
60 changes: 60 additions & 0 deletions tests/integration/view/simple/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,63 @@ func TestView_SimpleWithExtraFieldInViewQuery(t *testing.T) {

testUtils.ExecuteTestCase(t, test)
}

func TestView_SimpleViewOfView(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple view of view",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String
}
`,
},
testUtils.CreateView{
Query: `
User {
name
}
`,
SDL: `
type UserView {
name: String
}
`,
},
testUtils.CreateView{
Query: `
UserView {
name
}
`,
SDL: `
type UserViewView {
name: String
}
`,
},
testUtils.CreateDoc{
Doc: `{
"name": "John"
}`,
},
testUtils.Request{
Request: `
query {
UserViewView {
name
}
}
`,
Results: []map[string]any{
{
"name": "John",
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

0 comments on commit bc045fc

Please sign in to comment.