Skip to content

Commit

Permalink
chore(update_channels): allow empty targets
Browse files Browse the repository at this point in the history
Update channels can have zero target device groups.
Closes edgehog-device-manager#399 and Closes edgehog-device-manager#518.

Signed-off-by: Luca Zaninotto <[email protected]>
  • Loading branch information
lusergit committed Jan 13, 2025
1 parent 5374612 commit 278e5b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ defmodule Edgehog.UpdateCampaigns.UpdateChannel do
description """
The IDs of the target groups that are targeted by this update channel.
"""

allow_nil? false
constraints min_length: 1
end

change Changes.RelateTargetGroups do
Expand All @@ -78,8 +75,6 @@ defmodule Edgehog.UpdateCampaigns.UpdateChannel do
description """
The IDs of the target groups that are targeted by this update channel.
"""

constraints min_length: 1
end

# Needed because manage_relationship is not atomic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do
assert target_group_data["handle"] == target_group.handle
end

test "creates update_channel with nil target_group_ids", %{tenant: tenant} do
name = unique_update_channel_name()
handle = unique_update_channel_handle()

result =
[target_group_ids: nil, tenant: tenant, name: name, handle: handle]
|> create_update_channel_mutation()
|> extract_result!()

assert result["name"] == name
assert result["handle"] == handle
assert result["targetGroups"] == []
end

test "creates update_channel with empty target_group_ids", %{tenant: tenant} do
name = unique_update_channel_name()
handle = unique_update_channel_handle()

result =
[target_group_ids: [], tenant: tenant, name: name, handle: handle]
|> create_update_channel_mutation()
|> extract_result!()

assert result["name"] == name
assert result["handle"] == handle
assert result["targetGroups"] == []
end

test "fails with missing name", %{tenant: tenant} do
error =
[name: nil, tenant: tenant]
Expand Down Expand Up @@ -143,30 +171,6 @@ defmodule EdgehogWeb.Schema.Mutation.CreateUpdateChannelTest do
} = error
end

test "fails with missing target_group_ids", %{tenant: tenant} do
error =
[target_group_ids: nil, tenant: tenant]
|> create_update_channel_mutation()
|> extract_error!()

assert %{message: message} = error
assert message =~ ~s<In field "targetGroupIds": Expected type "[ID!]!", found null.>
end

test "fails with empty target_group_ids", %{tenant: tenant} do
error =
[target_group_ids: [], tenant: tenant]
|> create_update_channel_mutation()
|> extract_error!()

assert %{
path: ["createUpdateChannel"],
fields: [:target_group_ids],
message: "must have 1 or more items",
code: "invalid_argument"
} = error
end

test "fails when trying to use a non-existing target group", %{tenant: tenant} do
target_group_id = non_existing_device_group_id(tenant)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,13 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateUpdateChannelTest do
} = error
end

test "fails with empty target_group_ids", %{tenant: tenant, id: id} do
error =
test "updates update_channel with empty target_group_ids", %{tenant: tenant, id: id} do
result =
[id: id, target_group_ids: [], tenant: tenant]
|> update_update_channel_mutation()
|> extract_error!()
|> extract_result!()

assert %{
path: ["updateUpdateChannel"],
fields: [:target_group_ids],
code: "invalid_argument",
message: "must have 1 or more items"
} = error
assert result["id"] == id
end

test "fails when trying to use a non-existing target group id", %{tenant: tenant, id: id} do
Expand Down

0 comments on commit 278e5b1

Please sign in to comment.