use crate::{
interface::{
InterfaceDatabase, InterfaceField, Tier, default_filter_name, default_order_by_name,
tests::{ident, media, tight},
},
model::{AliasOptions, DatabaseKind},
};
fn emitted(model: &crate::interface::InterfaceModel) -> String {
tight(model.input_faces())
}
fn stored() -> crate::interface::InterfaceModel {
let mut model = media();
model.persist = vec![InterfaceDatabase {
kind: DatabaseKind::Sqlite,
aliases: AliasOptions::default(),
}];
model
}
#[test]
fn the_filter_and_the_order_by_wear_the_units_input_faces() {
let model = stored();
let emitted = emitted(&model);
let (filter, order) = (
default_filter_name(&model.name),
default_order_by_name(&model.name),
);
assert!(
emitted.contains(&format!(
"impl::ingraph::__private::async_graphql::InputTypefor{filter}"
)),
"{emitted}"
);
assert!(
emitted.contains(&format!(
"impl::ingraph::__private::async_graphql::InputObjectTypefor{filter}"
)),
"{emitted}"
);
assert!(
emitted.contains(&format!(
"impl::ingraph::__private::async_graphql::InputTypefor{order}"
)),
"{emitted}"
);
assert!(
emitted.contains(&format!(
"impl::ingraph::__private::async_graphql::OneofObjectTypefor{order}"
)),
"the ORDER is a @oneOf object, so *exactly one term* is the validator's rule:\n{emitted}"
);
}
#[test]
fn the_published_names_are_the_design_vocabulary() {
let emitted = emitted(&stored());
assert!(emitted.contains("\"MediaFilter\""), "{emitted}");
assert!(emitted.contains("\"MediaOrderBy\""), "{emitted}");
}
#[test]
fn the_faces_publish_the_contracts_own_fields_and_no_members() {
let mut model = stored();
model.fields.push(InterfaceField {
name: ident("frame_rate"),
ty: syn::parse_quote!(u32),
tier: Tier::Stored,
marker: None,
copy: true,
pins: Vec::new(),
wire: None,
operands: Vec::new(),
members: vec![crate::interface::MemberColumn {
variant: ident("Audio"),
column: ident("sample_rate"),
}],
});
let emitted = emitted(&model);
assert!(emitted.contains("\"frameRate\""), "{emitted}");
assert!(
!emitted.contains("\"sampleRate\""),
"a member's own spelling of a shared column is never a client's word:\n{emitted}"
);
assert!(
!emitted.contains("\"flags\""),
"nor is `Audio`'s name for the `mask` column:\n{emitted}"
);
}
#[test]
fn a_computed_field_reaches_neither_input_face() {
let emitted = emitted(&stored());
assert!(emitted.contains("\"title\""), "{emitted}");
assert!(
!emitted.contains("\"displayLabel\""),
"the computed tier is statically absent, and the absence IS the refusal:\n{emitted}"
);
assert!(!emitted.contains("\"checksum\""), "{emitted}");
}
#[test]
fn the_input_faces_ride_the_binding_gate() {
let emitted = emitted(&stored());
assert!(
emitted.contains("::ingraph::__private::gate::if_async_graphql!"),
"{emitted}"
);
}