test(build): reject invalid client handler names
Drive AppBuilder through a rooted client module with a non-Rust handler name and assert the exact InvalidData diagnostic, closing the public invalid-value mutation seam. req: build/004 req: client_local/011 req: diagnostics/004 req: test/021
This commit is contained in:
+23
-2
@@ -2512,7 +2512,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_builder_returns_output_errors_instead_of_panicking() {
|
||||
fn app_builder_propagates_output_and_client_contract_errors_without_panicking() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"hemx-build-error-{}-{}",
|
||||
std::process::id(),
|
||||
@@ -2552,8 +2552,29 @@ mod tests {
|
||||
result.unwrap().unwrap_err().to_string(),
|
||||
"client-local handlers require one data-hemx-client-module on a hemx root"
|
||||
);
|
||||
|
||||
let invalid_handler = templates.join("invalid_handler.heml");
|
||||
std::fs::write(
|
||||
&invalid_handler,
|
||||
r#"<main data-hemx-root="app" data-hemx-client-module="/app.js"><button data-hemx-client="save-item">Save</button></main>"#,
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::remove_file(templates.join("client.heml")).unwrap();
|
||||
let error = app()
|
||||
.template_dir(&templates)
|
||||
.out_dir(&invalid_out)
|
||||
.run()
|
||||
.unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidData);
|
||||
assert_eq!(
|
||||
error.to_string(),
|
||||
format!(
|
||||
"{}: invalid data-hemx-client value `save-item`; expected a Rust handler identifier",
|
||||
invalid_handler.display()
|
||||
)
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
// test req: build/004
|
||||
// test req: build/004 req: client_local/011 req: diagnostics/004
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user