Skip to content

Commit 6db750b

Browse files
authored
Fix scripts index API endpoint (#2097)
I mistakenly modified the `conn.assigns` in the ScriptsController test, which doesn't reflect how the real world works. This PR uses `device.product` instead of relying on the product being in `conn.assigns`. I verified this works locally with Postman.
1 parent de1a5b3 commit 6db750b

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/nerves_hub_web/controllers/api/script_controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ defmodule NervesHubWeb.API.ScriptController do
1111

1212
operation(:index, summary: "List all Support Scripts for a Product")
1313

14-
def index(%{assigns: %{product: product}} = conn, _params) do
14+
def index(%{assigns: %{device: device}} = conn, _params) do
1515
conn
16-
|> assign(:scripts, Scripts.all_by_product(product))
16+
|> assign(:scripts, Scripts.all_by_product(device.product))
1717
|> render(:index)
1818
end
1919

test/nerves_hub_web/controllers/api/script_controller_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ defmodule NervesHubWeb.API.ScriptControllerTest do
1414
describe "index" do
1515
test "lists scripts", %{conn: conn, product: product, device: device, user: user} do
1616
script = Fixtures.support_script_fixture(product, user)
17-
conn = Map.put(conn, :assigns, %{product: product})
1817
conn = get(conn, Routes.api_script_path(conn, :index, device))
1918
data = [script_response] = json_response(conn, 200)["data"]
2019
assert Enum.count(data) == 1

0 commit comments

Comments
 (0)