Skip to content

Commit

Permalink
use TestMessageProxy for assert receive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinco committed Aug 23, 2024
1 parent fc968f4 commit 5eac749
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
3 changes: 1 addition & 2 deletions test/unit/error_info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule ErrorInfoTest do
options: [
mailer: Support.BambooFakeMailer,
from: "[email protected]",
to: to_string(ErrorInfoTest),
to: to_string(BoomNotifier.TestMessageProxy),
subject: "BOOM error caught"
]

Expand Down Expand Up @@ -71,7 +71,6 @@ defmodule ErrorInfoTest do
end

setup do
Process.register(self(), ErrorInfoTest)
Logger.metadata(name: "Dennis", age: 17)
end

Expand Down
7 changes: 3 additions & 4 deletions test/unit/mailer_notifier_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule MailerNotifierTest do
options: [
mailer: @fake_mailer_module,
from: "[email protected]",
to: to_string(MailerNotifierTest),
to: to_string(BoomNotifier.TestMessageProxy),
subject: "BOOM error caught"
],
custom_data: [:assigns, :logger]
Expand Down Expand Up @@ -101,7 +101,7 @@ defmodule MailerNotifierTest do
options: [
mailer: @fake_mailer_module,
from: "[email protected]",
to: to_string(MailerNotifierTest),
to: to_string(BoomNotifier.TestMessageProxy),
subject: "BOOM error caught",
max_subject_length: 25
]
Expand All @@ -115,7 +115,6 @@ defmodule MailerNotifierTest do
:elixir_config.put(:ignore_module_conflict, false)

setup do
Process.register(self(), MailerNotifierTest)
Logger.metadata(name: "Dennis", age: 17)

on_exit(&flush_messages/0)
Expand Down Expand Up @@ -158,7 +157,7 @@ defmodule MailerNotifierTest do
test "Set email using proper from and to addresses" do
conn = conn(:get, "/")
catch_error(TestRouter.call(conn, []))
email_to = MailerNotifierTest |> to_string()
email_to = BoomNotifier.TestMessageProxy |> to_string()

assert_receive({:email_from, "[email protected]"}, @receive_timeout)
assert_receive({:email_to, ^email_to}, @receive_timeout)
Expand Down
4 changes: 1 addition & 3 deletions test/unit/notification_sender_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ defmodule BoomNotifier.NotificationSenderTest do
}

@throttle_timeout 500
@pid_name __MODULE__
@receive_timeout 100

@settings_basic [
notifier: __MODULE__.NotificationSenderTestNotifier,
options: [pid_name: @pid_name]
options: [pid_name: BoomNotifier.TestMessageProxy]
]

@settings_groupping @settings_basic ++
Expand Down Expand Up @@ -47,7 +46,6 @@ defmodule BoomNotifier.NotificationSenderTest do
end

setup do
self() |> Process.register(@pid_name)
clear_error_storage()

on_exit(&flush_messages/0)
Expand Down
23 changes: 12 additions & 11 deletions test/unit/notifier_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule NotifierTest do
import ExUnit.CaptureLog
import TestUtils

alias BoomNotifier.TestMessageProxy

doctest BoomNotifier

@receive_timeout 500
Expand Down Expand Up @@ -62,7 +64,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand All @@ -77,7 +79,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]
]
]
Expand All @@ -92,7 +94,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand All @@ -105,7 +107,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand All @@ -119,7 +121,7 @@ defmodule NotifierTest do
notification_trigger: :exponential,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand All @@ -133,7 +135,7 @@ defmodule NotifierTest do
notification_trigger: [exponential: [limit: 3]],
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand All @@ -154,7 +156,6 @@ defmodule NotifierTest do
end

setup do
Process.register(self(), NotifierTest)
clear_error_storage()

on_exit(&flush_messages/0)
Expand Down Expand Up @@ -359,7 +360,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
],
ignore_exceptions: [TestException]

Expand All @@ -373,7 +374,7 @@ defmodule NotifierTest do
notifier: FakeNotifier,
options: [
subject: "BOOM error caught",
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
],
ignore_exceptions: [TestException]

Expand Down Expand Up @@ -402,14 +403,14 @@ defmodule NotifierTest do
use Plug.ErrorHandler

def handle_errors(_conn, _error) do
test_pid = Process.whereis(NotifierTest)
test_pid = Process.whereis(TestMessageProxy)
send(test_pid, :handle_errors_called)
end

use BoomNotifier,
notifier: FakeNotifier,
options: [
sender_pid_name: NotifierTest
sender_pid_name: TestMessageProxy
]

def call(_conn, _opts) do
Expand Down

0 comments on commit 5eac749

Please sign in to comment.