Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Jul 7, 2022
1 parent 8d65444 commit 1b30176
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions test/trento/application/usecases/alerting_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Trento.Application.UseCases.AlertingTest do
@moduledoc false
use ExUnit.Case, async: true
use Trento.DataCase

Expand All @@ -10,12 +11,16 @@ defmodule Trento.Application.UseCases.AlertingTest do

@moduletag :integration

@some_sender "[email protected]"
@some_recipient "[email protected]"

describe "Enabling/Disabling Alerting Feature" do
setup do
on_exit(fn ->
Application.put_env(:trento, :alerting,
enabled: true,
recipient: "[email protected]"
sender: @some_sender,
recipient: @some_recipient
)
end)
end
Expand All @@ -30,7 +35,12 @@ defmodule Trento.Application.UseCases.AlertingTest do
end

test "An error should be raised when alerting is enabled but no recipient was provided" do
Application.put_env(:trento, :alerting, enabled: true)
Application.put_env(:trento, :alerting,
enabled: true,
sender: @some_sender
# no recipient set
)

sap_system_id = Faker.UUID.v4()
insert(:sap_system, id: sap_system_id)

Expand All @@ -40,6 +50,23 @@ defmodule Trento.Application.UseCases.AlertingTest do

assert_no_email_sent()
end

test "An error should be raised when alerting is enabled but no sender was provided" do
Application.put_env(:trento, :alerting,
enabled: true,
# no sender set
recipient: @some_recipient
)

sap_system_id = Faker.UUID.v4()
insert(:sap_system, id: sap_system_id)

assert_raise ArgumentError,
~r/Unexpected tuple format, {"Trento Alerts", nil} cannot be formatted into a Recipient./,
fn -> Alerting.notify_critical_sap_system_health(sap_system_id) end

assert_no_email_sent()
end
end

describe "Alerting the configured recipient about crucial facts with email notifications" do
Expand Down

0 comments on commit 1b30176

Please sign in to comment.