Skip to content

Commit

Permalink
Ignore checks result when an empty checks selection is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Sep 22, 2023
1 parent 89956c7 commit 0781f93
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/trento/domain/host/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,20 @@ defmodule Trento.Domain.Host do
end

def execute(
%Host{
host_id: host_id
},
%Host{} = host,
%SelectHostChecks{
checks: selected_checks
}
) do
%HostChecksSelected{
host_id: host_id,
checks: selected_checks
}
host
|> Multi.new()
|> Multi.execute(
&%HostChecksSelected{
host_id: &1.host_id,
checks: selected_checks
}
)
|> Multi.execute(&maybe_emit_host_health_changed_event/1)
end

def execute(
Expand Down
49 changes: 49 additions & 0 deletions test/trento/domain/host/host_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,55 @@ defmodule Trento.HostTest do
)
end
end

test "should ignore checks health when an empty checks selection is saved" do
host_id = Faker.UUID.v4()
host_registered_event = build(:host_registered_event, host_id: host_id)
heartbeat_succeded_event = build(:heartbeat_succeded, host_id: host_id)

checks_selected_event = %HostChecksSelected{
host_id: host_id,
checks: [Faker.UUID.v4()]
}

host_checks_health_changed_event =
build(:host_checks_health_changed,
host_id: host_id,
checks_health: Health.warning()
)

host_health_changed_event =
build(:host_health_changed_event, host_id: host_id, health: Health.warning())

assert_events_and_state(
[
host_registered_event,
heartbeat_succeded_event,
checks_selected_event,
host_checks_health_changed_event,
host_health_changed_event
],
SelectHostChecks.new!(%{
host_id: host_id,
checks: []
}),
[
%HostChecksSelected{
host_id: host_id,
checks: []
},
%HostHealthChanged{host_id: host_id, health: Health.passing()}
],
fn host ->
assert %Host{
heartbeat: Health.passing(),
selected_checks: [],
checks_health: Health.warning(),
health: Health.passing()
} = host
end
)
end
end

describe "heartbeat" do
Expand Down

0 comments on commit 0781f93

Please sign in to comment.