1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ApplicationRequirementsTest do
8 import ExUnit.CaptureLog
11 alias Pleroma.ApplicationRequirements
15 describe "check_welcome_message_config!/1" do
16 setup do: clear_config([:welcome])
17 setup do: clear_config([Pleroma.Emails.Mailer])
19 test "raises if welcome email enabled but mail disabled" do
20 Pleroma.Config.put([:welcome, :email, :enabled], true)
21 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
23 assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
24 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
29 describe "check_confirmation_accounts!" do
31 {Pleroma.ApplicationRequirements, [:passthrough],
33 check_migrations_applied!: fn _ -> :ok end
39 setup do: clear_config([:instance, :account_activation_required])
41 test "raises if account confirmation is required but mailer isn't enable" do
42 Pleroma.Config.put([:instance, :account_activation_required], true)
43 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
45 assert_raise Pleroma.ApplicationRequirements.VerifyError,
46 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
48 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
52 test "doesn't do anything if account confirmation is disabled" do
53 Pleroma.Config.put([:instance, :account_activation_required], false)
54 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
55 assert Pleroma.ApplicationRequirements.verify!() == :ok
58 test "doesn't do anything if account confirmation is required and mailer is enabled" do
59 Pleroma.Config.put([:instance, :account_activation_required], true)
60 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
61 assert Pleroma.ApplicationRequirements.verify!() == :ok
65 describe "check_rum!" do
67 {Pleroma.ApplicationRequirements, [:passthrough],
68 [check_migrations_applied!: fn _ -> :ok end]}
73 setup do: clear_config([:database, :rum_enabled])
75 test "raises if rum is enabled and detects unapplied rum migrations" do
76 Config.put([:database, :rum_enabled], true)
78 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
79 assert_raise ApplicationRequirements.VerifyError,
80 "Unapplied RUM Migrations detected",
82 capture_log(&ApplicationRequirements.verify!/0)
87 test "raises if rum is disabled and detects rum migrations" do
88 Config.put([:database, :rum_enabled], false)
90 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
91 assert_raise ApplicationRequirements.VerifyError,
92 "RUM Migrations detected",
94 capture_log(&ApplicationRequirements.verify!/0)
99 test "doesn't do anything if rum enabled and applied migrations" do
100 Config.put([:database, :rum_enabled], true)
102 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
103 assert ApplicationRequirements.verify!() == :ok
107 test "doesn't do anything if rum disabled" do
108 Config.put([:database, :rum_enabled], false)
110 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
111 assert ApplicationRequirements.verify!() == :ok
116 describe "check_migrations_applied!" do
120 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
121 migrations: fn Repo ->
123 {:up, 20_191_128_153_944, "fix_missing_following_count"},
124 {:up, 20_191_203_043_610, "create_report_notes"},
125 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
133 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
135 test "raises if it detects unapplied migrations" do
136 assert_raise ApplicationRequirements.VerifyError,
137 "Unapplied Migrations detected",
139 capture_log(&ApplicationRequirements.verify!/0)
143 test "doesn't do anything if disabled" do
144 Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
146 assert :ok == ApplicationRequirements.verify!()