-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
tests/integration/mutation/create/field_kinds/field_kind_json_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// 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 field_kinds | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestMutationCreate_WithJSONFieldGivenValidJSON_NoError(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Create mutation with JSON field given a valid JSON string.", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
custom: JSON | ||
} | ||
`, | ||
}, | ||
testUtils.Request{ | ||
Request: `mutation { | ||
create_Users(input: {name: "John", custom: "{\"tree\": \"maple\", \"age\": 250}"}) { | ||
_docID | ||
name | ||
custom | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"_docID": "bae-b2dff82c-ab26-5d06-a29a-02aa4807dde2", | ||
"custom": "{\"tree\":\"maple\",\"age\":250}", | ||
"name": "John", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreate_WithJSONFieldGivenInvalidJSON_Error(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Create mutation with JSON field given a valid JSON string.", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
custom: JSON | ||
} | ||
`, | ||
}, | ||
testUtils.Request{ | ||
Request: `mutation { | ||
create_Users(input: {name: "John", custom: "{\"tree\": \"maple, \"age\": 250}"}) { | ||
_docID | ||
name | ||
custom | ||
} | ||
}`, | ||
ExpectedError: `Argument "input" has invalid value {name: "John", custom: "{\"tree\": \"maple, \"age\": 250}"}. | ||
In field "custom": Expected type "JSON", found "{\"tree\": \"maple, \"age\": 250}".`, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreate_WithJSONFieldGivenSimpleString_Error(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Create mutation with JSON field given a valid JSON string.", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
custom: JSON | ||
} | ||
`, | ||
}, | ||
testUtils.Request{ | ||
Request: `mutation { | ||
create_Users(input: {name: "John", custom: "blah"}) { | ||
_docID | ||
name | ||
custom | ||
} | ||
}`, | ||
ExpectedError: `Argument "input" has invalid value {name: "John", custom: "blah"}. | ||
In field "custom": Expected type "JSON", found "blah".`, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |