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
7 import ExUnit.CaptureLog
12 describe "check_welcome_message_config!/1" do
13 setup do: clear_config([:welcome])
14 setup do: clear_config([Pleroma.Emails.Mailer])
16 test "raises if welcome email enabled but mail disabled" do
17 Pleroma.Config.put([:welcome, :email, :enabled], true)
18 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
20 assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
21 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
26 describe "check_confirmation_accounts!" do
28 {Pleroma.ApplicationRequirements, [:passthrough],
30 check_migrations_applied!: fn _ -> :ok end
36 setup do: clear_config([:instance, :account_activation_required])
38 test "raises if account confirmation is required but mailer isn't enable" do
39 Pleroma.Config.put([:instance, :account_activation_required], true)
40 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
42 assert_raise Pleroma.ApplicationRequirements.VerifyError,
43 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
45 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
49 test "doesn't do anything if account confirmation is disabled" do
50 Pleroma.Config.put([:instance, :account_activation_required], false)
51 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
52 assert Pleroma.ApplicationRequirements.verify!() == :ok
55 test "doesn't do anything if account confirmation is required and mailer is enabled" do
56 Pleroma.Config.put([:instance, :account_activation_required], true)
57 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
58 assert Pleroma.ApplicationRequirements.verify!() == :ok
62 describe "check_rum!" do
64 {Pleroma.ApplicationRequirements, [:passthrough],
65 [check_migrations_applied!: fn _ -> :ok end]}
70 setup do: clear_config([:database, :rum_enabled])
72 test "raises if rum is enabled and detects unapplied rum migrations" do
73 Pleroma.Config.put([:database, :rum_enabled], true)
75 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
76 assert_raise Pleroma.ApplicationRequirements.VerifyError,
77 "Unapplied RUM Migrations detected",
79 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
84 test "raises if rum is disabled and detects rum migrations" do
85 Pleroma.Config.put([:database, :rum_enabled], false)
87 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
88 assert_raise Pleroma.ApplicationRequirements.VerifyError,
89 "RUM Migrations detected",
91 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
96 test "doesn't do anything if rum enabled and applied migrations" do
97 Pleroma.Config.put([:database, :rum_enabled], true)
99 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
100 assert Pleroma.ApplicationRequirements.verify!() == :ok
104 test "doesn't do anything if rum disabled" do
105 Pleroma.Config.put([:database, :rum_enabled], false)
107 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
108 assert Pleroma.ApplicationRequirements.verify!() == :ok
113 describe "check_migrations_applied!" do
117 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
118 migrations: fn Repo ->
120 {:up, 20_191_128_153_944, "fix_missing_following_count"},
121 {:up, 20_191_203_043_610, "create_report_notes"},
122 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
130 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
132 test "raises if it detects unapplied migrations" do
133 assert_raise Pleroma.ApplicationRequirements.VerifyError,
134 "Unapplied Migrations detected",
136 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
140 test "doesn't do anything if disabled" do
141 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
143 assert :ok == Pleroma.ApplicationRequirements.verify!()