use crate::e2e::template_env;
use super::snippets::{MockCapture, mock_capture};
pub(crate) const MOCK_TOTAL_PATH: &str = "/__alef/requests/total";
pub(crate) const MOCK_ONE_PATH: &str = "/__alef/requests/one";
pub(crate) fn render_helper(language: &str) -> Option<String> {
let MockCapture {
helper_name,
helper_template,
} = mock_capture(language).ok()?;
Some(template_env::render(
helper_template,
crate::alef_context! {
helper_name => helper_name,
total_path => MOCK_TOTAL_PATH,
one_path => MOCK_ONE_PATH,
},
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_wired_language_renders_its_own_helper_name() {
for (language, expected_name) in [
("rust", "alef_mock_request_count"),
("python", "_alef_mock_request_count"),
("node", "alefMockRequestCount"),
("go", "alefMockRequestCount"),
("ruby", "alef_mock_request_count"),
("php", "alefMockRequestCount"),
("java", "alefMockRequestCount"),
("csharp", "alefMockRequestCount"),
] {
let rendered = render_helper(language).unwrap_or_else(|| panic!("{language} must render a helper"));
assert!(
rendered.contains(expected_name),
"{language} helper must be named {expected_name}, got:\n{rendered}"
);
}
}
#[test]
fn the_endpoint_paths_are_the_documented_constants() {
assert_eq!(MOCK_TOTAL_PATH, "/__alef/requests/total");
assert_eq!(MOCK_ONE_PATH, "/__alef/requests/one");
}
#[test]
fn an_unwired_language_renders_nothing() {
assert!(render_helper("php_ext").is_none());
}
}