Skip to content

Commit

Permalink
fix controller test blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Dec 31, 2024
1 parent 86e5f15 commit 832e894
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use {{crate_name}}_web::test_helpers::{BodyExt, DbTestContext, RouterExt};
use axum::{
body::Body,
http::{self, Method},
Expand All @@ -8,6 +7,7 @@ use googletest::prelude::*;
use hyper::StatusCode;
use {{db_crate_name}}::{entities, transaction, Error};
use {{macros_crate_name}}::db_test;
use {{web_crate_name}}::test_helpers::{BodyExt, DbTestContext, RouterExt};
use serde_json::json;
use std::collections::HashMap;
use uuid::Uuid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- if has_db -%}
use {{crate_name}}_web::test_helpers::{BodyExt, DbTestContext, RouterExt};
use {{web_crate_name}}::test_helpers::{BodyExt, DbTestContext, RouterExt};
{% else %}
use {{crate_name}}_web::test_helpers::{BodyExt, DbTestContext, RouterExt};
use {{web_crate_name}}::test_helpers::{BodyExt, TestContext, RouterExt};
{%- endif -%}
use axum::{body::Body, http::Method};
use googletest::prelude::*;
Expand Down
8 changes: 7 additions & 1 deletion blueprint/cli/src/bin/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,15 @@ async fn generate_controller_test(name: String) -> Result<String, anyhow::Error>
let name = to_snake_case(&name).to_lowercase();
let macros_crate_name = get_member_package_name("macros")?;
let macros_crate_name = to_snake_case(&macros_crate_name);
let web_crate_name = get_member_package_name("web")?;
let web_crate_name = to_snake_case(&web_crate_name);
let has_db = has_db();

let template = get_liquid_template("controller/minimal/test.rs")?;
let variables = liquid::object!({
"name": name,
"macros_crate_name": macros_crate_name,
"web_crate_name": web_crate_name,
"has_db": has_db,
});
let output = template
Expand Down Expand Up @@ -403,14 +406,17 @@ async fn generate_crud_controller_test(name: String) -> Result<String, anyhow::E
let db_crate_name = to_snake_case(&db_crate_name);
let macros_crate_name = get_member_package_name("macros")?;
let macros_crate_name = to_snake_case(&macros_crate_name);
let web_crate_name = get_member_package_name("web")?;
let web_crate_name = to_snake_case(&web_crate_name);

let template = get_liquid_template("controller/crud/test.rs")?;
let variables = liquid::object!({
"entity_struct_name": struct_name,
"entity_singular_name": name_singular,
"entity_plural_name": name_plural,
"db_crate_name": db_crate_name,
"macros_crate_name": macros_crate_name
"macros_crate_name": macros_crate_name,
"web_crate_name": web_crate_name,
});
let output = template
.render(&variables)
Expand Down

0 comments on commit 832e894

Please sign in to comment.