added type family support
This commit is contained in:
52
src/tests.rs
52
src/tests.rs
@ -1036,4 +1036,54 @@ fn test_validate_nullable_union() {
|
||||
let result_invalid = validate_json_schema("nullable_union_test.request", jsonb(invalid_string));
|
||||
assert_failure(&result_invalid);
|
||||
assert_has_error(&result_invalid, "TYPE_MISMATCH", "/nullable_prop");
|
||||
}
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
fn test_validate_type_hierarchy() {
|
||||
clear_json_schemas();
|
||||
let cache_result = hierarchy_schemas();
|
||||
assert_success(&cache_result);
|
||||
|
||||
// 1. Test success case: validating a derived type (person) against a base schema (organization)
|
||||
let person_instance = json!({
|
||||
"id": "person-id",
|
||||
"type": "person",
|
||||
"name": "person-name",
|
||||
"password": "person-password",
|
||||
"first_name": "person-first-name"
|
||||
});
|
||||
let result_success = validate_json_schema("organization", jsonb(person_instance.clone()));
|
||||
assert_success(&result_success);
|
||||
|
||||
// 2. Test success case: validating a base type (organization) against its own schema
|
||||
let org_instance = json!({
|
||||
"id": "org-id",
|
||||
"type": "organization",
|
||||
"name": "org-name"
|
||||
});
|
||||
let result_org_success = validate_json_schema("organization", jsonb(org_instance));
|
||||
assert_success(&result_org_success);
|
||||
|
||||
// 3. Test failure case: validating an ancestor type (entity) against a derived schema (organization)
|
||||
let entity_instance = json!({
|
||||
"id": "entity-id",
|
||||
"type": "entity"
|
||||
});
|
||||
let result_fail_ancestor = validate_json_schema("organization", jsonb(entity_instance));
|
||||
assert_failure(&result_fail_ancestor);
|
||||
assert_has_error(&result_fail_ancestor, "ENUM_VIOLATED", "/type");
|
||||
|
||||
// 4. Test failure case: validating a completely unrelated type
|
||||
let unrelated_instance = json!({
|
||||
"id": "job-id",
|
||||
"type": "job",
|
||||
"name": "job-name"
|
||||
});
|
||||
let result_fail_unrelated = validate_json_schema("organization", jsonb(unrelated_instance));
|
||||
assert_failure(&result_fail_unrelated);
|
||||
assert_has_error(&result_fail_unrelated, "ENUM_VIOLATED", "/type");
|
||||
|
||||
// 5. Test that the punc using the schema also works
|
||||
let punc_success = validate_json_schema("test_org_punc.request", jsonb(person_instance.clone()));
|
||||
assert_success(&punc_success);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user