Skip to content

Commit

Permalink
Exclude deleted devices from Deployment device counts (#1735)
Browse files Browse the repository at this point in the history
Missed this one from an earlier PR
  • Loading branch information
joshk authored Jan 7, 2025
1 parent 3a2c572 commit 42320dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nerves_hub/deployments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule NervesHub.Deployments do
|> select([d], {d.deployment_id, count(d.id)})
|> where([d], d.product_id == ^product_id)
|> group_by([d], d.deployment_id)
|> Repo.exclude_deleted()
|> Repo.all()
|> Map.new()
end
Expand Down
33 changes: 33 additions & 0 deletions test/nerves_hub_web/live/deployments/index_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule NervesHubWeb.Live.Deployments.IndexTest do
use NervesHubWeb.ConnCase.Browser, async: true

alias NervesHub.Deployments
alias NervesHub.Devices
alias NervesHub.Fixtures

test "no deployments", %{conn: conn, user: user, org: org} do
Expand All @@ -16,5 +18,36 @@ defmodule NervesHubWeb.Live.Deployments.IndexTest do
|> visit("/org/#{org.name}/#{product.name}/deployments")
|> assert_has("h1", text: "Deployments")
|> assert_has("a", text: deployment.name)
|> assert_has("td div", text: "0")
end

test "device counts don't include deleted devices", %{
conn: conn,
org: org,
product: product,
deployment: deployment,
device: device
} do
conn
|> visit("/org/#{org.name}/#{product.name}/deployments")
|> assert_has("h1", text: "Deployments")
|> assert_has("a", text: deployment.name)
|> assert_has("td div", text: "0")

Deployments.set_deployment(device)

conn
|> visit("/org/#{org.name}/#{product.name}/deployments")
|> assert_has("h1", text: "Deployments")
|> assert_has("a", text: deployment.name)
|> assert_has("td div", text: "1")

Devices.delete_device(device)

conn
|> visit("/org/#{org.name}/#{product.name}/deployments")
|> assert_has("h1", text: "Deployments")
|> assert_has("a", text: deployment.name)
|> assert_has("td div", text: "0")
end
end

0 comments on commit 42320dc

Please sign in to comment.