Skip to content

Commit

Permalink
Allow devices to have empty firmware when checking for deployments (#…
Browse files Browse the repository at this point in the history
…1749)

Fixes a bug (#1748 ) where the liveview crashes when trying to show a
device without firmware metadata.
  • Loading branch information
elinol authored Jan 13, 2025
1 parent f277003 commit 1aca237
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nerves_hub/deployments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ defmodule NervesHub.Deployments do
and should only be used when a human is choosing the deployment for a device.
"""
@spec eligible_deployments(Device.t()) :: [Deployment.t()]
def eligible_deployments(%Device{firmware_metadata: nil}), do: []

def eligible_deployments(device) do
Deployment
|> join(:inner, [d], assoc(d, :firmware), as: :firmware)
Expand Down
19 changes: 19 additions & 0 deletions test/nerves_hub_web/live/devices/show_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ defmodule NervesHubWeb.Live.Devices.ShowTest do
Endpoint.subscribe("device:#{device.id}")
end

describe "render liveview" do
test "render when device has no firmware", %{
conn: conn,
org: org,
product: product
} do
{:ok, device} =
Devices.create_device(%{
org_id: org.id,
product_id: product.id,
identifier: "no-firmware-device"
})

conn
|> visit("/org/#{org.name}/#{product.name}/devices/#{device.identifier}")
|> assert_has("h1", text: "no-firmware-device")
end
end

describe "handle_event" do
test "delete device", %{conn: conn, org: org, product: product, device: device} do
conn
Expand Down

0 comments on commit 1aca237

Please sign in to comment.