use crate::parse_schema;
const BARE: &str = r#"
type Ping {
nonce String
}
mutation procedure notify(args: Ping): Ping
@no_idempotency
"#;
const WITH_ARGUMENT: &str = r#"
type Ping {
nonce String
}
mutation procedure notify(args: Ping): Ping
@no_idempotency(true)
"#;
const DUPLICATED: &str = r#"
type Ping {
nonce String
}
mutation procedure notify(args: Ping): Ping
@no_idempotency
@no_idempotency
"#;
#[test]
fn bare_no_idempotency_still_parses() {
let schema = parse_schema(BARE).expect("the bare form is the supported one");
assert!(
schema.procedures[0]
.attributes
.iter()
.any(|a| a.raw == "@no_idempotency"),
"the attribute must survive validation onto the Procedure, or codegen \
has nothing to read"
);
}
#[test]
fn no_idempotency_needs_no_extension_block() {
let schema = parse_schema(BARE).expect("no extension block is declared above");
assert!(schema.declared_extensions.is_empty());
}
#[test]
fn no_idempotency_rejects_arguments() {
let error = parse_schema(WITH_ARGUMENT)
.expect_err("@no_idempotency(true) must not be silently accepted and ignored");
assert!(
error.message().contains("does not take any arguments"),
"the message must say why, got: {}",
error.message()
);
assert!(
error.message().contains("notify"),
"the message must name the procedure, got: {}",
error.message()
);
}
#[test]
fn no_idempotency_rejects_duplicates() {
let error = parse_schema(DUPLICATED).expect_err("a repeated @no_idempotency must be an error");
assert!(
error.message().contains("more than one @no_idempotency"),
"got: {}",
error.message()
);
}