Skip to content

Commit

Permalink
add json scalar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdf committed Jan 23, 2024
1 parent feb6d04 commit 5ec6148
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 24 deletions.
24 changes: 0 additions & 24 deletions tests/integration/schema/updates/add/field/kind/invalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,6 @@ func TestSchemaUpdatesAddFieldKind9(t *testing.T) {
testUtils.ExecuteTestCase(t, test)
}

func TestSchemaUpdatesAddFieldKind14(t *testing.T) {
test := testUtils.TestCase{
Description: "Test schema update, add field with kind deprecated (14)",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
}
`,
},
testUtils.SchemaPatch{
Patch: `
[
{ "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo", "Kind": 14} }
]
`,
ExpectedError: "no type found for given name. Type: 14",
},
},
}
testUtils.ExecuteTestCase(t, test)
}

func TestSchemaUpdatesAddFieldKind15(t *testing.T) {
test := testUtils.TestCase{
Description: "Test schema update, add field with kind deprecated (15)",
Expand Down
137 changes: 137 additions & 0 deletions tests/integration/schema/updates/add/field/kind/json_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright 2023 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 kind

import (
"testing"

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

func TestSchemaUpdatesAddFieldKindJSON(t *testing.T) {
test := testUtils.TestCase{
Description: "Test schema update, add field with kind json (14)",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
}
`,
},
testUtils.SchemaPatch{
Patch: `
[
{ "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo", "Kind": 14} }
]
`,
},
testUtils.Request{
Request: `query {
Users {
name
foo
}
}`,
Results: []map[string]any{},
},
},
}
testUtils.ExecuteTestCase(t, test)
}

func TestSchemaUpdatesAddFieldKindJSONWithCreate(t *testing.T) {
test := testUtils.TestCase{
Description: "Test schema update, add field with kind json (14) with create",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
}
`,
},
testUtils.SchemaPatch{
Patch: `
[
{ "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo", "Kind": 14} }
]
`,
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"foo": "{}"
}`,
},
testUtils.Request{
Request: `query {
Users {
name
foo
}
}`,
Results: []map[string]any{
{
"name": "John",
"foo": "{}",
},
},
},
},
}
testUtils.ExecuteTestCase(t, test)
}

func TestSchemaUpdatesAddFieldKindJSONSubstitutionWithCreate(t *testing.T) {
test := testUtils.TestCase{
Description: "Test schema update, add field with kind json substitution with create",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
name: String
}
`,
},
testUtils.SchemaPatch{
Patch: `
[
{ "op": "add", "path": "/Users/Fields/-", "value": {"Name": "foo", "Kind": "JSON"} }
]
`,
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"foo": "{}"
}`,
},
testUtils.Request{
Request: `query {
Users {
name
foo
}
}`,
Results: []map[string]any{
{
"name": "John",
"foo": "{}",
},
},
},
},
}
testUtils.ExecuteTestCase(t, test)
}

0 comments on commit 5ec6148

Please sign in to comment.