From 5eb44a01d26974b6aa2663a631e777c675412913 Mon Sep 17 00:00:00 2001 From: Ken van der Eerden <15888558+Ken-vdE@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:31:28 +0200 Subject: [PATCH 1/3] Fix scaffold api test endpoint being singular --- loco-gen/src/templates/scaffold/api/test.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loco-gen/src/templates/scaffold/api/test.t b/loco-gen/src/templates/scaffold/api/test.t index d6298659d..9fdfe805c 100644 --- a/loco-gen/src/templates/scaffold/api/test.t +++ b/loco-gen/src/templates/scaffold/api/test.t @@ -14,9 +14,9 @@ use serial_test::serial; #[tokio::test] #[serial] -async fn can_list() { +async fn can_get_{{ name | plural | snake_case }}() { testing::request::(|request, _ctx| async move { - let res = request.get("/{{ name | snake_case }}/").await; + let res = request.get("/{{ name | plural | snake_case }}/").await; assert_eq!(res.status_code(), 200); // you can assert content like this: From 0df9a5b534c2282897872633100e97c56ddd264f Mon Sep 17 00:00:00 2001 From: Ken van der Eerden <15888558+Ken-vdE@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:34:11 +0200 Subject: [PATCH 2/3] fix template controller api test endpoint being singular --- loco-gen/src/templates/controller/api/test.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loco-gen/src/templates/controller/api/test.t b/loco-gen/src/templates/controller/api/test.t index 3a507ec9f..d66fe7c81 100644 --- a/loco-gen/src/templates/controller/api/test.t +++ b/loco-gen/src/templates/controller/api/test.t @@ -17,7 +17,7 @@ use serial_test::serial; #[serial] async fn can_get_{{action}}() { testing::request::(|request, _ctx| async move { - let res = request.get("/{{ name | snake_case }}/{{action}}").await; + let res = request.get("/{{ name | plural | snake_case }}/{{action}}").await; assert_eq!(res.status_code(), 200); }) .await; From 5a60f1065ec6286860630f2491822ac54d8e3f65 Mon Sep 17 00:00:00 2001 From: Ken van der Eerden <15888558+Ken-vdE@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:01:00 +0200 Subject: [PATCH 3/3] added index request test --- loco-gen/src/templates/controller/api/test.t | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/loco-gen/src/templates/controller/api/test.t b/loco-gen/src/templates/controller/api/test.t index d66fe7c81..568e98d5c 100644 --- a/loco-gen/src/templates/controller/api/test.t +++ b/loco-gen/src/templates/controller/api/test.t @@ -12,6 +12,19 @@ use {{pkg_name}}::app::App; use loco_rs::testing; use serial_test::serial; +#[tokio::test] +#[serial] +async fn can_get_{{ name | plural | snake_case }}() { + testing::request::(|request, _ctx| async move { + let res = request.get("/{{ name | plural | snake_case }}/").await; + assert_eq!(res.status_code(), 200); + + // you can assert content like this: + // assert_eq!(res.text(), "content"); + }) + .await; +} + {% for action in actions -%} #[tokio::test] #[serial]