From dca41cc4a37999a6971b70ef5e0996e528b79bf5 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 12 Dec 2023 15:25:52 +0400 Subject: [PATCH] EmailTest: use config mock --- config/test.exs | 2 ++ lib/pleroma/emails/mailer.ex | 3 ++- lib/pleroma/user.ex | 3 ++- test/mix/tasks/pleroma/email_test.exs | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/test.exs b/config/test.exs index cf407ebf2..cdd3529c4 100644 --- a/config/test.exs +++ b/config/test.exs @@ -152,6 +152,8 @@ config :pleroma, Pleroma.Upload, config_impl: Pleroma.UnstubbedConfigMock config :pleroma, Pleroma.ScheduledActivity, config_impl: Pleroma.UnstubbedConfigMock config :pleroma, Pleroma.Web.RichMedia.Helpers, config_impl: Pleroma.StaticStubbedConfigMock +config :pleroma, Pleroma.Emails.Mailer, config_impl: Pleroma.UnstubbedConfigMock +config :pleroma, Pleroma.User, config_impl: Pleroma.UnstubbedConfigMock if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/lib/pleroma/emails/mailer.ex b/lib/pleroma/emails/mailer.ex index 101442130..02c148e9f 100644 --- a/lib/pleroma/emails/mailer.ex +++ b/lib/pleroma/emails/mailer.ex @@ -14,9 +14,10 @@ defmodule Pleroma.Emails.Mailer do @otp_app :pleroma @mailer_config [otp: :pleroma] + @config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config) @spec enabled?() :: boolean() - def enabled?, do: Pleroma.Config.get([__MODULE__, :enabled]) + def enabled?, do: @config_impl.get([__MODULE__, :enabled]) @doc "add email to queue" def deliver_async(email, config \\ []) do diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0706f5607..f939687eb 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -86,6 +86,7 @@ defmodule Pleroma.User do ] @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config) schema "users" do field(:bio, :string, default: "") @@ -1000,7 +1001,7 @@ defp maybe_send_welcome_email(_), do: {:ok, :noop} @spec maybe_send_confirmation_email(User.t()) :: {:ok, :enqueued | :noop} def maybe_send_confirmation_email(%User{is_confirmed: false, email: email} = user) when is_binary(email) do - if Config.get([:instance, :account_activation_required]) do + if @config_impl.get([:instance, :account_activation_required]) do send_confirmation_email(user) {:ok, :enqueued} else diff --git a/test/mix/tasks/pleroma/email_test.exs b/test/mix/tasks/pleroma/email_test.exs index 20b76ae3a..8682ee85d 100644 --- a/test/mix/tasks/pleroma/email_test.exs +++ b/test/mix/tasks/pleroma/email_test.exs @@ -3,13 +3,15 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.EmailTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Swoosh.TestAssertions - alias Pleroma.Config + alias Pleroma.Test.StaticConfig, as: Config alias Pleroma.Tests.ObanHelpers + alias Pleroma.UnstubbedConfigMock, as: ConfigMock + import Mox import Pleroma.Factory setup_all do @@ -22,8 +24,15 @@ defmodule Mix.Tasks.Pleroma.EmailTest do :ok end - setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true) - setup do: clear_config([:instance, :account_activation_required], true) + setup do + ConfigMock + |> stub(:get, fn + [Pleroma.Emails.Mailer, :enabled] -> true + [:instance, :account_activation_required] -> true + end) + + :ok + end describe "pleroma.email test" do test "Sends test email with no given address" do