Skip to content

Commit

Permalink
Improve api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Feb 13, 2025
1 parent dc9696a commit 7e56118
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
10 changes: 7 additions & 3 deletions lib/wanda_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ defmodule WandaWeb.Router do
get "/groups/:id/executions/last", ExecutionController, :last
post "/executions/start", ExecutionController, :start
get "/catalog", CatalogController, :catalog
end

scope "/groups" do
pipe_through [:api_v1, :protected_api]

get "/groups/:group_id/catalog", CatalogController, :selectable_checks
get "/:group_id/checks", CatalogController, :selectable_checks

post "/:check_id/customize/:group_id",
post "/:group_id/check/:check_id/customization",
ChecksCustomizationsController,
:apply_custom_values

delete "/:check_id/group/:group_id/customization",
delete "/:group_id/check/:check_id/customization",
ChecksCustomizationsController,
:reset_customization
end
Expand Down
4 changes: 2 additions & 2 deletions test/wanda_web/controllers/v1/catalog_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule WandaWeb.V1.CatalogControllerTest do
%{conn: conn, api_spec: api_spec} do
%{items: selectable_checks} =
conn
|> get("/api/v1/checks/groups/#{Faker.UUID.v4()}/catalog", %{})
|> get("/api/v1/groups/#{Faker.UUID.v4()}/checks", %{})
|> json_response(:ok)
|> assert_schema("SelectableChecksResponse", api_spec)

Expand Down Expand Up @@ -119,7 +119,7 @@ defmodule WandaWeb.V1.CatalogControllerTest do

%{items: selectable_checks} =
conn
|> get("/api/v1/checks/groups/#{group_id}/catalog", %{})
|> get("/api/v1/groups/#{group_id}/checks", %{})
|> json_response(:ok)
|> assert_schema("SelectableChecksResponse", api_spec)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
response =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", invalid_body)
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", invalid_body)
|> json_response(:unprocessable_entity)
|> assert_schema("JsonErrorResponse", api_spec)

Expand All @@ -150,7 +150,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
response =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", request_body)
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", request_body)
|> json_response(:not_found)
|> assert_schema("NotFound", api_spec)

Expand All @@ -176,7 +176,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
response =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", request_body)
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", request_body)
|> json_response(:forbidden)
|> assert_schema("Forbidden", api_spec)

Expand Down Expand Up @@ -271,7 +271,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
response =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", %{
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", %{
values: values
})
|> json_response(:bad_request)
Expand Down Expand Up @@ -312,7 +312,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
response =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", %{
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", %{
values: custom_values
})
|> json_response(:ok)
Expand Down Expand Up @@ -386,7 +386,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
)

assert conn
|> delete("/api/v1/checks/#{check_id}/group/#{group_id}/customization")
|> delete("/api/v1/groups/#{group_id}/check/#{check_id}/customization")
|> response(204) == ""

remaining_customizations =
Expand Down Expand Up @@ -429,7 +429,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do

conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/checks/#{check_id}/customize/#{group_id}", %{
|> post("/api/v1/groups/#{group_id}/check/#{check_id}/customization", %{
values: custom_values
})
|> json_response(:forbidden)
Expand All @@ -443,7 +443,7 @@ defmodule WandaWeb.V1.ChecksCustomizationsControllerTest do
} do
conn
|> put_req_header("content-type", "application/json")
|> delete("/api/v1/checks/#{Faker.UUID.v4()}/group/#{Faker.UUID.v4()}/customization")
|> delete("/api/v1/groups/#{Faker.UUID.v4()}/check/#{Faker.UUID.v4()}/customization")
|> json_response(:forbidden)
|> assert_schema("Forbidden", api_spec)
end
Expand Down

0 comments on commit 7e56118

Please sign in to comment.