Add juniper_tests crate with integration tests

This commit is contained in:
theduke 2017-06-24 13:25:21 +02:00
parent d33db983de
commit 3b42c97a4a
3 changed files with 62 additions and 0 deletions

12
juniper_tests/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "juniper_tests"
version = "0.1.0"
[dependencies]
juniper = { path = "../juniper" }
juniper_codegen = { path = "../juniper_codegen" }
[[test]]
name = "integration_tests"
path = "src/lib.rs"
harness = true

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)
);
}

4
juniper_tests/src/lib.rs Normal file
View file

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