Skip to content

Commit

Permalink
Add tests for default properties
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jul 11, 2022
1 parent f62cb1f commit aad0efc
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/integration/query/inline_array/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ func TestQueryInlineArrayWithBooleans(t *testing.T) {

func TestQueryInlineArrayWithIntegers(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple inline array with no filter, default integer array",
Query: `query {
users {
Name
FavouriteIntegers
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John"
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "John",
"FavouriteIntegers": nil,
},
},
},
{
Description: "Simple inline array with no filter, nil integer array",
Query: `query {
Expand Down
58 changes: 58 additions & 0 deletions tests/integration/query/simple/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,61 @@ func TestQuerySimpleWithUndefinedField(t *testing.T) {

executeTestCase(t, test)
}

func TestQuerySimpleWithSomeDefaultValues(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with some default-value fields",
Query: `query {
users {
Name
Email
Age
HeightM
Verified
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John"
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Email": nil,
"Age": nil,
"HeightM": nil,
"Verified": nil,
},
},
}

executeTestCase(t, test)
}

// This test documents undesirable behaviour and should be altered
// with https://github.com/sourcenetwork/defradb/issues/610.
// A document with nil fields should be returned.
func TestQuerySimpleWithDefaultValue(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with default-value fields",
Query: `query {
users {
Name
Age
HeightM
Verified
}
}`,
Docs: map[int][]string{
0: {
`{ }`,
},
},
Results: []map[string]interface{}{},
}

executeTestCase(t, test)
}

0 comments on commit aad0efc

Please sign in to comment.