Add basic enum introspection tests
Contrived for now - will need to expand on the graphql_enum! macro to include descriptions and deprecations
This commit is contained in:
parent
3b6c69ca1e
commit
8d9949e396
3 changed files with 73 additions and 0 deletions
70
src/executor_tests/introspection.rs
Normal file
70
src/executor_tests/introspection.rs
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use executor::FieldResult;
|
||||||
|
use value::Value;
|
||||||
|
use schema::model::RootNode;
|
||||||
|
|
||||||
|
enum Sample {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Root {}
|
||||||
|
|
||||||
|
graphql_enum!(Sample as "SampleEnum" {
|
||||||
|
Sample::One => "ONE",
|
||||||
|
Sample::Two => "TWO",
|
||||||
|
});
|
||||||
|
|
||||||
|
graphql_object!(Root: () as "Root" |&self| {
|
||||||
|
field sample_enum() -> FieldResult<Sample> {
|
||||||
|
Ok(Sample::One)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn enum_introspection() {
|
||||||
|
let doc = r#"
|
||||||
|
{
|
||||||
|
__type(name: "SampleEnum") {
|
||||||
|
enumValues {
|
||||||
|
name
|
||||||
|
description
|
||||||
|
isDeprecated
|
||||||
|
deprecationReason
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
let schema = RootNode::new(Root {}, ());
|
||||||
|
|
||||||
|
let (result, errs) = ::execute(doc, None, &schema, &HashMap::new(), &())
|
||||||
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
assert_eq!(errs, []);
|
||||||
|
|
||||||
|
println!("Result: {:?}", result);
|
||||||
|
|
||||||
|
let values = result
|
||||||
|
.as_object_value().expect("Result is not an object")
|
||||||
|
.get("__type").expect("__type field missing")
|
||||||
|
.as_object_value().expect("__type field not an object value")
|
||||||
|
.get("enumValues").expect("enumValues field missing")
|
||||||
|
.as_list_value().expect("enumValues not a list");
|
||||||
|
|
||||||
|
assert_eq!(values.len(), 2);
|
||||||
|
|
||||||
|
assert!(values.contains(&Value::object(vec![
|
||||||
|
("name", Value::string("ONE")),
|
||||||
|
("description", Value::null()),
|
||||||
|
("isDeprecated", Value::boolean(false)),
|
||||||
|
("deprecationReason", Value::null()),
|
||||||
|
].into_iter().collect())));
|
||||||
|
|
||||||
|
assert!(values.contains(&Value::object(vec![
|
||||||
|
("name", Value::string("TWO")),
|
||||||
|
("description", Value::null()),
|
||||||
|
("isDeprecated", Value::boolean(false)),
|
||||||
|
("deprecationReason", Value::null()),
|
||||||
|
].into_iter().collect())));
|
||||||
|
}
|
1
src/executor_tests/mod.rs
Normal file
1
src/executor_tests/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mod introspection;
|
|
@ -189,6 +189,8 @@ mod integrations;
|
||||||
#[cfg(all(test, not(feature="expose-test-schema")))] mod tests;
|
#[cfg(all(test, not(feature="expose-test-schema")))] mod tests;
|
||||||
#[cfg(feature="expose-test-schema")] pub mod tests;
|
#[cfg(feature="expose-test-schema")] pub mod tests;
|
||||||
|
|
||||||
|
#[cfg(test)] mod executor_tests;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use rustc_serialize::json::{ToJson, Json};
|
use rustc_serialize::json::{ToJson, Json};
|
||||||
|
|
Loading…
Reference in a new issue