use crate::{
interface::{
InterfaceDatabase, InterfaceModel,
tests::{media, tight},
},
model::{AliasOptions, DatabaseKind},
};
fn stored() -> InterfaceModel {
let mut model = media();
model.persist = vec![InterfaceDatabase {
kind: DatabaseKind::Sqlite,
aliases: AliasOptions::default(),
}];
model
}
fn emitted(model: &InterfaceModel) -> String {
tight(model.queries())
}
#[test]
fn the_derived_plural_is_the_base_and_a_degenerate_one_is_legal() {
let model = stored();
assert_eq!(model.published_plural(), "Media");
let emitted = emitted(&model);
assert!(emitted.contains("#[graphql(name=\"media\")]"), "{emitted}");
assert!(emitted.contains("\"MediaConnection\""), "{emitted}");
assert!(emitted.contains("\"MediaEdge\""), "{emitted}");
}
#[test]
fn the_declared_plural_moves_the_field_and_both_page_names() {
let mut model = stored();
model.plural = Some("corpora".to_owned());
let emitted = emitted(&model);
assert!(
emitted.contains("#[graphql(name=\"corpora\")]"),
"{emitted}"
);
assert!(emitted.contains("\"CorporaConnection\""), "{emitted}");
assert!(emitted.contains("\"CorporaEdge\""), "{emitted}");
assert!(!emitted.contains("\"MediaConnection\""), "{emitted}");
}
#[test]
fn the_word_is_raised_and_lowered_rather_than_re_cased() {
let mut model = stored();
model.plural = Some("Corpora".to_owned());
let emitted = emitted(&model);
assert!(
emitted.contains("#[graphql(name=\"corpora\")]"),
"{emitted}"
);
assert!(emitted.contains("\"CorporaConnection\""), "{emitted}");
}
#[test]
fn a_renamed_page_covers_the_plural_built_word_alone() {
let mut model = stored();
model.plural = Some("corpora".to_owned());
model.connection = Some("CorpusPage".to_owned());
let emitted = emitted(&model);
assert!(emitted.contains("\"CorpusPage\""), "{emitted}");
assert!(
emitted.contains("\"CorporaEdge\""),
"the edge stays on the tier below:\n{emitted}"
);
assert!(
emitted.contains("#[graphql(name=\"corpora\")]"),
"and so does the field:\n{emitted}"
);
}
#[test]
fn the_unit_carries_the_list_and_no_get_leg() {
let emitted = emitted(&stored());
assert!(emitted.contains("__async_graphql_media_list"), "{emitted}");
assert!(
!emitted.contains("#[graphql(name=\"id\")]"),
"an interface's address is a SUM, so there is no id a client could send:\n{emitted}"
);
assert!(
!emitted.contains("Lineage"),
"and no ancestry, an interface owning no table for one to be a path through:\n{emitted}"
);
}
#[test]
fn the_legs_arguments_are_the_relay_five_with_the_predicate_last() {
let emitted = emitted(&stored());
let at = |word: &str| {
emitted
.find(word)
.unwrap_or_else(|| panic!("{word} is written:\n{emitted}"))
};
assert!(at("#[graphql(name=\"orderBy\")]") < at("#[graphql(name=\"first\")]"));
assert!(at("#[graphql(name=\"first\")]") < at("#[graphql(name=\"last\")]"));
assert!(at("#[graphql(name=\"after\")]") < at("#[graphql(name=\"before\")]"));
assert!(at("#[graphql(name=\"before\")]") < at("#[graphql(name=\"where\")]"));
}
#[test]
fn the_face_rides_the_binding_gate_and_the_databases() {
let emitted = emitted(&stored());
assert!(
emitted.contains("::ingraph::__private::gate::if_async_graphql!"),
"{emitted}"
);
assert!(
emitted.contains("::ingraph::__private::gate::if_sqlite!"),
"{emitted}"
);
}