From 851bbd54affb239fffd8e11434b80ed7355bb46e Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 2 Apr 2026 15:26:15 +0100 Subject: [PATCH] Setup swoosh sandbox --- config/test.exs | 2 +- test/error_tracker/error_notifier_test.exs | 10 ++++++++-- .../records_on_this_day_email_test.exs | 4 ++++ test/test_helper.exs | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/test.exs b/config/test.exs index 616bca6c..4192dd32 100644 --- a/config/test.exs +++ b/config/test.exs @@ -104,4 +104,4 @@ config :music_library, color_extractor: MusicLibrary.Colors.FakeColorExtractor config :music_library, Oban, testing: :manual -config :music_library, MusicLibrary.Mailer, adapter: Swoosh.Adapters.Test +config :music_library, MusicLibrary.Mailer, adapter: Swoosh.Adapters.Sandbox diff --git a/test/error_tracker/error_notifier_test.exs b/test/error_tracker/error_notifier_test.exs index 3709eade..95299c44 100644 --- a/test/error_tracker/error_notifier_test.exs +++ b/test/error_tracker/error_notifier_test.exs @@ -4,6 +4,7 @@ defmodule ErrorTracker.ErrorNotifierTest do import Swoosh.TestAssertions alias ErrorTracker.{Error, ErrorNotifier, Occurrence} + alias Swoosh.Adapters.Sandbox, as: SwooshSandbox @config [ from_email: "test@example.com", @@ -39,9 +40,9 @@ defmodule ErrorTracker.ErrorNotifierTest do ) end - setup :set_swoosh_global - setup do + :ok = SwooshSandbox.checkout() + previous = Application.get_env(:music_library, ErrorNotifier) case Process.whereis(ErrorNotifier) do @@ -50,6 +51,8 @@ defmodule ErrorTracker.ErrorNotifierTest do end on_exit(fn -> + SwooshSandbox.checkin() + case Process.whereis(ErrorNotifier) do nil -> :ok pid -> GenServer.stop(pid) @@ -113,6 +116,7 @@ defmodule ErrorTracker.ErrorNotifierTest do ) {:ok, pid} = ErrorNotifier.start_link([]) + SwooshSandbox.allow(self(), pid) :telemetry.execute([:error_tracker, :error, :new], %{}, %{ error: %ErrorTracker.Error{id: 1}, @@ -141,6 +145,7 @@ defmodule ErrorTracker.ErrorNotifierTest do Application.put_env(:music_library, ErrorNotifier, @config) {:ok, pid} = ErrorNotifier.start_link([]) + SwooshSandbox.allow(self(), pid) :telemetry.execute([:error_tracker, :error, :new], %{}, %{ error: %Error{id: 1}, @@ -168,6 +173,7 @@ defmodule ErrorTracker.ErrorNotifierTest do Application.put_env(:music_library, ErrorNotifier, @config) {:ok, pid} = ErrorNotifier.start_link([]) + SwooshSandbox.allow(self(), pid) :telemetry.execute([:error_tracker, :error, :new], %{}, %{ error: %Error{id: 99}, diff --git a/test/music_library_web/records_on_this_day_email_test.exs b/test/music_library_web/records_on_this_day_email_test.exs index 716a7102..713b0c62 100644 --- a/test/music_library_web/records_on_this_day_email_test.exs +++ b/test/music_library_web/records_on_this_day_email_test.exs @@ -6,8 +6,11 @@ defmodule MusicLibraryWeb.RecordsOnThisDayEmailTest do alias MusicLibrary.Fixtures alias MusicLibrary.Records.Record alias MusicLibraryWeb.RecordsOnThisDayEmail + alias Swoosh.Adapters.Sandbox, as: SwooshSandbox setup do + :ok = SwooshSandbox.checkout() + Application.put_env(:music_library, RecordsOnThisDayEmail, from_email: "test@example.com", to_email: "recipient@example.com", @@ -16,6 +19,7 @@ defmodule MusicLibraryWeb.RecordsOnThisDayEmailTest do ) on_exit(fn -> + SwooshSandbox.checkin() Application.delete_env(:music_library, RecordsOnThisDayEmail) end) end diff --git a/test/test_helper.exs b/test/test_helper.exs index a6fa7343..c42f0b9e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,3 +1,4 @@ +{:ok, _} = Swoosh.Adapters.Sandbox.Storage.start_link([]) ExUnit.start() Ecto.Adapters.SQL.Sandbox.mode(MusicLibrary.Repo, :manual) Ecto.Adapters.SQL.Sandbox.mode(MusicLibrary.BackgroundRepo, :manual)