-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Relevant issue(s) Resolves #2243 ## Description This PR adds a JSON scalar type to the schema system ## Tasks - [x] I made sure the code is well commented, particularly hard-to-understand areas. - [x] I made sure the repository-held documentation is changed accordingly. - [x] I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in [tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)). - [x] I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ... ## How has this been tested? make test Specify the platform(s) on which this was tested: - MacOS --------- Co-authored-by: Shahzad Lone <[email protected]>
- Loading branch information
1 parent
59b4652
commit ba79b3b
Showing
8 changed files
with
284 additions
and
26 deletions.
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
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
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
137 changes: 137 additions & 0 deletions
137
tests/integration/schema/updates/add/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,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) | ||
} |