Skip to content

Commit

Permalink
Issue software updates discovery process for all the registered hosts…
Browse files Browse the repository at this point in the history
… when saving settings
  • Loading branch information
nelsonkopliku committed Apr 15, 2024
1 parent 0310eec commit 47792ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/trento/software_updates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ defmodule Trento.SoftwareUpdates do
| {:error, :settings_already_configured}
| {:error, any()}
def save_settings(settings_submission, date_service \\ DateService) do
with {:ok, :settings_not_configured, settings} <- ensure_no_settings_configured() do
save_new_settings(settings, settings_submission, date_service)
with {:ok, :settings_not_configured, settings} <- ensure_no_settings_configured(),
saving_result <- save_new_settings(settings, settings_submission, date_service) do
Discovery.discover_software_updates()
saving_result
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/trento/software_updates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Trento.SoftwareUpdates.SettingsTest do

import Trento.Factory

alias Trento.Hosts.Commands.DiscoverSoftwareUpdates
alias Trento.SoftwareUpdates
alias Trento.SoftwareUpdates.Settings

Expand Down Expand Up @@ -195,6 +196,27 @@ defmodule Trento.SoftwareUpdates.SettingsTest do

assert {:error, :settings_already_configured} = SoftwareUpdates.save_settings(settings)
end

test "should issue software updates discovery process when saving settings" do
insert_list(5, :host)
insert(:host, deregistered_at: DateTime.to_iso8601(Faker.DateTime.backward(2)))

expect(
Trento.Commanded.Mock,
:dispatch,
5,
fn %DiscoverSoftwareUpdates{} -> :ok end
)

settings = %{
url: "https://valid.com",
username: Faker.Internet.user_name(),
password: Faker.Lorem.word(),
ca_cert: Faker.Lorem.sentence()
}

assert {:ok, _} = SoftwareUpdates.save_settings(settings)
end
end

describe "changing software updates settings" do
Expand Down

0 comments on commit 47792ad

Please sign in to comment.