Add nesting layer for codegen tests and add test for input_object derive

This commit is contained in:
theduke 2017-06-24 20:20:54 +02:00
parent 1312c6a026
commit 03f694fff6
5 changed files with 71 additions and 46 deletions

View file

@ -5,6 +5,7 @@ version = "0.1.0"
[dependencies]
juniper = { path = "../juniper" }
juniper_codegen = { path = "../juniper_codegen" }
serde_json = { version = "^1.0.2" }
[[test]]
name = "integration_tests"

View file

@ -0,0 +1,46 @@
use std::collections::HashMap;
use juniper::{self, InputValue, ToInputValue, GraphQLType, FromInputValue};
#[derive(GraphQLEnum, Debug, PartialEq)]
#[graphql(name="Some", description="enum descr")]
enum SomeEnum {
Regular,
#[graphql(
name="FULL",
description="field descr",
deprecated="depr"
)]
Full,
}
#[test]
fn test_derived_enum() {
// Ensure that rename works.
assert_eq!(SomeEnum::name(), Some("Some"));
// Ensure validity of meta info.
let mut registry = juniper::Registry::new(HashMap::new());
let meta = SomeEnum::meta(&mut registry);
// Test Regular variant.
assert_eq!(
SomeEnum::Regular.to(),
InputValue::String("Regular".into())
);
assert_eq!(
FromInputValue::from(&InputValue::String("Regular".into())),
Some(SomeEnum::Regular)
);
// Test FULL variant.
assert_eq!(
SomeEnum::Full.to(),
InputValue::String("FULL".into())
);
assert_eq!(
FromInputValue::from(&InputValue::String("FULL".into())),
Some(SomeEnum::Full)
);
}

View file

@ -0,0 +1,21 @@
use juniper::{self, InputValue, ToInputValue, GraphQLType, FromInputValue};
#[derive(GraphQLInputObject, Debug, PartialEq)]
#[graphql(name="MyInput")]
struct Input {
regular_field: String,
#[graphql(name="haha", default="33")]
c: i32,
}
#[test]
fn test_derived_input_object() {
assert_eq!(Input::name(), Some("MyInput"));
let obj = Input {
regular_field: "a".to_string(),
c: 33,
};
let restored: Input = FromInputValue::from(&obj.to()).unwrap();
assert_eq!(obj, restored);
}

View file

@ -1,46 +1,2 @@
use std::collections::HashMap;
use juniper::{self, InputValue, ToInputValue, GraphQLType, FromInputValue};
#[derive(GraphQLEnum, Debug, PartialEq)]
#[graphql(name="Some", description="enum descr")]
enum SomeEnum {
Regular,
#[graphql(
name="FULL",
description="field descr",
deprecated="depr"
)]
Full,
}
#[test]
fn test_derived_enum() {
// Ensure that rename works.
assert_eq!(SomeEnum::name(), Some("Some"));
// Ensure validity of meta info.
let mut registry = juniper::Registry::new(HashMap::new());
let meta = SomeEnum::meta(&mut registry);
// Test Regular variant.
assert_eq!(
SomeEnum::Regular.to(),
InputValue::String("Regular".into())
);
assert_eq!(
FromInputValue::from(&InputValue::String("Regular".into())),
Some(SomeEnum::Regular)
);
// Test FULL variant.
assert_eq!(
SomeEnum::Full.to(),
InputValue::String("FULL".into())
);
assert_eq!(
FromInputValue::from(&InputValue::String("FULL".into())),
Some(SomeEnum::Full)
);
}
mod enums;
mod input_objects;

View file

@ -1,4 +1,5 @@
#[macro_use] extern crate juniper;
#[macro_use] extern crate juniper_codegen;
#[macro_use] extern crate serde_json;
mod codegen;