Tests: Fix all the tests.

This commit is contained in:
Lain Soykaf 2023-12-10 19:19:56 +04:00
parent c068a218ea
commit 6e3267d1bd
4 changed files with 21 additions and 19 deletions

View File

@ -145,7 +145,8 @@ config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock
config :pleroma, Pleroma.PromEx, disabled: true
config Pleroma.User.Backup, :config_impl, Pleroma.UnstubbedConfigMock
# Mox definitions. Only read during compile time.
Application.put_env(Pleroma.User.Backup, :config_impl, Pleroma.UnstubbedConfigMock)
if File.exists?("./config/test.secret.exs") do
import_config "test.secret.exs"

View File

@ -12,7 +12,9 @@ defmodule Pleroma.User.BackupTest do
alias Pleroma.Bookmark
alias Pleroma.Tests.ObanHelpers
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
alias Pleroma.User.Backup
alias Pleroma.User.Backup.ProcessorMock
alias Pleroma.Web.CommonAPI
alias Pleroma.Workers.BackupWorker
@ -20,6 +22,14 @@ defmodule Pleroma.User.BackupTest do
clear_config([Pleroma.Upload, :uploader])
clear_config([Backup, :limit_days])
clear_config([Pleroma.Emails.Mailer, :enabled], true)
ConfigMock
|> Mox.stub_with(Pleroma.Config)
ProcessorMock
|> Mox.stub_with(Pleroma.User.Backup.Processor)
:ok
end
test "it does not requrie enabled email" do
@ -302,24 +312,6 @@ defmodule Pleroma.User.BackupTest do
end
end
test "it handles unrecoverable exceptions" do
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
with_mock Backup, [:passthrough], do_process: fn _, _ -> raise "mock exception" end do
{:error, %{backup: backup, reason: :exit}} = Backup.process(backup)
assert backup.state == :failed
end
with_mock Backup, [:passthrough], do_process: fn _, _ -> Process.sleep(:timer.seconds(32)) end do
{:error, %{backup: backup, reason: :timeout}} = Backup.process(backup)
assert backup.state == :failed
end
end
describe "it uploads and deletes a backup archive" do
setup do
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")

View File

@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
alias Pleroma.ModerationLog
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@ -1077,6 +1078,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "/api/pleroma/backups" do
test "it creates a backup", %{conn: conn} do
ConfigMock
|> Mox.stub_with(Pleroma.Config)
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
token = insert(:oauth_admin_token, user: admin)
user = %{id: user_id, nickname: user_nickname} = insert(:user)

View File

@ -7,10 +7,15 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
alias Pleroma.User.Backup
alias Pleroma.Web.PleromaAPI.BackupView
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
setup do
clear_config([Pleroma.Upload, :uploader])
clear_config([Backup, :limit_days])
ConfigMock
|> Mox.stub_with(Pleroma.Config)
oauth_access(["read:backups"])
end