use crate::{
interface::{
InterfaceDatabase, default_output_name,
tests::{media, tight},
},
model::{AliasOptions, DatabaseKind},
};
fn emitted(model: &crate::interface::InterfaceModel) -> String {
tight(model.sdl_face())
}
fn stored() -> crate::interface::InterfaceModel {
let mut model = media();
model.persist = vec![InterfaceDatabase {
kind: DatabaseKind::Sqlite,
aliases: AliasOptions::default(),
}];
model
}
#[test]
fn the_output_sum_is_published_as_an_interface() {
let model = stored();
let emitted = emitted(&model);
let name = default_output_name(&model.name);
assert!(
emitted.contains(&format!(
"impl::ingraph::__private::async_graphql::InterfaceTypefor{name}"
)),
"{emitted}"
);
assert!(
emitted.contains("registry::MetaTypeId::Interface"),
"{emitted}"
);
assert!(emitted.contains("MetaType::Interface"), "{emitted}");
assert!(
emitted.contains("Cow::Borrowed(\"Media\")"),
"the published name is the interface's own:\n{emitted}"
);
}
#[test]
fn every_member_is_told_it_implements_the_interface() {
let emitted = emitted(&stored());
assert_eq!(
emitted.matches("Registry::add_implements").count(),
2,
"one per member:\n{emitted}"
);
assert_eq!(
emitted.matches("IndexSet::insert").count(),
2,
"and one possible type per member:\n{emitted}"
);
assert!(
emitted.contains("<Videoas::ingraph::__private::transform::Transformer>::Graphql"),
"the member's OUTPUT is reached as a family projection, never as a name this crate \
builds:\n{emitted}"
);
}
#[test]
fn the_typename_is_delegated_per_arm() {
let emitted = emitted(&stored());
assert!(emitted.contains("fnintrospection_type_name"), "{emitted}");
assert_eq!(
emitted
.matches("OutputType::introspection_type_name(__ingraph_member)")
.count(),
2,
"one arm per member, each answering with that member's own published name:\n{emitted}"
);
}
#[test]
fn no_discriminant_field_is_published() {
let emitted = emitted(&stored());
assert!(!emitted.contains("String::from(\"kind\")"), "{emitted}");
}
#[test]
fn the_published_fields_are_the_stored_contract() {
let emitted = emitted(&stored());
assert!(emitted.contains("String::from(\"title\")"), "{emitted}");
assert!(emitted.contains("String::from(\"mask\")"), "{emitted}");
assert!(
emitted.contains("ToGraphqlOutput>::Output<'static>"),
"the field's TYPE is the member's own crossing:\n{emitted}"
);
assert!(
!emitted.contains("String::from(\"displayLabel\")"),
"the COMPUTED tier is not on a member's object, so an interface declaring it would promise an \
`implements` no member satisfies:\n{emitted}"
);
}
#[test]
fn the_container_delegates_to_the_member_that_answered() {
let emitted = emitted(&stored());
assert_eq!(
emitted
.matches("ContainerType::collect_all_fields(__ingraph_member")
.count(),
2,
"{emitted}"
);
assert_eq!(
emitted
.matches("ContainerType::resolve_field(__ingraph_member")
.count(),
2,
"{emitted}"
);
}
#[test]
fn the_face_is_gated_and_conditional() {
assert!(
emitted(&stored()).contains("::ingraph::__private::gate::if_async_graphql!"),
"the face names async-graphql at every line",
);
let mut bare = media();
bare.persist = Vec::new();
for field in &mut bare.fields {
field.pins = Vec::new();
}
assert!(emitted(&bare).is_empty());
}