Tests: fix more tests
This commit is contained in:
parent
dca41cc4a3
commit
05352330bb
|
@ -7,9 +7,11 @@ defmodule Pleroma.ApplicationRequirementsTest do
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
|
|
||||||
alias Pleroma.ApplicationRequirements
|
alias Pleroma.ApplicationRequirements
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
describe "check_repo_pool_size!/1" do
|
describe "check_repo_pool_size!/1" do
|
||||||
test "raises if the pool size is unexpected" do
|
test "raises if the pool size is unexpected" do
|
||||||
|
@ -37,7 +39,11 @@ test "doesn't raise if the pool size is unexpected but the respective flag is se
|
||||||
|
|
||||||
test "warns if welcome email enabled but mail disabled" do
|
test "warns if welcome email enabled but mail disabled" do
|
||||||
clear_config([:welcome, :email, :enabled], true)
|
clear_config([:welcome, :email, :enabled], true)
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Pleroma.Emails.Mailer, :enabled] -> false
|
||||||
|
end)
|
||||||
|
|
||||||
assert capture_log(fn ->
|
assert capture_log(fn ->
|
||||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||||
|
@ -59,7 +65,11 @@ test "warns if welcome email enabled but mail disabled" do
|
||||||
|
|
||||||
test "warns if account confirmation is required but mailer isn't enabled" do
|
test "warns if account confirmation is required but mailer isn't enabled" do
|
||||||
clear_config([:instance, :account_activation_required], true)
|
clear_config([:instance, :account_activation_required], true)
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Pleroma.Emails.Mailer, :enabled] -> false
|
||||||
|
end)
|
||||||
|
|
||||||
assert capture_log(fn ->
|
assert capture_log(fn ->
|
||||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||||
|
@ -74,7 +84,12 @@ test "doesn't do anything if account confirmation is disabled" do
|
||||||
|
|
||||||
test "doesn't do anything if account confirmation is required and mailer is enabled" do
|
test "doesn't do anything if account confirmation is required and mailer is enabled" do
|
||||||
clear_config([:instance, :account_activation_required], true)
|
clear_config([:instance, :account_activation_required], true)
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Pleroma.Emails.Mailer, :enabled] -> true
|
||||||
|
end)
|
||||||
|
|
||||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,12 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Emails.MailerTest do
|
defmodule Pleroma.Emails.MailerTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase, async: true
|
||||||
alias Pleroma.Emails.Mailer
|
|
||||||
|
|
||||||
|
alias Pleroma.Emails.Mailer
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Swoosh.TestAssertions
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
@email %Swoosh.Email{
|
@email %Swoosh.Email{
|
||||||
|
@ -14,10 +17,22 @@ defmodule Pleroma.Emails.MailerTest do
|
||||||
subject: "Pleroma test email",
|
subject: "Pleroma test email",
|
||||||
to: [{"Test User", "user1@example.com"}]
|
to: [{"Test User", "user1@example.com"}]
|
||||||
}
|
}
|
||||||
setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Mailer, :enabled] -> true
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "not send email when mailer is disabled" do
|
test "not send email when mailer is disabled" do
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Mailer, :enabled] -> false
|
||||||
|
end)
|
||||||
|
|
||||||
Mailer.deliver(@email)
|
Mailer.deliver(@email)
|
||||||
:timer.sleep(100)
|
:timer.sleep(100)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,11 @@ defmodule Pleroma.User.WelcomeEmailTest do
|
||||||
|
|
||||||
setup do: clear_config([:welcome])
|
setup do: clear_config([:welcome])
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "send_email/1" do
|
describe "send_email/1" do
|
||||||
test "send a welcome email" do
|
test "send a welcome email" do
|
||||||
user = insert(:user, name: "Jimm")
|
user = insert(:user, name: "Jimm")
|
||||||
|
|
|
@ -991,7 +991,11 @@ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
|
||||||
|
|
||||||
describe "PATCH /resend_confirmation_email" do
|
describe "PATCH /resend_confirmation_email" do
|
||||||
test "it resend emails for two users", %{conn: conn, admin: admin} do
|
test "it resend emails for two users", %{conn: conn, admin: admin} do
|
||||||
|
ConfigMock
|
||||||
|
|> Mox.stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
clear_config([:instance, :admin_privileges], [:users_manage_credentials])
|
clear_config([:instance, :admin_privileges], [:users_manage_credentials])
|
||||||
|
|
||||||
[first_user, second_user] = insert_pair(:user, is_confirmed: false)
|
[first_user, second_user] = insert_pair(:user, is_confirmed: false)
|
||||||
|
|
||||||
ret_conn =
|
ret_conn =
|
||||||
|
@ -1079,7 +1083,7 @@ test "it requires privileged role :statistics_read", %{conn: conn} do
|
||||||
describe "/api/pleroma/backups" do
|
describe "/api/pleroma/backups" do
|
||||||
test "it creates a backup", %{conn: conn} do
|
test "it creates a backup", %{conn: conn} do
|
||||||
ConfigMock
|
ConfigMock
|
||||||
|> Mox.stub_with(Pleroma.Config)
|
|> Mox.stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
||||||
token = insert(:oauth_admin_token, user: admin)
|
token = insert(:oauth_admin_token, user: admin)
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: false
|
use Pleroma.Web.ConnCase, async: false
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.UserInviteToken
|
alias Pleroma.UserInviteToken
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -19,6 +21,9 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
||||||
|> assign(:user, admin)
|
|> assign(:user, admin)
|
||||||
|> assign(:token, token)
|
|> assign(:token, token)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, %{admin: admin, token: token, conn: conn}}
|
{:ok, %{admin: admin, token: token, conn: conn}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Test.StaticConfig, as: Config
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Swoosh.TestAssertions
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
|
@ -25,7 +27,15 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
||||||
[user: user]
|
[user: user]
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do: clear_config([:instance, :account_activation_required], true)
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:instance, :account_activation_required] -> true
|
||||||
|
path -> Config.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "resend account confirmation email", %{conn: conn, user: user} do
|
test "resend account confirmation email", %{conn: conn, user: user} do
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -11,9 +11,15 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Swoosh.TestAssertions
|
import Swoosh.TestAssertions
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/password_reset/token" do
|
describe "GET /api/pleroma/password_reset/token" do
|
||||||
test "it returns error when token invalid", %{conn: conn} do
|
test "it returns error when token invalid", %{conn: conn} do
|
||||||
response =
|
response =
|
||||||
|
|
|
@ -16,6 +16,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "it registers a new user and returns the user." do
|
test "it registers a new user and returns the user." do
|
||||||
data = %{
|
data = %{
|
||||||
:username => "lain",
|
:username => "lain",
|
||||||
|
@ -48,6 +53,10 @@ test "it registers a new user with empty string in bio and returns the user" do
|
||||||
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
||||||
clear_config([:instance, :account_activation_required], true)
|
clear_config([:instance, :account_activation_required], true)
|
||||||
|
|
||||||
|
Pleroma.UnstubbedConfigMock
|
||||||
|
|> Mox.expect(:get, fn [:instance, :account_activation_required] -> true end)
|
||||||
|
|> Mox.expect(:get, fn [Pleroma.Emails.Mailer, :enabled] -> true end)
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
:username => "lain",
|
:username => "lain",
|
||||||
:email => "lain@wired.jp",
|
:email => "lain@wired.jp",
|
||||||
|
@ -64,8 +73,8 @@ test "it sends confirmation email if :account_activation_required is specified i
|
||||||
|
|
||||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||||
|
|
||||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
notify_email = Pleroma.Test.StaticConfig.get([:instance, :notify_email])
|
||||||
instance_name = Pleroma.Config.get([:instance, :name])
|
instance_name = Pleroma.Test.StaticConfig.get([:instance, :name])
|
||||||
|
|
||||||
Swoosh.TestAssertions.assert_email_sent(
|
Swoosh.TestAssertions.assert_email_sent(
|
||||||
from: {instance_name, notify_email},
|
from: {instance_name, notify_email},
|
||||||
|
|
Loading…
Reference in New Issue