From f87435b96c43d18b9fef9bc837c4fb23a345ce1c Mon Sep 17 00:00:00 2001 From: Sunli Date: Fri, 4 Sep 2020 14:14:48 +0800 Subject: [PATCH] Add test for multiple flatten attribute of InputObject. --- tests/input_object.rs | 64 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/input_object.rs b/tests/input_object.rs index 3120af09..5d3baf92 100644 --- a/tests/input_object.rs +++ b/tests/input_object.rs @@ -105,7 +105,7 @@ pub async fn test_inputobject_derive_and_item_attributes() { } #[async_std::test] -pub async fn test_inputobject_flatten() { +pub async fn test_inputobject_flatten_recursive() { #[derive(GQLInputObject, Debug, Eq, PartialEq)] struct A { a: i32, @@ -231,3 +231,65 @@ pub async fn test_inputobject_flatten() { }) ); } + +#[async_std::test] +pub async fn test_inputobject_flatten_multiple() { + #[derive(GQLInputObject, Debug, Eq, PartialEq)] + struct A { + a: i32, + } + + #[derive(GQLInputObject, Debug, Eq, PartialEq)] + struct B { + b: i32, + } + + #[derive(GQLInputObject, Debug, Eq, PartialEq)] + struct C { + c: i32, + } + + #[derive(GQLInputObject, Debug, Eq, PartialEq)] + struct ABC { + #[field(flatten)] + a: A, + + #[field(flatten)] + b: B, + + #[field(flatten)] + c: C, + } + + assert_eq!( + ABC::parse(Some( + serde_json::json!({ + "a": 10, + "b": 20, + "c": 30, + }) + .into() + )) + .unwrap(), + ABC { + a: A { a: 10 }, + b: B { b: 20 }, + c: C { c: 30 } + } + ); + + assert_eq!( + ABC { + a: A { a: 10 }, + b: B { b: 20 }, + c: C { c: 30 } + } + .to_value(), + serde_json::json!({ + "a": 10, + "b": 20, + "c": 30, + }) + .into() + ); +}