use crate::core::config::e2e::{ArgMapping, CallConfig};
use crate::core::ir::{EnumDef, EnumVariant, FieldDef, TypeDef, TypeRef};
use crate::e2e::fixture::Fixture;
fn object_arg() -> ArgMapping {
ArgMapping {
name: "request".into(),
field: "input".into(),
arg_type: "json_object".into(),
optional: false,
owned: true,
element_type: Some("SampleRequest".into()),
go_type: None,
vec_inner_is_ref: false,
trait_name: None,
}
}
fn request_with_event_type() -> TypeDef {
TypeDef {
name: "SampleRequest".into(),
fields: vec![FieldDef {
name: "event".into(),
ty: TypeRef::Named("SampleEvent".into()),
..Default::default()
}],
..Default::default()
}
}
fn event_enum_with_field(field: FieldDef) -> EnumDef {
EnumDef {
name: "SampleEvent".into(),
serde_rename_all: Some("SCREAMING_SNAKE_CASE".into()),
variants: vec![EnumVariant {
name: "Uploaded".into(),
fields: vec![field],
..Default::default()
}],
..Default::default()
}
}
fn call_with_input(input: serde_json::Value) -> (Fixture, CallConfig) {
let fixture = Fixture {
input,
..Default::default()
};
let call = CallConfig {
args: vec![object_arg()],
..Default::default()
};
(fixture, call)
}
#[test]
fn enum_rename_all_is_not_applied_to_field_names() {
let field = FieldDef {
name: "file_name".into(),
ty: TypeRef::Bytes,
..Default::default()
};
let (fixture, call) = call_with_input(serde_json::json!({
"event": {"UPLOADED": {"FILE_NAME": "documents/sample.bin"}}
}));
assert!(!super::fixture_uses_test_documents(
&fixture,
&call,
&[request_with_event_type()],
&[event_enum_with_field(field)]
));
}
#[test]
fn explicit_field_serde_rename_still_resolves_inside_a_struct_variant() {
let field = FieldDef {
name: "file_name".into(),
ty: TypeRef::Bytes,
serde_rename: Some("attachment".into()),
..Default::default()
};
let (fixture, call) = call_with_input(serde_json::json!({
"event": {"UPLOADED": {"attachment": "documents/sample.bin"}}
}));
assert!(super::fixture_uses_test_documents(
&fixture,
&call,
&[request_with_event_type()],
&[event_enum_with_field(field)]
));
}