use crate::core::config::e2e::{ArgMapping, CallConfig};
use crate::core::ir::{FieldDef, TypeDef, TypeRef};
use crate::e2e::fixture::Fixture;
fn arg_for(element_type: &str) -> ArgMapping {
ArgMapping {
name: "request".into(),
field: "input".into(),
arg_type: "json_object".into(),
optional: false,
owned: true,
element_type: Some(element_type.into()),
go_type: None,
vec_inner_is_ref: false,
trait_name: None,
}
}
fn self_referential_flatten_type() -> TypeDef {
TypeDef {
name: "SampleNode".into(),
fields: vec![FieldDef {
name: "wrapped".into(),
ty: TypeRef::Named("SampleNode".into()),
serde_flatten: true,
..Default::default()
}],
..Default::default()
}
}
#[test]
fn self_referential_flatten_field_terminates_and_reports_no_file_input() {
let fixture = Fixture {
input: serde_json::json!({}),
..Default::default()
};
let call = CallConfig {
args: vec![arg_for("SampleNode")],
..Default::default()
};
assert!(!super::fixture_uses_test_documents(
&fixture,
&call,
&[self_referential_flatten_type()],
&[]
));
}
fn leaf_type() -> TypeDef {
TypeDef {
name: "SampleLeaf".into(),
fields: vec![FieldDef {
name: "content".into(),
ty: TypeRef::Bytes,
..Default::default()
}],
..Default::default()
}
}
fn sibling_pair_type() -> TypeDef {
TypeDef {
name: "SampleRequest".into(),
fields: vec![
FieldDef {
name: "first".into(),
ty: TypeRef::Named("SampleLeaf".into()),
..Default::default()
},
FieldDef {
name: "second".into(),
ty: TypeRef::Named("SampleLeaf".into()),
..Default::default()
},
],
..Default::default()
}
}
#[test]
fn sibling_fields_of_the_same_named_type_both_get_checked() {
let fixture = Fixture {
input: serde_json::json!({
"first": {"content": "inline text"},
"second": {"content": "documents/sample.bin"}
}),
..Default::default()
};
let call = CallConfig {
args: vec![arg_for("SampleRequest")],
..Default::default()
};
assert!(super::fixture_uses_test_documents(
&fixture,
&call,
&[sibling_pair_type(), leaf_type()],
&[]
));
}