use crate::core::ir::ApiSurface;
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
use std::collections::{HashMap, HashSet};
#[path = "testdata/list_payload_shapes.rs"]
pub mod core_fixture;
pub fn api() -> ApiSurface {
let directory = tempfile::tempdir().unwrap();
let source = directory.path().join("lib.rs");
std::fs::write(&source, include_str!("testdata/list_payload_shapes.rs")).unwrap();
let api = crate::extract::extractor::extract(&[source.as_path()], "sample_core", "1.0.0", None).unwrap();
assert_eq!(api.enums.len(), 2);
assert_eq!(api.types.len(), 1);
api
}
pub fn resolver(text_projection: bool) -> FieldResolver {
let api = api();
let projected = if text_projection {
vec!["Body".into()]
} else {
Vec::new()
};
FieldResolver::new(
&HashMap::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
)
.with_ir_enum_map(
FieldResolver::ir_enum_fields(&api.types, &api.enums),
Some("Reply".into()),
)
.with_wasm_enum_representations(&api.enums)
.with_text_projected_enums(&projected)
}
pub fn assertions() -> Vec<Assertion> {
[
("count_equals", "content.parts", serde_json::json!(2)),
("equals", "content.parts[0].text", serde_json::json!("hello")),
("equals", "content.parts[1].value", serde_json::json!(" world")),
]
.into_iter()
.map(|(kind, field, value)| Assertion {
assertion_type: kind.into(),
field: Some(field.into()),
value: Some(value),
..Default::default()
})
.collect()
}
pub fn wire_value() -> serde_json::Value {
assert!(
serde_json::to_value(core_fixture::Body::Text("plain".into()))
.unwrap()
.is_string()
);
serde_json::to_value(core_fixture::reply()).unwrap()
}
pub fn nested_wire_value() -> serde_json::Value {
serde_json::to_value(core_fixture::Reply {
summary: "report".into(),
content: Some(core_fixture::Body::Parts(vec![core_fixture::Piece::Group {
items: vec!["left".into(), "right".into()],
}])),
})
.unwrap()
}