diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index 0b1f3cde..521882ea 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -253,7 +253,6 @@ impl App { #[cfg(test)] mod tests { - use super::*; #[test] diff --git a/crates/tuono/src/route.rs b/crates/tuono/src/route.rs index de0f5206..02391b8e 100644 --- a/crates/tuono/src/route.rs +++ b/crates/tuono/src/route.rs @@ -102,7 +102,7 @@ fn read_http_methods_from_file(path: &String) -> Vec { // Extract just the element surrounded by the phrantesist. .replace("tuono_lib::api(", "") .replace(")]", ""); - Method::from_str(http_method.as_str()).unwrap_or(Method::GET) + Method::from_str(http_method.to_uppercase().as_str()).unwrap_or(Method::GET) }) .collect::>() } @@ -283,7 +283,6 @@ impl Route { #[cfg(test)] mod tests { - use super::*; #[test] diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index bd076f5b..d4496409 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -107,6 +107,41 @@ fn it_successfully_create_multiple_api_for_the_same_file() { ); } +#[test] +#[serial] +fn it_successfully_import_mixed_case_routes() { + let temp_tuono_project = TempTuonoProject::new(); + + for method in ["get", "post", "put", "delete", "patch"] { + temp_tuono_project.add_file_with_content( + &format!("./src/routes/api/{}_lower.rs", method), + &format!(r"#[tuono_lib::api({})]", method), + ); + temp_tuono_project.add_file_with_content( + &format!("./src/routes/api/{}_upper.rs", method), + &format!(r"#[tuono_lib::api({})]", method.to_uppercase()), + ); + } + + let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); + test_tuono_build + .arg("build") + .arg("--no-js-emit") + .assert() + .success(); + + let temp_main_rs_path = temp_tuono_project.path().join(".tuono/main.rs"); + + let temp_main_rs_content = + fs::read_to_string(&temp_main_rs_path).expect("Failed to read '.tuono/main.rs' content."); + + for method in ["get", "post", "put", "delete", "patch"] { + let expected = format!(r#"use tuono_lib::axum::routing::{};"#, method); + let imports = temp_main_rs_content.match_indices(&expected); + assert_eq!(imports.count(), 1); + } +} + #[test] #[serial] fn it_successfully_create_catch_all_routes() {