From 1b3017642174c38ceb0d90734f403d1b7fc254b3 Mon Sep 17 00:00:00 2001 From: nelsonkopliku Date: Thu, 7 Jul 2022 15:01:20 +0200 Subject: [PATCH] Updated tests --- .../application/usecases/alerting_test.exs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/trento/application/usecases/alerting_test.exs b/test/trento/application/usecases/alerting_test.exs index e56d1cead6..8211eebaf7 100644 --- a/test/trento/application/usecases/alerting_test.exs +++ b/test/trento/application/usecases/alerting_test.exs @@ -1,4 +1,5 @@ defmodule Trento.Application.UseCases.AlertingTest do + @moduledoc false use ExUnit.Case, async: true use Trento.DataCase @@ -10,12 +11,16 @@ defmodule Trento.Application.UseCases.AlertingTest do @moduletag :integration + @some_sender "some.sender@email.com" + @some_recipient "some.recipient@email.com" + describe "Enabling/Disabling Alerting Feature" do setup do on_exit(fn -> Application.put_env(:trento, :alerting, enabled: true, - recipient: "some.recipient@email.com" + sender: @some_sender, + recipient: @some_recipient ) end) end @@ -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) @@ -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