use quote::ToTokens as _;
fn leg() -> String {
let model = crate::tests::queried();
let graphql = model.graphql.as_ref().expect("the fixture has a wire face");
let database = model
.queryable()
.first()
.copied()
.expect("the fixture stores in a queryable backend");
model
.single_leg(graphql, database)
.to_token_stream()
.to_string()
.replace(' ', "")
}
#[test]
fn the_single_leg_branches_on_an_optional_door() {
let emitted = leg();
assert!(
emitted.contains("Context::data_opt::"),
"the leg reads the batch door OPTIONALLY:\n{emitted}"
);
assert!(
emitted.contains("graphql::BatchDoor"),
"and by the framework's own door type, through the shelf:\n{emitted}"
);
}
#[test]
fn the_door_is_keyed_on_this_records_id_and_row() {
let emitted = leg();
assert!(
emitted.contains("BatchDoor<Uuid7,VideoTrackSqlite>"),
"the door names the declared id type and this backend's row:\n{emitted}"
);
}
#[test]
fn the_key_is_the_declarations_own_spelling() {
let emitted = leg();
assert!(
emitted.contains("BatchDoor<Uuid7,"),
"`Uuid7` rather than the `u128` it resolves to:\n{emitted}"
);
}
#[test]
fn the_absent_lane_still_reads_the_store_the_way_it_did() {
let emitted = leg();
for token in ["SqlDoor", "sql::rows::", "SqlDoor::pool", "slice::from_ref"] {
assert!(
emitted.contains(token),
"the per-row lane still spells `{token}`:\n{emitted}"
);
}
}
#[test]
fn the_read_door_is_looked_up_after_the_batch_door() {
let emitted = leg();
let batch = emitted.find("data_opt::").expect("the batch lookup");
let read = emitted.find("data::<").expect("the read door lookup");
assert!(
batch < read,
"the batch door is read first, and the read door only where there is no batch:\n{emitted}"
);
}
#[test]
fn both_lanes_cross_the_written_id() {
let emitted = leg();
assert_eq!(
emitted
.matches("ToGraphqlInput>::cross(__async_graphql_id)")
.count(),
2,
"one crossing per lane, and neither hoisted above the branch:\n{emitted}"
);
}
#[test]
fn both_lanes_cross_their_refusals_the_same_way() {
let emitted = leg();
assert_eq!(
emitted.matches("graphql::refused(").count(),
2,
"one per lane, through the one place a code is ever attached:\n{emitted}"
);
assert_eq!(
emitted.matches("refused_address(").count(),
2,
"and one address refusal per lane, since each crosses its own id:\n{emitted}"
);
}
#[test]
fn the_leg_names_no_engine_and_no_spawner() {
let emitted = leg();
for absent in ["DataLoader", "AsLoader", "spawn", "dataloader", "cfg("] {
assert!(
!emitted.contains(absent),
"an expansion must not name `{absent}` — the engine is the application's:\n{emitted}"
);
}
}
#[test]
fn one_raise_serves_both_lanes() {
let emitted = leg();
assert_eq!(
emitted.matches("let__ingraph_hit=match").count(),
1,
"the branch produces the hit, and the raise below it is written once:\n{emitted}"
);
}