Skip to content

Commit

Permalink
add the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duguorong009 committed Jul 20, 2023
1 parent 054e25b commit cca2542
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,54 @@ mod tests {
"type": "obj"
}))));
}

#[pg_test]
fn test_jsonschema_validation_errors_none() {
let errors = crate::jsonschema_validation_errors(
Json(json!({ "maxLength": 4 })),
Json(json!("foo")),
);
assert!(errors.len() == 0);
}

#[pg_test]
fn test_jsonschema_validation_erros_one() {
let errors = crate::jsonschema_validation_errors(
Json(json!({ "maxLength": 4 })),
Json(json!("123456789")),
);
assert!(errors.len() == 1);
assert!(errors[0] == "\"123456789\" is longer than 4 characters".to_string());
}

#[pg_test]
fn test_jsonschema_validation_errors_multiple() {
let errors = crate::jsonschema_validation_errors(
Json(json!(
{
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"bar": {
"type": "number"
},
"baz": {
"type": "boolean"
},
"additionalProperties": false,
"required": ["foo", "bar", "baz"]
}
})),
Json(json!({"foo": 1, "bar": [], "bat": true})),
);
assert!(errors.len() == 1);
assert!(
errors[0]
== "[\"foo\",\"bar\",\"baz\"] is not of types \"boolean\", \"object\"".to_string()
);
}
}

#[cfg(test)]
Expand Down

0 comments on commit cca2542

Please sign in to comment.