Skip to content

Commit

Permalink
Merge pull request #910 from Ken-vdE/patch-2
Browse files Browse the repository at this point in the history
Fix tests being generated with wrong endpoints.
  • Loading branch information
jondot authored Oct 27, 2024
2 parents abc9e2b + 5a60f10 commit 32051ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion loco-gen/src/templates/controller/api/test.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@ 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::<App, _, _>(|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]
async fn can_get_{{action}}() {
testing::request::<App, _, _>(|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;
Expand Down
4 changes: 2 additions & 2 deletions loco-gen/src/templates/scaffold/api/test.t
Original file line number Diff line number Diff line change
Expand Up @@ -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::<App, _, _>(|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:
Expand Down

0 comments on commit 32051ef

Please sign in to comment.